From: Terence Parr <> Date: Thu, 14 Sep 1995 00:21:00 +0000 (-0500) Subject: auto commit for import X-Git-Url: https://pd.if.org/git/?p=pccts;a=commitdiff_plain;h=180c0e017ef63e91d69d9e5a781c9731e51e3fa4 auto commit for import --- diff --git a/testcpp/4/test.g b/testcpp/4/test.g new file mode 100755 index 0000000..8d71839 --- /dev/null +++ b/testcpp/4/test.g @@ -0,0 +1,45 @@ +/* This is test.g which tests a simple DLG-based scanner + * with user-defined tokens + */ + +/* Here, we use #tokdefs to define token types, but still let DLG do the + * lexing. ANTLR will not create a tokens.h file. + */ +#tokdefs "mytokens.h" + +<< +#include "DLGLexer.h" /* include definition of DLGLexer. + * This cannot be generated automatically because + * ANTLR has no idea what you will call this file + * with the DLG command-line options. + */ + +typedef ANTLRCommonToken ANTLRToken; + +int main() +{ + ANTLRTokenPtr aToken = new ANTLRToken; + DLGFileInput in(stdin); + DLGLexer scan(&in); + ANTLRTokenBuffer pipe(&scan); + scan.setToken(mytoken(aToken)); + Expr parser(&pipe); + parser.init(); + + parser.e(); + return 0; +} +>> + +#token "[\ \t\n]+" <> + +class Expr { /* Define a grammar class */ + +e : IDENTIFIER NUMBER "@" + <getText(), $2->getText());>> + ; + +} + +#token IDENTIFIER "[a-z]+" +#token NUMBER "[0-9]+"