Skip to content
Snippets Groups Projects

Dominicsbranch

Merged Dominic Daniel Krämer requested to merge dominicsbranch into main
4 files
+ 159
61
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 21
7
@@ -2,36 +2,50 @@ import java.io.BufferedReader;
@@ -2,36 +2,50 @@ import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Arrays;
 
import java.util.LinkedList;
import java.util.List;
import java.util.List;
public class Application {
public class Application {
public static void main(String[] args) {
public static void main(String[] args) {
 
//LinkedList<String> expressions = new LinkedList<>()
 
//LinkedList<String> expressions = new List<>();
 
List<String> expressions = new LinkedList<>();
 
//Reads the file "expressions.txt" and adds its values to a list
BufferedReader reader;
BufferedReader reader;
String datapath = "expressions.txt";
String datapath = "expressions.txt";
try {
try {
System.out.println("Reading the file:");
System.out.println("Reading the file...\n");
reader = new BufferedReader(new FileReader(datapath));
reader = new BufferedReader(new FileReader(datapath));
String line = reader.readLine();
String line = reader.readLine();
while(line != null) {
while(line != null) {
System.out.println(line);
expressions.add(line);
line = reader.readLine();
line = reader.readLine();
}
}
System.out.println();
reader.close();
reader.close();
}
}
catch (IOException e ) {
catch (IOException e ) {
e.printStackTrace();
e.printStackTrace();
}
}
//List with a fitting String to be parsed into multiple tokens
List<String> test = Arrays.asList("1 + xy^2 - (31 * x)y");
//Iterates through every String and parses them into multiple tokens
//Iterates through every String
for (String value: expressions) {
for (String value: test) {
System.out.println(value);
//creates a list of tokens out of the String
//creates a list of tokens out of the String
List<Lexer.Token> tokens = Lexer.lex(value);
List<Lexer.Token> tokens = Lexer.lex(value);
 
//prints each token out (with .toString())
//prints each token out (with .toString())
for(Lexer.Token singleToken: tokens) {
for(Lexer.Token singleToken: tokens) {
System.out.println(singleToken.toString());
System.out.println(singleToken.toString());
}
}
 
Parser parser = new Parser();
 
try {
 
parser.parse(tokens);
 
System.out.println();
 
}
 
catch (ParserException e) {
 
System.out.println(e.getMessage());
 
}
 
System.out.println();
}
}
}
}
}
}
Loading