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

fixed a bug, parser can now parse decimals in combination with operators

parent f70e7e82
No related branches found
No related tags found
Loading
x+2/40+3*x
\ No newline at end of file
40.2+3*x
\ No newline at end of file
......@@ -101,6 +101,36 @@ public class Parser {
if(ts.size()==1) {
return null;
}
int index;
for(index=0; index<ts.size(); index++) {
if(ts.get(index).getType()== Lexer.TokenType.SPECIAL) {
if(!parseCharacter(ts.get(index).getData(), ".")) {
break;
}
}
}
if(index==ts.size()) {
return null;
}
//0
//1
//2
//3
//4 * => index=4
//5
//6
//7
List<Lexer.Token> leftList = new LinkedList<>();
for(int i=0; i<index; i++) {
leftList.add(ts.remove(0));
}
Expression leftExpression = parseExpression(leftList);
String operator = ts.remove(0).getData();
parseOperator(operator);
Expression rightExpression = parseExpression(ts);
/*
if(parseCharacter(ts.get(1).getData(), ".")) {
return null;
}
......@@ -114,6 +144,8 @@ public class Parser {
String operator = ts.remove(0).getData();
parseOperator(operator);
Expression rightExpression = parseExpression(ts);
*/
return new BinaryOperation(leftExpression, operator, rightExpression);
}
......
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