Skip to content
Snippets Groups Projects
Commit 2aca6157 authored by Dominic Daniel Krämer's avatar Dominic Daniel Krämer
Browse files

Merge branch 'dominicsbranch' into 'main'

Dominicsbranch

See merge request !6
parents ed911771 fd8638be
No related branches found
No related tags found
1 merge request!6Dominicsbranch
1 + xy^2 - (31 * x)y 1 + xy^2 - (31 * x)y
\ No newline at end of file 1 + x^2 - (3 * x)
2x + 0,5x^2 - 1
\ No newline at end of file
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
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) {
BufferedReader reader;
String datapath = "expressions.txt";
try {
System.out.println("Reading the file:");
reader = new BufferedReader(new FileReader(datapath));
String line = reader.readLine();
while(line != null) {
System.out.println(line);
line = reader.readLine();
}
System.out.println();
reader.close();
}
catch (IOException e ) {
e.printStackTrace();
}
//List with a fitting String to be parsed into multiple tokens //List with a fitting String to be parsed into multiple tokens
List<String> test = Arrays.asList("1 + xy^2 - (31 * x)y"); List<String> test = Arrays.asList("1 + xy^2 - (31 * x)y");
//Iterates through every String //Iterates through every String
......
...@@ -84,7 +84,7 @@ public class Parser { ...@@ -84,7 +84,7 @@ public class Parser {
//parses a list of tokens into a value //parses a list of tokens into a value
private Optional<Expression> parseValue(List<Lexer.Token> ts) throws ParserException { private Optional<Expression> parseValue(List<Lexer.Token> ts) throws ParserException {
if (ts.isEmpty()) { if (ts.isEmpty()) {
throw new ParserException("SyntaxError: expected a number"); throw new ParserException("RuntimeException: empty token list");
} }
if (ts.get(0).getType() != Lexer.TokenType.NUMBER) { if (ts.get(0).getType() != Lexer.TokenType.NUMBER) {
return Optional.empty(); return Optional.empty();
...@@ -114,13 +114,13 @@ public class Parser { ...@@ -114,13 +114,13 @@ public class Parser {
//parses a decimal of a list of tokens & a string //parses a decimal of a list of tokens & a string
private Expression parseDecimal(List<Lexer.Token> ts, String data) throws ParserException { private Expression parseDecimal(List<Lexer.Token> ts, String data) throws ParserException {
if(ts.size()<1) { if(ts.size()<1) {
throw new ParserException("SyntaxError: "); throw new ParserException("RuntimeException: empty token list");
} }
if(ts.get(0).getType() != Lexer.TokenType.SPECIAL) { if(ts.get(0).getType() != Lexer.TokenType.SPECIAL) {
throw new ParserException(""); throw new ParserException("SyntaxException: expected a comma");
} }
if(ts.get(1).getType() != Lexer.TokenType.NUMBER) { if(ts.get(1).getType() != Lexer.TokenType.NUMBER) {
throw new ParserException(""); throw new ParserException("SyntaxException: expected a number after a comma");
} }
Number beforeDot = (Number) parseNumber(data); Number beforeDot = (Number) parseNumber(data);
ts.remove(0); ts.remove(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment