Skip to content

Commit

Permalink
implemented support for multiple statement lines
Browse files Browse the repository at this point in the history
added check for colon token statement separator after processing a
command to getCommands(), which deletes the colon token and sets new
colon sub-code in the last token added to the rpn output list; added
end statement flag to colon code in table; added support for new colon
sub-colon to token text() function; added new translator test #16 with
various colon tests including errors (old translator segfaults on this
test)
  • Loading branch information
thunder422 committed Aug 23, 2013
1 parent a3a7152 commit 734521d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ibcp.h
Expand Up @@ -79,7 +79,8 @@ enum SubCode
Used_SubCode = 0x00000020, // parentheses used in output
Last_SubCode = 0x00000040, // parentheses used as last token
End_SubCode = 0x00000080, // end of INPUT parsing codes
UnUsed_SubCode = 0x00000100 // token not in output (for errors)
Colon_SubCode = 0x00000100, // reproduce ":" after token
UnUsed_SubCode = 0x10000000 // token not in output (for errors)
};


Expand Down
2 changes: 1 addition & 1 deletion table.cpp
Expand Up @@ -729,7 +729,7 @@ static TableEntry tableEntries[] =
},
{ // Colon_Code
Operator_TokenType, OneChar_Multiple,
":", NULL, Null_Flag, 4, None_DataType
":", NULL, EndStmt_Flag, 4, None_DataType
},
{ // RemOp_Code
Operator_TokenType, OneChar_Multiple,
Expand Down
22 changes: 22 additions & 0 deletions test/translator16.dat
@@ -0,0 +1,22 @@
###################################################
# Translator Test #15: Colon Tests (2013-04-05) #
###################################################

A=SQR(17):PRINT A
PRINT A:PRINT B
PRINT A;:PRINT B
INPUT A:PRINT A
A,B,C=5.0:INPUT D
A$,LEFT$(B$,1),MID$(C$,2,3)="A":PRINT A$
INPUT PROMPT "Number",A:PRINT A
INPUT PROMPT "Number";A:PRINT A
INPUT PROMPT "Number:";A:PRINT A
INPUT A;:PRINT A
PRINT A:REM output A
PRINT A:'output A:test
INPUT A;:R=SQR(A):PRINT"Sqrt(";A;")=";R

# colon error tests
:
PRINT:
PRINT::PRINT
49 changes: 49 additions & 0 deletions test/translator16.txt
@@ -0,0 +1,49 @@

Input: A=SQR(17):PRINT A
Output: A<ref> 17 CvtDbl SQR( Assign':' A PrintDbl PRINT

Input: PRINT A:PRINT B
Output: A PrintDbl PRINT':' B PrintDbl PRINT

Input: PRINT A;:PRINT B
Output: A PrintDbl ;':' B PrintDbl PRINT

Input: INPUT A:PRINT A
Output: InputParse InputBegin A<ref> InputAssign INPUT':' A PrintDbl PRINT

Input: A,B,C=5.0:INPUT D
Output: A<ref> B<ref> C<ref> 5.0 AssignList':' InputParse InputBegin D<ref> InputAssign INPUT

Input: A$,LEFT$(B$,1),MID$(C$,2,3)="A":PRINT A$
Output: A$<ref> B$<ref> 1 C$<ref> 2 3 "A" AssignKeepMid3 AssignKeepLeft Assign$':' A$ PrintStr PRINT

Input: INPUT PROMPT "Number",A:PRINT A
Output: "Number" InputParse InputBeginStr'Question' A<ref> InputAssign INPUT-PROMPT':' A PrintDbl PRINT

Input: INPUT PROMPT "Number";A:PRINT A
Output: "Number" InputParse InputBeginStr A<ref> InputAssign INPUT-PROMPT':' A PrintDbl PRINT

Input: INPUT PROMPT "Number:";A:PRINT A
Output: "Number:" InputParse InputBeginStr A<ref> InputAssign INPUT-PROMPT':' A PrintDbl PRINT

Input: INPUT A;:PRINT A
Output: InputParse InputBegin A<ref> InputAssign INPUT'Keep:' A PrintDbl PRINT

Input: PRINT A:REM output A
Output: A PrintDbl PRINT':' REM| output A|

Input: PRINT A:'output A:test
Output: A PrintDbl PRINT':' '|output A:test|

Input: INPUT A;:R=SQR(A):PRINT"Sqrt(";A;")=";R
Output: InputParse InputBegin A<ref> InputAssign INPUT'Keep:' R<ref> A SQR( Assign':' "Sqrt(" PrintStr A PrintDbl ")=" PrintStr R PrintDbl PRINT

Input: :
^-- expected command

Input: PRINT:
^-- expected command

Input: PRINT::PRINT
^-- expected command

4 changes: 4 additions & 0 deletions token.cpp
Expand Up @@ -401,6 +401,10 @@ QString Token::text(void)
{
string += "Question";
}
if (isSubCode(Colon_SubCode))
{
string += ":";
}
string += '\'';
}
return string;
Expand Down
8 changes: 7 additions & 1 deletion translator.cpp
Expand Up @@ -1796,7 +1796,13 @@ TokenStatus Translator::getCommands(Token *&token)
{
break;
}
else
else if (token->isCode(Colon_Code))
{
// delete uneeded colon token, set colon sub-code on last token
delete token;
outputLastToken()->setSubCodeMask(Colon_SubCode);
}
else // unknown end statement token, return to caller
{
return Done_TokenStatus;
}
Expand Down

0 comments on commit 734521d

Please sign in to comment.