Debian Codegraph @

yo/concrete/poly2/parser/grammar

raw
1 //HEAD
2 %filenames parser
3 %scanner ../scanner/scanner.h
4 %baseclass-preinclude ../spsembase/spsembase.h
5 %stype spSemBase
6
7 %token INT IDENT
8 //=
9 %%
10
11 //RULES
12 rules:
13 rules rule
14 |
15 rule
16 ;
17 //=
18
19 //INT
20 int:
21 INT
22 {
23 $$ = new Semantic<Tag::INT>(A2x(d_scanner.matched()).to<int>());
24 }
25 ;
26
27 ident:
28 IDENT
29 {
30 $$ = new Semantic<Tag::TEXT>(d_scanner.matched());
31 }
32 ;
33 //=
34
35 //ARGS
36 value:
37 int
38 |
39 ident
40 ;
41
42 arglist:
43 arglist ',' value
44 {
45 $1->as<Tag::VECTOR>().push_back($3);
46 }
47 |
48 value
49 {
50 $$ = new Semantic<Tag::VECTOR>(
51 vector<shared_ptr<SemBase const>> {$1});
52 }
53 ;
54 //=
55
56 //RULE
57 rule:
58 ident '(' arglist ')' ';'
59 {
60 display($1, $3);
61 }
62 |
63 ident '=' int ';'
64 {
65 cout << $1->as<Tag::TEXT>() << " = " << $3->as<Tag::INT>() << ";\n";
66 }
67 ;
68 //=
69