diff options
author | pacien | 2018-02-23 01:11:34 +0100 |
---|---|---|
committer | pacien | 2018-02-23 01:11:34 +0100 |
commit | 806dd4ff649a1fb9a28dc469cc17d7dd5dbc1da5 (patch) | |
tree | da414ebbb1807a2dea82235faa429f6e6613db69 /src/tpc.y | |
parent | 11acfa2e75350d31a665b8ee99925916c2c8b5f1 (diff) | |
download | tpc-compiler-806dd4ff649a1fb9a28dc469cc17d7dd5dbc1da5.tar.gz |
Adapt for new grammar
Diffstat (limited to 'src/tpc.y')
-rw-r--r-- | src/tpc.y | 215 |
1 files changed, 124 insertions, 91 deletions
@@ -12,103 +12,136 @@ void yyerror(char *); | |||
12 | 12 | ||
13 | %} | 13 | %} |
14 | 14 | ||
15 | %token CARACTERE NUM IDENT ORDER EQ ADDSUB DIVSTAR | 15 | %token CARACTERE NUM IDENT |
16 | %token OR AND CONST IF WHILE RETURN VOID TYPE | 16 | %token ADDSUB DIVSTAR |
17 | %token ORDER EQ OR AND | ||
18 | %token IF WHILE RETURN | ||
19 | %token CONST VOID TYPE | ||
20 | %token PRINT READC READE | ||
17 | 21 | ||
18 | %left ',' | 22 | %left ',' |
19 | %precedence ')' | 23 | %precedence ')' |
20 | %precedence ELSE | 24 | %precedence ELSE |
21 | 25 | ||
22 | %% | 26 | %% |
23 | Prog : DeclConsts DeclVars DeclFoncts | 27 | Prog: |
24 | ; | 28 | DeclConsts DeclVars DeclFoncts |
25 | DeclConsts : DeclConsts CONST ListConst ';' | 29 | ; |
26 | | | 30 | DeclConsts: |
27 | ; | 31 | DeclConsts CONST ListConst ';' |
28 | ListConst : ListConst ',' IDENT '=' Litteral | 32 | | |
29 | | IDENT '=' Litteral | 33 | ; |
30 | ; | 34 | ListConst: |
31 | Litteral : NombreSigne | 35 | ListConst ',' IDENT '=' Litteral |
32 | | CARACTERE | 36 | | IDENT '=' Litteral |
33 | ; | 37 | ; |
34 | NombreSigne : NUM | 38 | Litteral: |
35 | | ADDSUB NUM | 39 | NombreSigne |
36 | ; | 40 | | CARACTERE |
37 | DeclVars : DeclVars TYPE Declarateurs ';' | 41 | ; |
38 | | | 42 | NombreSigne: |
39 | ; | 43 | NUM |
40 | Declarateurs : Declarateurs ',' Declarateur | 44 | | ADDSUB NUM |
41 | | Declarateur | 45 | ; |
42 | ; | 46 | DeclVars: |
43 | Declarateur : IDENT | 47 | DeclVars TYPE Declarateurs ';' |
44 | | IDENT '[' NUM ']' | 48 | | |
45 | ; | 49 | ; |
46 | DeclFoncts : DeclFoncts DeclFonct | 50 | Declarateurs: |
47 | | DeclFonct | 51 | Declarateurs ',' Declarateur |
48 | ; | 52 | | Declarateur |
49 | DeclFonct : EnTeteFonct Corps | 53 | ; |
50 | ; | 54 | Declarateur: |
51 | EnTeteFonct : TYPE IDENT '(' Parametres ')' | 55 | IDENT |
52 | | VOID IDENT '(' Parametres ')' | 56 | | IDENT '[' NUM ']' |
53 | ; | 57 | ; |
54 | Parametres : VOID | 58 | DeclFoncts: |
55 | | ListTypVar | 59 | DeclFoncts DeclFonct |
56 | ; | 60 | | DeclFonct |
57 | ListTypVar : ListTypVar ',' TYPE IDENT | 61 | ; |
58 | | TYPE IDENT | 62 | DeclFonct: |
59 | ; | 63 | EnTeteFonct Corps |
60 | Corps : '{' DeclConsts DeclVars SuiteInstr '}' | 64 | ; |
61 | ; | 65 | EnTeteFonct: |
62 | SuiteInstr : SuiteInstr Instr | 66 | TYPE IDENT '(' Parametres ')' |
63 | | | 67 | | VOID IDENT '(' Parametres ')' |
64 | ; | 68 | ; |
65 | Instr : Exp ';' | 69 | Parametres: |
66 | | RETURN Exp ';' | 70 | VOID |
67 | | RETURN ';' | 71 | | ListTypVar |
68 | | ';' | 72 | ; |
69 | | IF '(' Exp ')' Instr | 73 | ListTypVar: |
70 | | IF '(' Exp ')' Instr ELSE Instr | 74 | ListTypVar ',' TYPE IDENT |
71 | | WHILE '(' Exp ')' Instr | 75 | | TYPE IDENT |
72 | | '{' SuiteInstr '}' | 76 | ; |
73 | ; | 77 | Corps: |
74 | Exp : LValue '=' Exp | 78 | '{' DeclConsts DeclVars SuiteInstr '}' |
75 | | EB | 79 | ; |
76 | ; | 80 | SuiteInstr: |
77 | EB : EB OR TB | 81 | SuiteInstr Instr |
78 | | TB | 82 | | ; |
79 | ; | 83 | Instr: |
80 | TB : TB AND FB | 84 | Exp ';' |
81 | | FB | 85 | | ';' |
82 | ; | 86 | | RETURN Exp ';' |
83 | FB : FB EQ M | 87 | | RETURN ';' |
84 | | M | 88 | | READE '(' IDENT ')' ';' |
85 | ; | 89 | | READC '(' IDENT ')' ';' |
86 | M : M ORDER E | 90 | | PRINT '(' Exp ')' ';' |
87 | | E | 91 | | IF '(' Exp ')' Instr |
88 | ; | 92 | | IF '(' Exp ')' Instr ELSE Instr |
89 | E : E ADDSUB T | 93 | | WHILE '(' Exp ')' Instr |
90 | | T | 94 | | '{' SuiteInstr '}' |
91 | ; | 95 | ; |
92 | T : T DIVSTAR F | 96 | Exp: |
93 | | F | 97 | LValue '=' Exp |
94 | ; | 98 | | EB |
95 | F : ADDSUB F | 99 | ; |
96 | | '!' F | 100 | EB: |
97 | | '(' Exp ')' | 101 | EB OR TB |
98 | | LValue | 102 | | TB |
99 | | NUM | 103 | ; |
100 | | CARACTERE | 104 | TB: |
101 | | IDENT '(' Arguments ')' | 105 | TB AND FB |
102 | ; | 106 | | FB |
103 | LValue : IDENT | 107 | ; |
104 | | IDENT '[' Exp ']' | 108 | FB: |
105 | ; | 109 | FB EQ M |
106 | Arguments : ListExp | 110 | | M |
107 | | | 111 | ; |
108 | ; | 112 | M: |
109 | ListExp : ListExp ',' ListExp | 113 | M ORDER E |
110 | | Exp | 114 | | E |
111 | ; | 115 | ; |
116 | E: | ||
117 | E ADDSUB T | ||
118 | | T | ||
119 | ; | ||
120 | T: | ||
121 | T DIVSTAR F | ||
122 | | F | ||
123 | ; | ||
124 | F: | ||
125 | ADDSUB F | ||
126 | | '!' F | ||
127 | | '(' Exp ')' | ||
128 | | LValue | ||
129 | | NUM | ||
130 | | CARACTERE | ||
131 | | IDENT '(' Arguments ')' | ||
132 | ; | ||
133 | LValue: | ||
134 | IDENT | ||
135 | | IDENT '[' Exp ']' | ||
136 | ; | ||
137 | Arguments: | ||
138 | ListExp | ||
139 | | | ||
140 | ; | ||
141 | ListExp: | ||
142 | ListExp ',' Exp | ||
143 | | Exp | ||
144 | ; | ||
112 | %% | 145 | %% |
113 | 146 | ||
114 | void yyerror(char *msg){ | 147 | void yyerror(char *msg){ |