summaryrefslogtreecommitdiff
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
parentbbf4e8304b50b6a972cacc6337d1aa283ccb83be (diff)
Corregido error de paréntesis derecho.
-rw-r--r--main.cpp13
-rw-r--r--parser.cpp16
2 files changed, 23 insertions, 6 deletions
diff --git a/main.cpp b/main.cpp
index 12ee839..a7e81bb 100644
--- a/main.cpp
+++ b/main.cpp
@@ -19,10 +19,15 @@ int main(){
{
parser.parse(input);
cout << "Todo correcto." << endl;
- }catch(ParserException e)
- {
- cout << e.showMsg() << endl;
- }
+ }
+ catch(ParserException e)
+ {
+ cout << e.showMsg() << endl;
+ }
+ catch(LexerException e)
+ {
+ cout << e.showMsg() << endl;
+ }
return 0;
}
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: