Skip to content
Snippets Groups Projects
Select Git revision
  • 42a2f3b294d5139a5cb9b87a7dd870e5a29704b6
  • master default protected
  • release/1.1.4
  • release/1.1.3
  • release/1.1.1
  • 1.4.2
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.1
  • 1.2.0
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1.1
  • 1.1.0
  • 1.0.9
  • 1.0.8
  • 1.0.7
  • v1.0.5
  • 1.0.5
21 results

TLA2B.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    TLA2B.java 2.68 KiB
    package de.tla2b;
    
    import de.tla2b.exceptions.FrontEndException;
    import de.tla2b.exceptions.NotImplementedException;
    import de.tla2b.exceptions.TLA2BException;
    import de.tla2b.global.TranslationGlobals;
    import de.tla2bAst.Translator;
    
    import org.apache.commons.cli.CommandLine;
    import org.apache.commons.cli.DefaultParser;
    import org.apache.commons.cli.HelpFormatter;
    import org.apache.commons.cli.Option;
    import org.apache.commons.cli.Options;
    import org.apache.commons.cli.ParseException;
    
    public class TLA2B implements TranslationGlobals {
    	public final static String VERSION = "version";
    
    	private String mainFile;
    
    	private static boolean error = false;
    
    	public static boolean hasError() {
    		return error;
    	}
    
    	public void handleParameter(String[] args) {
    		DefaultParser parser = new DefaultParser();
    		Options options = getCommandlineOptions();
    		try {
    			CommandLine line = parser.parse(options, args);
    			String[] remainingArgs = line.getArgs();
    			if (line.hasOption(VERSION)) {
    				System.out.println("TLA2B version: " + VERSION_NUMBER);
    			}
    			if (remainingArgs.length != 1) {
    				System.out.println("Error: expected a module file.");
    				HelpFormatter formatter = new HelpFormatter();
    				formatter.printHelp("java -jar TLA2B.jar [file]", options);
    				System.exit(-1);
    			} else {
    				mainFile = remainingArgs[0];
    			}
    		} catch (ParseException e) {
    			System.out.println(e.getMessage());
    			HelpFormatter formatter = new HelpFormatter();
    			formatter.printHelp("java -jar TLA2B.jar [file]", options);
    			System.exit(-1);
    		}
    
    	}
    
    	public static void main(String[] args) {
    		// To indicate an error we use the exit code -1
    		TLA2B tla2b = new TLA2B();
    
    		tla2b.handleParameter(args);
    
    		Translator translator = null;
    		try {
    			translator = new Translator(tla2b.mainFile);
    		} catch (FrontEndException e) {
    			System.exit(-1);
    		}
    		try {
    			translator.translate();
    		} catch (NotImplementedException e) {
    			System.err.print("**** Translation Error ****\n");
    			System.err.print("Not implemented:\n");
    			System.err.println(e.getMessage());
    			System.exit(-1);
    		} catch (TLA2BException e) {
    			System.err.print("**** Translation Error ****\n");
    			System.err.println(e.getMessage());
    			//e.printStackTrace();
    			System.exit(-1);
    		}
    		translator.createMachineFile();
    		translator.createProbFile();
    	}
    
    	private static Options getCommandlineOptions() {
    		Options options = new Options();
    		options.addOption(VERSION, false, "prints the current version of TLA2B");
    		
    		Option config = Option.builder("config")
    			.argName("file")
    			.hasArg()
    			.desc("config file")
    			.build();
    		options.addOption(config);
    		return options;
    	}
    }