]> pd.if.org Git - pccts/blob - testcpp/3/test.g
auto commit for import
[pccts] / testcpp / 3 / test.g
1 /* Ariel Tamches (tamches@cs.wisc.edu):
2  * This tests linking in a simple non-DLG scanner with user-defined token
3  * types.
4  */
5
6 /* All TokenType's must have some end-of-file token;  You must define
7  * it with setEofToken() to your end of input token.
8  *
9  * We assume that #tokdefs is  employed for this example; i.e., ANTLR does
10  * NOT assign token numbers.
11  *
12  * ANTLR option -gx must be used to turn off generation of DLG crud (when you
13  * want to define your own token stream).
14  */
15
16 #tokdefs "mytokens.h"
17
18 /* user should define ANTLRToken outside of #header since AToken.h would
19  * not have been included yet.  You can force inclusion of AToken.h if
20  * you must use #header, however.
21  */
22 <<
23 typedef ANTLRCommonToken ANTLRToken;    /* use a predefined Token class */
24 >>
25
26 /* At this point, ANTLRToken and ANTLRTokenStream are defined, user must now
27  * derive a class from ANTLRTokenStream (which embodies the user's scanner)
28  */
29 <<#include "MyLexer.h">>
30
31 <<
32 int main()
33 {
34         /* create one of my scanners */
35         MyLexer scan;
36         ANTLRTokenBuffer pipe(&scan);
37         /* create a parser of type Expr hooked to my scanner */
38         Expr parser(&pipe);
39         parser.init();
40         parser.setEofToken(Eof);
41
42         parser.e();                             /* start parsing at rule 'e' of that parser */
43         return 0;
44 }
45 >>
46
47 class Expr {
48
49 e       :       IDENTIFIER NUMBER
50                 <<fprintf(stderr, "text is %s,%s\n", $1->getText(), $2->getText());>>
51                 Eof
52         ;
53
54 }