Skip to content
Snippets Groups Projects
Select Git revision
  • 99d3eb2319807c879daccbefeb65bcc58ce4eed6
  • main default protected
  • feat/final
  • feature/Michelle
  • feat/010125
  • Luca
  • feat/knew
  • feat/try
  • feat/katha2
  • feature/katharina
10 results

2024-12-22_Server_mit_Client_Funktion.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Application.java 2.53 KiB
    package main;
    
    import Exceptions.LexerException;
    import Exceptions.ParserException;
    
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.LinkedList;
    import java.util.List;
    
    public class Application {
        public static void main(String[] args) {
            //A list that will contain a String for each line of the "expressions.txt" file
            List<String> expressions = new LinkedList<>();
            //Reads the file "expressions.txt" and adds its values to the list expressions
            BufferedReader reader;
            String datapath = "expressions.txt";
            try {
                System.out.println("Reading the file...\n");
                reader = new BufferedReader(new FileReader(datapath));
                String currentLine = reader.readLine();
                while(currentLine !=null) {
                    expressions.add(currentLine);
                    currentLine = reader.readLine();
                }
                reader.close();
            }
            catch(IOException e) {
                e.printStackTrace();
            }
    
            //Iterate through every String
            for (String expressionString: expressions) {
                System.out.println("Expression: " + expressionString);
                //Usage of the lexer, parser & evaluator
                try {
                    //Create a list of tokens with the lexer
                    List<Lexer.Token> tokens = Lexer.lex(expressionString);
                    System.out.println("Lexer created tokens:");
                    //prints out each token to the console
                    for(Lexer.Token token: tokens) {
                        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) {
                    e.printStackTrace();
                }
    
            }
    
            /*
                    Evaluator evaluator = new Evaluator();
                    String s = printer.visit(exp);
                    System.out.println("Evaluating: '" + evaluator.visit(exp) + "'");
                    SwingFunctionPlotter.plotFunction(s);
            }*/
        }
    }