From 98342425bde17b9b236f8226e466d7e604371720 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sat, 2 Apr 2022 12:27:43 -0600 Subject: Corregido error de paréntesis derecho. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parser.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'parser.cpp') 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: -- cgit v1.2.3