Skip to content

Commit

Permalink
needed to catch errors from expressions inside parentheses
Browse files Browse the repository at this point in the history
after getting the expression inside a parentheses, if an error is
returned, the routine is incorrectly proceeded getting the next token;
the routine now correctly exits when an error is returned

updated regtestn script and batch to run all the tests
  • Loading branch information
thunder422 committed Jul 24, 2013
1 parent 98f6ed9 commit 9d87ab2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion regtestn.bat
Expand Up @@ -37,7 +37,7 @@ rem be answered No for batch to continue - comp has no option to not
rem ask this question)
rem

del expression*.txt translator0*.txt
del expression*.txt translator*.txt
for %%i in (test/expression*.dat test/translator0*.dat) do (
ibcp -n test\%%i >%%~ni.txt
)
Expand Down
2 changes: 1 addition & 1 deletion regtestn.in
Expand Up @@ -35,7 +35,7 @@
rm -f expression*.txt translator*.txt
dir=@ibcp_SOURCE_DIR@/test/
./ibcp -v
for input in ${dir}expression*.dat ${dir}translator0[1-5].dat
for input in ${dir}expression*.dat ${dir}translator*.dat
do
base=${input##*/}
output=${base%.dat}.txt
Expand Down
57 changes: 30 additions & 27 deletions translator.cpp
Expand Up @@ -1905,39 +1905,42 @@ TokenStatus Translator::getExpression(Token *&token, DataType dataType)

// get an expression and terminating token
token = NULL;
if ((status = getExpression(token, dataType)) == Done_TokenStatus)
if ((status = getExpression(token, dataType)) != Done_TokenStatus)
{
// check terminating token
if (!token->isCode(CloseParen_Code))
{
status = ExpOpOrParen_TokenStatus;
break;
}
break; // exit on error
}

// make sure holding stack contains the open parentheses
Token *topToken = m_holdStack.pop().token;
if (!topToken->code() == OpenParen_Code)
{
// oops, no open parentheses (this should not happen)
return BUG_UnexpectedCloseParen;
}
// check terminating token
if (!token->isCode(CloseParen_Code))
{
status = ExpOpOrParen_TokenStatus;
break;
}

// make sure holding stack contains the open parentheses
Token *topToken = m_holdStack.pop().token;
if (!topToken->code() == OpenParen_Code)
{
// oops, no open parentheses (this should not happen)
return BUG_UnexpectedCloseParen;
}

// replace first and last operands of token on done stack
m_doneStack.replaceTopFirstLast(topToken, token);
// replace first and last operands of token on done stack
m_doneStack.replaceTopFirstLast(topToken, token);

// mark close paren as used for last operand and pending paren
// (so it doesn't get deleted until it's not used anymore)
token->setSubCodeMask(Last_SubCode + Used_SubCode);
// mark close paren as used for last operand and pending paren
// (so it doesn't get deleted until it's not used anymore)
token->setSubCodeMask(Last_SubCode + Used_SubCode);

// set highest precedence if not an operator on done stack top
// (no operators in the parentheses)
topToken = m_doneStack.top().rpnItem->token();
m_lastPrecedence = topToken->isType(Operator_TokenType)
? m_table.precedence(topToken) : HighestPrecedence;
// set highest precedence if not an operator on done stack top
// (no operators in the parentheses)
topToken = m_doneStack.top().rpnItem->token();
m_lastPrecedence = topToken->isType(Operator_TokenType)
? m_table.precedence(topToken) : HighestPrecedence;

// set pending parentheses token pointer
m_pendingParen = token;

// set pending parentheses token pointer
m_pendingParen = token;
}
token = NULL; // get another token
}
else
Expand Down

0 comments on commit 9d87ab2

Please sign in to comment.