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