improve constant loading. Still sucks, but oh well
[oota-llvm.git] / utils / Burg / gram.yc
1 %{
2 char rcsid_gram[] = "$Id$";
3
4 #include <stdio.h>
5 #include "b.h"
6 #include "fe.h"
7 void doGram(List);
8 %}
9
10 %union {
11         int y_int;
12         char *y_string;
13         Arity y_arity;
14         Binding y_binding;
15         PatternAST y_patternAST;
16         RuleAST y_ruleAST;
17         List y_list;
18         IntList y_intlist;
19 }
20
21 %start full
22
23 %term ERROR
24 %term K_TERM
25 %term K_GRAM
26 %term K_START
27 %term K_PPERCENT
28 %term INT
29 %term ID
30
31 %token <y_string> ID
32 %token <y_int> INT
33
34 %type <y_arity> decl
35 %type <y_binding> binding
36 %type <y_intlist> cost costtail
37 %type <y_ruleAST> rule
38 %type <y_patternAST> pattern
39 %type <y_list> decls rules bindinglist grammarlist
40 %%
41
42
43 full    : spec
44         | spec K_PPERCENT
45                 { yyfinished(); }
46         ;
47
48 spec    : decls K_PPERCENT rules
49                 { doSpec($1, $3); }
50         ;
51
52 decls   : /* lambda */  { $$ = 0; }
53         | decls decl    { $$ = newList($2, $1); }
54         ;
55
56 decl    : K_TERM bindinglist    { $$ = newArity(-1, $2); }
57         | K_GRAM grammarlist    { $$ = 0; doGram($2); }
58         | K_START ID            { $$ = 0; doStart($2); }        /* kludge */
59         ;
60
61 grammarlist     : /* lambda */          { $$ = 0; }
62                 | grammarlist ID        { $$ = newList($2, $1); }
63                 ;
64
65 bindinglist     : /* lambda */          { $$ = 0; }
66                 | bindinglist binding   { $$ = newList($2, $1); }
67                 ;
68
69 binding : ID '=' INT    { $$ = newBinding($1, $3); }
70         ;
71
72 rules   : /* lambda */  { $$ = 0; }
73         | rules rule    { $$ = newList($2, $1); }
74         ;
75
76 rule    : ID ':' pattern '=' INT cost ';'       { $$ = newRuleAST($1, $3, $5, $6); }
77                 ;
78
79 pattern : ID                                    { $$ = newPatternAST($1, 0); }
80         | ID '(' pattern ')'                    { $$ = newPatternAST($1, newList($3,0)); }
81         | ID '(' pattern ',' pattern ')'        { $$ = newPatternAST($1, newList($3, newList($5, 0))); }
82         ;
83
84 cost    : /* lambda */          { $$ = 0; }
85         | '(' INT costtail ')'  { $$ = newIntList($2, $3); }
86         ;
87
88 costtail        : /* lambda */          { $$ = 0; }
89                 | ',' INT costtail      { $$ = newIntList($2, $3); }
90                 | INT costtail          { $$ = newIntList($1, $2); }
91                 ;