Skip to content

Commit

Permalink
corrected parser and unary operator issues
Browse files Browse the repository at this point in the history
parser errors were not being handled correctly in all cases and when a
unary operator occurred when a binary operator should, the error message
should have included "binary" in front of operator

getToken() modified to only return number parser errors in operand mode
when the current data type if not a string

translate2() expression only test mode modified to look for a
non-numeric parser error and set the ExpOpOrEnd status

getExpression() for parentheses expression processing modified to see
if the terminating token is a unary operand and set status to new
ExpBinOpOrParen status; when getting binary operator or
end-of-expression token, no longer returns ExpOpOrEnd status (parser
error returned and caller determines actual status)

getOperand() modified upon an error from getToken() if not reference
mode, error status is still returned, but for reference modes, if a
parser error then the length of the error is set to one before returning
the expected reference status for the current data type and reference
mode

getInternalFunction() modified if getExpression() returns a parser
error, then the parser error is returned if it is a numeric parser
error; for other parser errors or if the terminating token is a unary
operator, the appropriate error is return, however, for a unary
operator, the appropriate error with "binary" in front of "operator" is
returned

getParenToken() modified to look for a parser error from getExpression()
otherwise if the terminating token is a unary operator, then the new
ExpBinOpCommaOrParen status is return

added new ExpBinOpOrComma, ExpBinOpCommaOrParen, ExpBinOpOrParen(), and
ExpBinOpSemiOrComma token statuses for unexpected unary operator errors;
reformatted token status messages array to prevent long line and
adjusted enums.awk for these changes

added several unexpected unary operator error statements to translator
test #14 (parser errors), most of which were not previously tested; old
translator fails many of these tests, so its output was saved to another
file (new translator passes all tests in #14 except for the
unimplemented PRINT and INPUT statements
  • Loading branch information
thunder422 committed Aug 1, 2013
1 parent b4a908b commit 87e4072
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 95 deletions.
4 changes: 4 additions & 0 deletions basic/let.cpp
Expand Up @@ -144,6 +144,10 @@ TokenStatus letTranslate(Translator &translator, Token *commandToken,
if ((status = translator.getExpression(token,
translator.equivalentDataType(dataType))) != Done_TokenStatus)
{
if (status == Parser_TokenStatus && token->isDataType(None_DataType))
{
status = ExpOpOrEnd_TokenStatus;
}
return status;
}

Expand Down
21 changes: 13 additions & 8 deletions enums.awk
Expand Up @@ -114,23 +114,28 @@ BEGIN {
# found end of token message array
msg_array = 0
}
else {
else
{
nf = split(line, field)
if (field[nf - 1] == "//")
if (field[1] == "//")
{
# 2012-10-06: remove the CR if present
cr = index(field[nf], "\r")
# remove the CR if present
name = field[2]
cr = index(name, "\r")
if (cr > 0)
{
field[nf] = substr(field[nf], 0, cr - 1)
name = substr(name, 0, cr - 1)
}
if (field[1] !~ /BUG/)
}
else
{
if (line !~ /BUG:/)
{
ts = field[nf] "_TokenStatus"
ts = name "_TokenStatus"
}
else
{
ts = "BUG_" field[nf]
ts = "BUG_" name
}

# check for duplicates
Expand Down
11 changes: 11 additions & 0 deletions test/translator14.dat
Expand Up @@ -140,3 +140,14 @@ INPUT PROMPT A$(1,.

INPUT PROMPT "A";A(1,?
INPUT PROMPT "A";A(1,1e999

# unexpected unary operator tests
Z = A NOT
Z = A + B NOT
Z = (A NOT
Z = INT(A NOT
Z = MID$(A$ NOT
Z = MID$(A$,5 NOT
Z = A(B NOT
MID$(A$ NOT
MID$(A$,5 NOT
31 changes: 29 additions & 2 deletions test/translator14.txt
Expand Up @@ -90,10 +90,10 @@ Input: MID$(..
^-- expected string variable

Input: MID$(A$?
^-- expected operator or comma
^-- expected comma

Input: MID$(A$.e
^-- expected operator or comma
^-- expected comma

Input: MID$(A$,?
^-- expected numeric expression
Expand Down Expand Up @@ -257,3 +257,30 @@ Input: INPUT PROMPT "A";A(1,?
Input: INPUT PROMPT "A";A(1,1e999
^^^^^-- floating point constant is out of range

Input: Z = A NOT
^^^-- expected binary operator or end-of-statement

Input: Z = A + B NOT
^^^-- expected binary operator or end-of-statement

Input: Z = (A NOT
^^^-- expected binary operator or closing parentheses

Input: Z = INT(A NOT
^^^-- expected binary operator or closing parentheses

Input: Z = MID$(A$ NOT
^^^-- expected binary operator or comma

Input: Z = MID$(A$,5 NOT
^^^-- expected binary operator, comma or closing parentheses

Input: Z = A(B NOT
^^^-- expected binary operator, comma or closing parentheses

Input: MID$(A$ NOT
^^^-- expected comma

Input: MID$(A$,5 NOT
^^^-- expected binary operator, comma or closing parentheses

194 changes: 131 additions & 63 deletions token.cpp
Expand Up @@ -33,71 +33,139 @@ int Token::s_prec[sizeof_TokenType];
bool Token::s_table[sizeof_TokenType];

// token status message array
// (TokenStatus enumeration generated from names
// in comments at the end each line by enums.awk,
// lines starting with comments are ignored)
// (TokenStatus enumeration generated from names in comments
// on the line before the line with the message string by enums.awk,
// extra lines starting with comments are ignored)
const QString Token::s_messageArray[sizeof_TokenStatus] = {
tr("Null_TokenStatus (BUG)"), // Null
tr("Good_TokenStatus (BUG)"), // Good
tr("Done_TokenStatus (BUG)"), // Done
tr("Parser_TokenStatus (BUG)"), // Parser
tr("expected command"), // ExpCmd
tr("expected expression"), // ExpExpr
tr("expected expression or end-of-statement"), // ExpExprOrEnd
tr("expected operator or end-of-statement"), // ExpOpOrEnd
tr("expected binary operator or end-of-statement"), // ExpBinOpOrEnd
tr("expected equal or comma for assignment"), // ExpEqualOrComma
tr("expected comma"), // ExpComma
tr("expected item for assignment"), // ExpAssignItem
tr("expected operator or comma"), // ExpOpOrComma
tr("expected operator, comma or closing parentheses"), // ExpOpCommaOrParen
tr("expected operator or closing parentheses"), // ExpOpOrParen
tr("expected double expression"), // ExpDouble
tr("expected integer expression"), // ExpInteger
tr("expected string expression (old)"), // ExpString
tr("expected numeric expression"), // ExpNumExpr
tr("expected string expression"), // ExpStrExpr
tr("expected semicolon, comma or end-of-statement"), // ExpSemiCommaOrEnd
tr("expected semicolon or comma"), // ExpSemiOrComma
tr("expected operator, semicolon or comma"), // ExpOpSemiOrComma
tr("expected double variable"), // ExpDblVar
tr("expected integer variable"), // ExpIntVar
tr("expected string variable"), // ExpStrVar
tr("expected variable"), // ExpVar
tr("expected string item for assignment"), // ExpStrItem
tr("expected end-of-statement"), // ExpEndStmt
// Null
tr("Null_TokenStatus (BUG)"),
// Good
tr("Good_TokenStatus (BUG)"),
// Done
tr("Done_TokenStatus (BUG)"),
// Parser
tr("Parser_TokenStatus (BUG)"),
// ExpCmd
tr("expected command"),
// ExpExpr
tr("expected expression"),
// ExpExprOrEnd
tr("expected expression or end-of-statement"),
// ExpOpOrEnd
tr("expected operator or end-of-statement"),
// ExpBinOpOrEnd
tr("expected binary operator or end-of-statement"),
// ExpEqualOrComma
tr("expected equal or comma for assignment"),
// ExpComma
tr("expected comma"),
// ExpAssignItem
tr("expected item for assignment"),
// ExpOpOrComma
tr("expected operator or comma"),
// ExpOpCommaOrParen
tr("expected operator, comma or closing parentheses"),
// ExpOpOrParen
tr("expected operator or closing parentheses"),
// ExpBinOpOrComma
tr("expected binary operator or comma"),
// ExpBinOpCommaOrParen
tr("expected binary operator, comma or closing parentheses"),
// ExpBinOpOrParen
tr("expected binary operator or closing parentheses"),
// ExpDouble
tr("expected double expression"),
// ExpInteger
tr("expected integer expression"),
// ExpString
tr("expected string expression (old)"),
// ExpNumExpr
tr("expected numeric expression"),
// ExpStrExpr
tr("expected string expression"),
// ExpSemiCommaOrEnd
tr("expected semicolon, comma or end-of-statement"),
// ExpSemiOrComma
tr("expected semicolon or comma"),
// ExpOpSemiOrComma
tr("expected operator, semicolon or comma"),
// ExpBinOpSemiOrComma
tr("expected binary operator, semicolon or comma"),
// ExpDblVar
tr("expected double variable"),
// ExpIntVar
tr("expected integer variable"),
// ExpStrVar
tr("expected string variable"),
// ExpVar
tr("expected variable"),
// ExpStrItem
tr("expected string item for assignment"),
// ExpEndStmt
tr("expected end-of-statement"),
// the following statuses used during development
tr("BUG: not yet implemented"), // NotYetImplemented
tr("BUG: invalid mode"), // InvalidMode
tr("BUG: hold stack empty"), // HoldStackEmpty
tr("BUG: hold stack not empty"), // HoldStackNotEmpty
tr("BUG: done stack not empty"), // DoneStackNotEmpty
tr("BUG: done stack empty - parentheses"), // DoneStackEmptyParen
tr("BUG: done stack empty - operands"), // DoneStackEmptyOperands
tr("BUG: done stack empty - operands 2"), // DoneStackEmptyOperands2
tr("BUG: done stack empty - find code"), // DoneStackEmptyFindCode
tr("BUG: unexpected closing parentheses"), // UnexpectedCloseParen
tr("BUG: unexpected token on hold stack"), // UnexpectedToken
tr("BUG: expected operand on done stack"), // DoneStackEmpty
tr("BUG: command stack not empty"), // CmdStackNotEmpty
tr("BUG: command stack empty"), // CmdStackEmpty
tr("BUG: command stack empty for expression"), // CmdStackEmptyExpr
tr("BUG: command stack empty for command"), // CmdStackEmptyCmd
tr("BUG: no assign list code found"), // NoAssignListCode
tr("BUG: invalid data type"), // InvalidDataType
tr("BUG: count stack empty"), // CountStackEmpty
tr("BUG: unexpected parentheses in expression"), // UnexpParenExpr
tr("BUG: unexpected token"), // UnexpToken
tr("BUG: debug #1"), // Debug1
tr("BUG: debug #2"), // Debug2
tr("BUG: debug #3"), // Debug3
tr("BUG: debug #4"), // Debug4
tr("BUG: debug #5"), // Debug5
tr("BUG: debug #6"), // Debug6
tr("BUG: debug #7"), // Debug7
tr("BUG: debug #8"), // Debug8
tr("BUG: debug #9"), // Debug9
tr("BUG: debug") // Debug
// NotYetImplemented
tr("BUG: not yet implemented"),
// InvalidMode
tr("BUG: invalid mode"),
// HoldStackEmpty
tr("BUG: hold stack empty"),
// HoldStackNotEmpty
tr("BUG: hold stack not empty"),
// DoneStackNotEmpty
tr("BUG: done stack not empty"),
// DoneStackEmptyParen
tr("BUG: done stack empty - parentheses"),
// DoneStackEmptyOperands
tr("BUG: done stack empty - operands"),
// DoneStackEmptyOperands2
tr("BUG: done stack empty - operands 2"),
// DoneStackEmptyFindCode
tr("BUG: done stack empty - find code"),
// UnexpectedCloseParen
tr("BUG: unexpected closing parentheses"),
// UnexpectedToken
tr("BUG: unexpected token on hold stack"),
// DoneStackEmpty
tr("BUG: expected operand on done stack"),
// CmdStackNotEmpty
tr("BUG: command stack not empty"),
// CmdStackEmpty
tr("BUG: command stack empty"),
// CmdStackEmptyExpr
tr("BUG: command stack empty for command"),
// CmdStackEmptyCmd
tr("BUG: command stack empty for expression"),
// NoAssignListCode
tr("BUG: no assign list code found"),
// InvalidDataType
tr("BUG: invalid data type"),
// CountStackEmpty
tr("BUG: count stack empty"),
// UnexpParenExpr
tr("BUG: unexpected parentheses in expression"),
// UnexpToken
tr("BUG: unexpected token"),
// Debug1
tr("BUG: debug #1"),
// Debug2
tr("BUG: debug #2"),
// Debug3
tr("BUG: debug #3"),
// Debug4
tr("BUG: debug #4"),
// Debug5
tr("BUG: debug #5"),
// Debug6
tr("BUG: debug #6"),
// Debug7
tr("BUG: debug #7"),
// Debug8
tr("BUG: debug #8"),
// Debug9
tr("BUG: debug #9"),
// Debug
tr("BUG: debug")
};


Expand Down

0 comments on commit 87e4072

Please sign in to comment.