summaryrefslogtreecommitdiff
path: root/parser.cpp
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2022-04-02 12:27:43 -0600
committerHombreLaser <sebastian-440@live.com>2022-04-02 12:27:43 -0600
commit98342425bde17b9b236f8226e466d7e604371720 (patch)
tree214da01f6534d08ba1e76f044843f00bc7e79ac2 /parser.cpp
parentbbf4e8304b50b6a972cacc6337d1aa283ccb83be (diff)
Corregido error de paréntesis derecho.
Diffstat (limited to 'parser.cpp')
-rw-r--r--parser.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/parser.cpp b/parser.cpp
index 8cba19e..11ff786 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -19,6 +19,11 @@ bool Parser::checkToken(){
void Parser::parse(string expr){
setText(expr);
parseExpr();
+
+ /* Si no se ha consumido toda la cadena, lanzamos
+ error. */
+ if(tokenizer.getCurrentToken().type != nil)
+ throw ParserException("Sintaxis incorrecta.");
}
void Parser::parseExpr(){
@@ -33,7 +38,7 @@ void Parser::parsePrimeExpr(){
tokenizer.nextToken();
if(!checkToken())
- throw ParserException("Carácter inválido.");
+ throw ParserException("Sintaxis incorrecta.");
parseTerm();
parsePrimeExpr();
@@ -52,7 +57,7 @@ void Parser::parsePrimeTerm(){
tokenizer.nextToken();
if(!checkToken())
- throw ParserException("Carácter inválido.");
+ throw ParserException("Sintaxis incorrecta.");
parsePower();
parsePrimeTerm();
@@ -72,6 +77,8 @@ void Parser::parsePrimePower(){
if(tokenizer.getCurrentToken().type != number)
throw ParserException("Sintaxis incorrecta.");
+ tokenizer.nextToken();
+
parsePrimePower();
}
}
@@ -90,6 +97,9 @@ void Parser::parseFactor(){
// Consumimos paréntesis derecho.
if(tokenizer.getCurrentToken().type != right_parens)
throw ParserException("Sintaxis incorrecta.");
+
+ tokenizer.nextToken();
+
break;
case function:
tokenizer.nextToken();
@@ -101,6 +111,8 @@ void Parser::parseFactor(){
if(tokenizer.getCurrentToken().type != right_parens)
throw ParserException("Sintaxis incorrecta.");
+
+ tokenizer.nextToken();
break;
case variable: