add HAS AN keyword for grammatically correct declarations
http://forum.lolcode.org/viewtopic.php?f=4&t=13#p19
This commit is contained in:
parent
f5f5edb889
commit
bc32a948bf
8
parser.c
8
parser.c
|
@ -2910,8 +2910,10 @@ StmtNode *parseDeclarationStmtNode(Token ***tokenp)
|
|||
if (!scope) goto parseDeclarationStmtNodeAbort;
|
||||
|
||||
/* Remove the declaration keywords from the token stream */
|
||||
if (!acceptToken(&tokens, TT_HASA)) {
|
||||
parser_error_expected_token(TT_HASA, tokens);
|
||||
status = acceptToken(&tokens, TT_HASA);
|
||||
if (!status) status = acceptToken(&tokens, TT_HASAN) || -1;
|
||||
if (status < 1) {
|
||||
parser_error_expected_token(TT_HASA - status, tokens);
|
||||
goto parseDeclarationStmtNodeAbort;
|
||||
}
|
||||
|
||||
|
@ -4190,7 +4192,7 @@ StmtNode *parseStmtNode(Token ***tokenp)
|
|||
ret = parseAssignmentStmtNode(tokenp);
|
||||
}
|
||||
/* Variable declaration */
|
||||
else if (peekToken(&tokens, TT_HASA)) {
|
||||
else if (peekToken(&tokens, TT_HASA) || peekToken(&tokens, TT_HASAN)) {
|
||||
ret = parseDeclarationStmtNode(tokenp);
|
||||
}
|
||||
/* Deallocation */
|
||||
|
|
3
parser.h
3
parser.h
|
@ -80,7 +80,8 @@
|
|||
*
|
||||
* \par
|
||||
* DeclarationStmtNode ::= IdentifierNode \c TT_HASA IdentifierNode
|
||||
* Initialization ? \c TT_NEWLINE
|
||||
* Initialization ? \c TT_NEWLINE | IdentifierNode \c TT_HASAN
|
||||
* IdentifierNode Initialization ? \c TT_NEWLINE
|
||||
*
|
||||
* \par
|
||||
* Initialization ::= \c TT_ITZ ExprNode | \c TT_ITZA TypeNode | \c TT_ITZLIEKA IdentifierNode
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
INCLUDE(AddLolTest)
|
||||
ADD_LOL_TEST(11-AlternativeArticle OUTPUT test.out)
|
|
@ -0,0 +1,5 @@
|
|||
HAI 1.3
|
||||
I HAS AN array ITZ A BUKKIT
|
||||
array HAS AN element ITZ "catmium"
|
||||
VISIBLE array'Z element
|
||||
KTHXBYE
|
|
@ -0,0 +1 @@
|
|||
catmium
|
|
@ -0,0 +1,2 @@
|
|||
This test checks that variables may be declared using the
|
||||
grammatically appropriate indefinite article.
|
|
@ -8,3 +8,4 @@ add_subdirectory(7-AssignmentSameVariable)
|
|||
add_subdirectory(8-TypeInitialization)
|
||||
add_subdirectory(9-Deallocation)
|
||||
add_subdirectory(10-Indirect)
|
||||
add_subdirectory(11-AlternativeArticle)
|
||||
|
|
|
@ -50,6 +50,7 @@ typedef enum {
|
|||
TT_HAI, /**< Beginning of main block. */
|
||||
TT_KTHXBYE, /**< End of main block. */
|
||||
TT_HASA, /**< Variable declaration. */
|
||||
TT_HASAN, /**< Variable declaration. */
|
||||
TT_ITZA, /**< Variable type initialization. */
|
||||
TT_ITZ, /**< Variable value initialization. */
|
||||
TT_RNOOB, /**< Deallocation. */
|
||||
|
@ -131,6 +132,7 @@ static const char *keywords[] = {
|
|||
"HAI", /* TT_HAI */
|
||||
"KTHXBYE", /* TT_KTHXBYE */
|
||||
"HAS A", /* TT_HASA */
|
||||
"HAS AN", /* TT_HASAN */
|
||||
"ITZ A", /* TT_ITZA */
|
||||
"ITZ", /* TT_ITZ */
|
||||
"R NOOB", /* TT_RNOOB */
|
||||
|
|
Loading…
Reference in New Issue