Skip to content
Snippets Groups Projects

Dominicsbranch

2 files
+ 41
6
Compare changes
  • Side-by-side
  • Inline

Files

+ 40
5
@@ -101,6 +101,39 @@ public class Parser {
@@ -101,6 +101,39 @@ public class Parser {
if(ts.size()==1) {
if(ts.size()==1) {
return null;
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;
 
}
BinaryOperation operation;
BinaryOperation operation;
if(ts.get(1).getType()!= Lexer.TokenType.SPECIAL) {
if(ts.get(1).getType()!= Lexer.TokenType.SPECIAL) {
throw new ParserException("SyntaxError: unexpected operator: " + ts.get(1).getData());
throw new ParserException("SyntaxError: unexpected operator: " + ts.get(1).getData());
@@ -111,6 +144,8 @@ public class Parser {
@@ -111,6 +144,8 @@ public class Parser {
String operator = ts.remove(0).getData();
String operator = ts.remove(0).getData();
parseOperator(operator);
parseOperator(operator);
Expression rightExpression = parseExpression(ts);
Expression rightExpression = parseExpression(ts);
 
 
*/
return new BinaryOperation(leftExpression, operator, rightExpression);
return new BinaryOperation(leftExpression, operator, rightExpression);
}
}
@@ -151,7 +186,7 @@ public class Parser {
@@ -151,7 +186,7 @@ public class Parser {
if (ts.size()>1) {
if (ts.size()>1) {
//if the next token is of TokenType.SPECIAL, check if it's a comma
//if the next token is of TokenType.SPECIAL, check if it's a comma
//if it is, create a decimal
//if it is, create a decimal
if(ts.get(0).getType() == Lexer.TokenType.SPECIAL) {
if(ts.get(1).getType() == Lexer.TokenType.SPECIAL) {
if(parseComma(ts)) {
if(parseComma(ts)) {
value = parseDecimal(ts);
value = parseDecimal(ts);
}
}
@@ -191,8 +226,8 @@ public class Parser {
@@ -191,8 +226,8 @@ public class Parser {
return new Number(data);
return new Number(data);
}
}
parseDigitWithoutZero(data);
parseDigitWithoutZero(data.substring(0,1));
parseDigit(data);
parseDigit(data.substring(1));
return new Number(data);
return new Number(data);
}
}
@@ -219,9 +254,9 @@ public class Parser {
@@ -219,9 +254,9 @@ public class Parser {
}
}
private Boolean parseComma(List<Lexer.Token> ts) throws ParserException {
private Boolean parseComma(List<Lexer.Token> ts) throws ParserException {
String data = ts.get(0).getData();
String data = ts.get(1).getData();
if(parseCharacter(data, ".")) {
if(parseCharacter(data, ".")) {
if(ts.get(1).getType()!= Lexer.TokenType.NUMBER) {
if(ts.get(2).getType()!= Lexer.TokenType.NUMBER) {
throw new ParserException("SyntaxError: no number after comma");
throw new ParserException("SyntaxError: no number after comma");
}
}
return true;
return true;
Loading