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

fixed a bug, parser can now parse numbers that contains zeros

parent 2fd496f2
No related branches found
No related tags found
1 merge request!8Dominicsbranch
This commit is part of merge request !8. Comments created here will be created in the context of that merge request.
x+2/5223+y+44+4+2^12/222 x+2/40+3*x
\ No newline at end of file \ No newline at end of file
...@@ -101,6 +101,9 @@ public class Parser { ...@@ -101,6 +101,9 @@ public class Parser {
if(ts.size()==1) { if(ts.size()==1) {
return null; return null;
} }
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());
...@@ -151,7 +154,7 @@ public class Parser { ...@@ -151,7 +154,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 +194,8 @@ public class Parser { ...@@ -191,8 +194,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 +222,9 @@ public class Parser { ...@@ -219,9 +222,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;
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment