Skip to content
Snippets Groups Projects

Dominicsbranch

5 files
+ 253
70
Compare changes
  • Side-by-side
  • Inline

Files

+ 11
15
@@ -32,17 +32,25 @@ public class Application {
@@ -32,17 +32,25 @@ public class Application {
}
}
//Iterate through every String
//Iterate through every String
for (String expression: expressions) {
for (String expressionString: expressions) {
System.out.println("Expression: " + expression);
System.out.println("Expression: " + expressionString);
//Usage of the lexer, parser & evaluator
//Usage of the lexer, parser & evaluator
try {
try {
//Create a list of tokens with the lexer
//Create a list of tokens with the lexer
List<Lexer.Token> tokens = Lexer.lex(expression);
List<Lexer.Token> tokens = Lexer.lex(expressionString);
System.out.println("Lexer created tokens:");
System.out.println("Lexer created tokens:");
//prints out each token to the console
//prints out each token to the console
for(Lexer.Token token: tokens) {
for(Lexer.Token token: tokens) {
System.out.println(token.toString());
System.out.println(token.toString());
}
}
 
//Parse all tokens with the parser and saves the result into the variable 'ast'
 
Parser parser = new Parser();
 
Parser.Expression ast = parser.parse(tokens);
 
//Prints the ast out with an ASTPrinter
 
//the result can later be used to show the ast in a function plotter
 
ASTPrinter printer = new ASTPrinter();
 
System.out.println("Printing: '" + printer.visit(ast) + "'");
 
System.out.println();
}
}
catch (Exception e) {
catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
@@ -51,22 +59,10 @@ public class Application {
@@ -51,22 +59,10 @@ public class Application {
}
}
/*
/*
//Iterates through every String and parses them into multiple tokens
for (String value: expressions) {
Parser parser = new Parser();
try {
Parser.Expression exp = parser.parse(tokens);
ASTPrinter printer = new ASTPrinter();
Evaluator evaluator = new Evaluator();
Evaluator evaluator = new Evaluator();
System.out.println("Printing: '" + printer.visit(exp) + "'");
String s = printer.visit(exp);
String s = printer.visit(exp);
System.out.println("Evaluating: '" + evaluator.visit(exp) + "'");
System.out.println("Evaluating: '" + evaluator.visit(exp) + "'");
SwingFunctionPlotter.plotFunction(s);
SwingFunctionPlotter.plotFunction(s);
}
catch (ParserException e) {
System.out.println(e.getMessage());
}
System.out.println();
}*/
}*/
}
}
}
}
Loading