]> pd.if.org Git - pccts/blob - testcpp/4/test.g
auto commit for import
[pccts] / testcpp / 4 / test.g
1 /* This is test.g which tests a simple DLG-based scanner
2  * with user-defined tokens
3  */
4
5 /* Here, we use #tokdefs to define token types, but still let DLG do the
6  * lexing. ANTLR will not create a tokens.h file.
7  */
8 #tokdefs "mytokens.h"
9
10 <<
11 #include "DLGLexer.h"           /* include definition of DLGLexer.
12                                                          * This cannot be generated automatically because
13                                                          * ANTLR has no idea what you will call this file
14                                                          * with the DLG command-line options.
15                                                          */
16
17 typedef ANTLRCommonToken ANTLRToken;
18
19 int main()
20 {
21         ANTLRTokenPtr aToken = new ANTLRToken;
22         DLGFileInput in(stdin);
23         DLGLexer scan(&in);
24         ANTLRTokenBuffer pipe(&scan);
25         scan.setToken(mytoken(aToken));
26         Expr parser(&pipe);
27         parser.init();
28
29         parser.e();
30         return 0;
31 }
32 >>
33
34 #token "[\ \t\n]+"      <<skip();>>
35
36 class Expr {                            /* Define a grammar class */
37
38 e       :       IDENTIFIER NUMBER "@"
39                 <<fprintf(stderr, "text is %s,%s\n", $1->getText(), $2->getText());>>
40         ;
41
42 }
43
44 #token IDENTIFIER       "[a-z]+"
45 #token NUMBER           "[0-9]+"