diff options
Diffstat (limited to 'parser.cpp')
-rw-r--r-- | parser.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -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: |