diff options
author | chris.sutcliffe <ctd.sutcliffe@gmail.com> | 2021-11-29 16:46:56 +0000 |
---|---|---|
committer | chris.sutcliffe <ctd.sutcliffe@gmail.com> | 2021-11-29 16:46:56 +0000 |
commit | 33359862f5455dc7003ebbe5357c611298042cee (patch) | |
tree | 1eff075406177fb2d0feff685f24c7e306f589c8 /code/Interpreter2/src/Interpreter/Language.java | |
parent | 2e3be43da8761eb77b00af20f559fef7a8c6b1b8 (diff) | |
download | esotericFORTRAN-33359862f5455dc7003ebbe5357c611298042cee.tar.gz esotericFORTRAN-33359862f5455dc7003ebbe5357c611298042cee.zip |
clean repo (remove code dir, add UI dir)
Diffstat (limited to 'code/Interpreter2/src/Interpreter/Language.java')
-rw-r--r-- | code/Interpreter2/src/Interpreter/Language.java | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/code/Interpreter2/src/Interpreter/Language.java b/code/Interpreter2/src/Interpreter/Language.java deleted file mode 100644 index 80aa1e3..0000000 --- a/code/Interpreter2/src/Interpreter/Language.java +++ /dev/null @@ -1,63 +0,0 @@ -package Interpreter; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; -import java.util.Scanner; - -//Base class for the interpreter -public class Language { - static boolean hadError = false; - public static void main(String[] args){ - - //Allow users to input a single line of code - //Still needs some work to re-ask for input after each line - if (args.length < 1){ - Scanner input = new Scanner(System.in); - String sourceCode = "1"; - while (sourceCode!=""){ - System.out.print("Code: "); - sourceCode = input.nextLine(); - runInterpreter(sourceCode); - hadError=false; - } - input.close(); - - //Allow users to provide a path to a file as an argument - } else if (args.length==1){ - try { - String sourcecode = Files.readString(Paths.get(args[0])); //Maybe should set charset here - runInterpreter(sourcecode); - } catch (IOException exception){ - System.out.println("File not found"); - } - - } else { - System.out.println("Error, argument should be file path"); - System.exit(64); - } - } - - //Extract and print each token - private static void runInterpreter(String sourceCode){ - TokenScanner scanner = new TokenScanner(); - List<Token> tokens = scanner.extractTokens(sourceCode); - //for (Token token : tokens) { - // System.out.println(token); - //} - if (hadError) return; - //Parse into AST - Parser parser = new Parser(tokens); - List<Statement> ast = parser.parse(); - if (hadError) return; - Interpreter interpreter = new Interpreter(); - interpreter.interpret(ast); - } - - static void displayError(String message){ - hadError=true; - System.out.println("An error was encountered"); - System.out.println(message); - } -} |