From cc08e4aeb2f7d41ebc03b3f820dffcd666297ada Mon Sep 17 00:00:00 2001 From: Terence Parr <> Date: Wed, 13 Sep 1995 19:43:36 -0500 Subject: [PATCH] auto commit for import --- testcpp/9/test.g | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 testcpp/9/test.g diff --git a/testcpp/9/test.g b/testcpp/9/test.g new file mode 100755 index 0000000..6669c07 --- /dev/null +++ b/testcpp/9/test.g @@ -0,0 +1,49 @@ +/* This is test.g which tests simple AST refs and construction */ + +<< +typedef ANTLRCommonToken ANTLRToken; +#include "DLGLexer.h" +#include "PBlackBox.h" + +class AST : public ASTBase { +public: + ANTLRTokenPtr token; + AST(ANTLRTokenPtr t) { token = t; } + void preorder_action() { + char *s = token->getText(); + printf(" %s", s); + } +}; + +int main() +{ + ParserBlackBox p(stdin); + ASTBase *root = NULL; + p.parser()->e(&root); + root->preorder(); + printf("\n"); + root->destroy(); + return 0; +} +>> + +#token "[\ \t\n]+" <> +#token Eof "@" + +class Expr { /* Define a grammar class */ + +e : mult_expr ( ("\+"^|"\-"^) mult_expr )* + ; + +mult_expr + : atom ( ("\*"^|"\/"^) atom )* + ; + +atom: IDENTIFIER + | NUMBER + ; + +} + +#token IDENTIFIER "[a-z]+" +#token NUMBER "[0-9]+" -- 2.40.0