add HAS AN keyword for grammatically correct declarations

http://forum.lolcode.org/viewtopic.php?f=4&t=13#p19
This commit is contained in:
D.E. Akers 2015-08-15 23:19:36 -04:00 committed by Justin Meza
parent f5f5edb889
commit bc32a948bf
8 changed files with 20 additions and 4 deletions

View File

@ -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 */

View File

@ -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

View File

@ -0,0 +1,2 @@
INCLUDE(AddLolTest)
ADD_LOL_TEST(11-AlternativeArticle OUTPUT test.out)

View File

@ -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

View File

@ -0,0 +1 @@
catmium

View File

@ -0,0 +1,2 @@
This test checks that variables may be declared using the
grammatically appropriate indefinite article.

View File

@ -8,3 +8,4 @@ add_subdirectory(7-AssignmentSameVariable)
add_subdirectory(8-TypeInitialization)
add_subdirectory(9-Deallocation)
add_subdirectory(10-Indirect)
add_subdirectory(11-AlternativeArticle)

View File

@ -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 */