From bc32a948bfbe991babe51334ffc832c2005f4e91 Mon Sep 17 00:00:00 2001 From: "D.E. Akers" <0x0dea@gmail.com> Date: Sat, 15 Aug 2015 23:19:36 -0400 Subject: [PATCH] add HAS AN keyword for grammatically correct declarations http://forum.lolcode.org/viewtopic.php?f=4&t=13#p19 --- parser.c | 8 +++++--- parser.h | 3 ++- .../6-Variables/11-AlternativeArticle/CMakeLists.txt | 2 ++ test/1.3-Tests/6-Variables/11-AlternativeArticle/test.lol | 5 +++++ test/1.3-Tests/6-Variables/11-AlternativeArticle/test.out | 1 + .../6-Variables/11-AlternativeArticle/test.readme | 2 ++ test/1.3-Tests/6-Variables/CMakeLists.txt | 1 + tokenizer.h | 2 ++ 8 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/1.3-Tests/6-Variables/11-AlternativeArticle/CMakeLists.txt create mode 100644 test/1.3-Tests/6-Variables/11-AlternativeArticle/test.lol create mode 100644 test/1.3-Tests/6-Variables/11-AlternativeArticle/test.out create mode 100644 test/1.3-Tests/6-Variables/11-AlternativeArticle/test.readme diff --git a/parser.c b/parser.c index 5727b90..1e15c00 100644 --- a/parser.c +++ b/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 */ diff --git a/parser.h b/parser.h index 4fc2e20..f935fe5 100644 --- a/parser.h +++ b/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 diff --git a/test/1.3-Tests/6-Variables/11-AlternativeArticle/CMakeLists.txt b/test/1.3-Tests/6-Variables/11-AlternativeArticle/CMakeLists.txt new file mode 100644 index 0000000..c7d7b87 --- /dev/null +++ b/test/1.3-Tests/6-Variables/11-AlternativeArticle/CMakeLists.txt @@ -0,0 +1,2 @@ +INCLUDE(AddLolTest) +ADD_LOL_TEST(11-AlternativeArticle OUTPUT test.out) diff --git a/test/1.3-Tests/6-Variables/11-AlternativeArticle/test.lol b/test/1.3-Tests/6-Variables/11-AlternativeArticle/test.lol new file mode 100644 index 0000000..7bcd8b8 --- /dev/null +++ b/test/1.3-Tests/6-Variables/11-AlternativeArticle/test.lol @@ -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 diff --git a/test/1.3-Tests/6-Variables/11-AlternativeArticle/test.out b/test/1.3-Tests/6-Variables/11-AlternativeArticle/test.out new file mode 100644 index 0000000..00eaef7 --- /dev/null +++ b/test/1.3-Tests/6-Variables/11-AlternativeArticle/test.out @@ -0,0 +1 @@ +catmium diff --git a/test/1.3-Tests/6-Variables/11-AlternativeArticle/test.readme b/test/1.3-Tests/6-Variables/11-AlternativeArticle/test.readme new file mode 100644 index 0000000..653a20d --- /dev/null +++ b/test/1.3-Tests/6-Variables/11-AlternativeArticle/test.readme @@ -0,0 +1,2 @@ +This test checks that variables may be declared using the +grammatically appropriate indefinite article. diff --git a/test/1.3-Tests/6-Variables/CMakeLists.txt b/test/1.3-Tests/6-Variables/CMakeLists.txt index 76135cd..273a0ec 100644 --- a/test/1.3-Tests/6-Variables/CMakeLists.txt +++ b/test/1.3-Tests/6-Variables/CMakeLists.txt @@ -8,3 +8,4 @@ add_subdirectory(7-AssignmentSameVariable) add_subdirectory(8-TypeInitialization) add_subdirectory(9-Deallocation) add_subdirectory(10-Indirect) +add_subdirectory(11-AlternativeArticle) diff --git a/tokenizer.h b/tokenizer.h index 7631f41..6f264f8 100644 --- a/tokenizer.h +++ b/tokenizer.h @@ -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 */