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

lexer now treats decimals as one token, not split into three (number, special, number)

parent 3ecdfbdc
No related branches found
No related tags found
1 merge request!9Dominicsbranch
......@@ -50,6 +50,9 @@ public class Lexer {
if(endIndex==input.length()) {
break;
}
if(Character.compare(input.charAt(endIndex),'.')==0) {
endIndex+=1;
}
}
}
Token token = new Token(TokenType.NUMBER, input.substring(index,endIndex));
......
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
public class Parser {
......@@ -12,10 +11,12 @@ public class Parser {
Expression leftExpression;
String operator;
Expression rightExpression;
public BinaryOperation(Expression leftExpression, String operator, Expression rightExpression) {
Boolean capseled;
public BinaryOperation(Expression leftExpression, String operator, Expression rightExpression, Boolean capseled) {
this.leftExpression = leftExpression;
this.operator = operator;
this.rightExpression = rightExpression;
this.capseled = capseled;
}
}
......@@ -112,15 +113,6 @@ public class Parser {
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));
......@@ -129,24 +121,7 @@ public class Parser {
String operator = ts.remove(0).getData();
parseOperator(operator);
Expression rightExpression = parseExpression(ts);
/*
if(parseCharacter(ts.get(1).getData(), ".")) {
return null;
}
BinaryOperation operation;
if(ts.get(1).getType()!= Lexer.TokenType.SPECIAL) {
throw new ParserException("SyntaxError: unexpected operator: " + ts.get(1).getData());
}
List<Lexer.Token> leftList = new LinkedList<>();
leftList.add(ts.remove(0));
Expression leftExpression = parseExpression(leftList);
String operator = ts.remove(0).getData();
parseOperator(operator);
Expression rightExpression = parseExpression(ts);
*/
return new BinaryOperation(leftExpression, operator, rightExpression);
return new BinaryOperation(leftExpression, operator, rightExpression, false);
}
private Variable parseVariable(List<Lexer.Token> ts) throws ParserException {
......
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