zyvaflo.opp.exp 7.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
File "zyvaflo.mly", line 12, characters 61-71:
Warning: the token EQUALEQUAL is unused.
File "zyvaflo.mly", line 9, characters 16-22:
Warning: the token STRING is unused.
%{
open Primitive
open Pp
%}
%start main
%token WRITELN
%token WRITE
%token WHILE
%token VAR
%token THEN
%token <string> STRING
%token SEMISEMI
%token SEMI
%token RPAREN
%token REAL
%token READ
%token RBRACKET
%token PROGRAM
%token PROCEDURE
%token OF
%token LPAREN
%token LBRACKET
%token INTEGER
%token <int> INT
%token IF
%token <string> IDENT
%token FUNCTION
%token <string> FLOAT
%token END
%token ELSE
%token DOT
%token DO
%token COMMA
%token COLONEQUAL
%token COLON
%token BOOLEAN
%token <bool> BOOL
%token BEGIN
%token ARRAY
%token ALLOC
%token LESSGREATER
%token LESSEQUAL
%token LESS
%token GREATEREQUAL
%token GREATER
%token EQUALEQUAL
%token EQUAL
%token PLUS
%token MINUS
%token TIMES
%token DIV
%left LESSGREATER LESSEQUAL LESS GREATEREQUAL GREATER EQUALEQUAL EQUAL 
%left PLUS MINUS 
%left TIMES DIV 
%nonassoc UMINUS 
%type <Pp.program> main
%%

main:
64 65
| _1 = PROGRAM _2 = vars _3 = definitions _4 = body _5 = endtok
    {    ( {global_vars = _2; definitions = _3; main = _4 } )}
66 67

endtok:
68 69 70 71
| _1 = SEMISEMI
    {           (())}
| _1 = DOT
    {           (())}
72 73

vars:
74 75
| _1 = VAR _2 = args2
    {                              ( _2 )}
76
| 
77
    {                              ( [] )}
78 79

args2:
80 81
| _1 = declvar _2 = SEMI _3 = args2
    {                     ( _1 @ _3 )}
82
| 
83
    {                     ( [] )}
84 85

idents:
86 87 88 89
| _1 = IDENT _2 = COMMA _3 = idents
    {                     (_1 :: _3 )}
| _1 = IDENT
    {                     ( [ _1 ] )}
90 91

declvar:
92 93
| _1 = idents _2 = COLON _3 = type_expr
    {                                   ( List.map (fun x -> x, _3) _1 )}
94 95

definitions:
96 97
| _1 = fonction _2 = SEMI _3 = definitions
    {                                      ( _1 :: _3 )}
98
| 
99
    {                                      ( [] )}
100 101

fonction:
102 103 104 105
| _1 = FUNCTION _2 = IDENT _3 = LPAREN _4 = args _5 = RPAREN _6 = COLON _7 = type_expr _8 = SEMI _9 = vars _10 = body
    {    ( _2, { arguments = _4; result = Some _7; local_vars = _9; body = _10 } )}
| _1 = PROCEDURE _2 = IDENT _3 = LPAREN _4 = args _5 = RPAREN _6 = SEMI _7 = vars _8 = body
    {    ( _2, { arguments = _4; result = None; local_vars = _7; body = _8 } )}
106 107

args:
108 109
| _1 = declvar _2 = args1
    {                                      ( _1 @ _2 )}
110
| 
111
    {                                      ( [] )}
112 113

args1:
114 115
| _1 = SEMI _2 = declvar _3 = args1
    {                                      ( _2 @ _3 )}
116
| 
117
    {                                      ( [] )}
118 119

instruction:
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
| _1 = IDENT _2 = COLONEQUAL _3 = expression
    {                                      ( Set (_1, _3) )}
| _1 = BEGIN _2 = bloc _3 = END
    {                                      ( Sequence _2 )}
| _1 = IF _2 = expression _3 = THEN _4 = instruction _5 = ELSE _6 = instruction
    {                                      ( If (_2, _4, _6) )}
| _1 = WHILE _2 = expression _3 = DO _4 = instruction
    {                                      ( While (_2, _4) )}
| _1 = IDENT _2 = LPAREN _3 = arguments _4 = RPAREN
    {                                      ( Procedure_call (_1, _3) )}
| _1 = READ _2 = LPAREN _3 = IDENT _4 = RPAREN
    {                                      ( Read (_3) )}
| _1 = WRITE _2 = LPAREN _3 = expression _4 = RPAREN
    {                                      ( Write (_3) )}
| _1 = WRITELN _2 = LPAREN _3 = expression _4 = RPAREN
    {                                      ( Writeln (_3) )}
| _1 = array_expression _2 = LBRACKET _3 = expression _4 = RBRACKET _5 = COLONEQUAL _6 = expression
    {                                      ( Seti (_1, _3, _6) )}
138 139

body:
140 141
| _1 = BEGIN _2 = bloc _3 = END
    {                                      ( _2 )}
142 143

bloc:
144 145
| _1 = instruction _2 = bloc1
    {                                      ( _1 :: _2 )}
146
| 
147
    {                                      ( [] )}
148 149

bloc1:
150 151
| _1 = SEMI _2 = instruction _3 = bloc1
    {                                      ( _2 :: _3 )}
152
| 
153
    {                                      ( [] )}
154 155

arguments:
156 157
| _1 = expression _2 = arguments1
    {                                      ( _1 :: _2 )}
158
| 
159
    {                                      ( [] )}
160 161

arguments1:
162 163
| _1 = COMMA _2 = expression _3 = arguments1
    {                                      ( _2 :: _3 )}
164
| 
165
    {                                      ( [] )}
166 167

expression:
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| _1 = LPAREN _2 = expression _3 = RPAREN
    {                                      ( _2 )}
| _1 = INT
    {                                      ( Int _1 )}
| _1 = FLOAT
    {                                      ( Float _1 )}
| _1 = MINUS _2 = expression %prec UMINUS
    {                                      ( Bin (Op Sub, Int 0, _2) )}
| _1 = BOOL
    {                                      ( Bool _1 )}
| _1 = IDENT
    {                                      ( Get _1 )}
| _1 = call_expression
    {                                      ( _1 )}
| _1 = array_expression _2 = LBRACKET _3 = expression _4 = RBRACKET
    {                                      ( Geti (_1, _3) )}
| _1 = expression _2 = PLUS _3 = expression
    {                                      ( Bin (Op Add, _1, _3) )}
| _1 = expression _2 = MINUS _3 = expression
    {                                      ( Bin (Op Sub, _1, _3) )}
| _1 = expression _2 = TIMES _3 = expression
    {                                      ( Bin (Op Mul, _1, _3) )}
| _1 = expression _2 = DIV _3 = expression
    {                                      ( Bin (Op Div, _1, _3) )}
| _1 = expression _2 = LESS _3 = expression
    {                                      ( Bin (Cmp Lt, _1, _3) )}
| _1 = expression _2 = LESSEQUAL _3 = expression
    {                                      ( Bin (Cmp Le, _1, _3) )}
| _1 = expression _2 = GREATER _3 = expression
    {                                      ( Bin (Cmp Gt, _1, _3) )}
| _1 = expression _2 = GREATEREQUAL _3 = expression
    {                                      ( Bin (Cmp Ge, _1, _3) )}
| _1 = expression _2 = EQUAL _3 = expression
    {                                      ( Bin (Cmp Eq, _1, _3) )}
| _1 = expression _2 = LESSGREATER _3 = expression
    {                                      ( Bin (Cmp Ne, _1, _3) )}
204 205

array_expression:
206 207 208 209 210 211 212 213
| _1 = IDENT
    {        ( Get _1 )}
| _1 = array_expression _2 = LBRACKET _3 = expression _4 = RBRACKET
    {                                                ( Geti (_1, _3) )}
| _1 = call_expression
    {                  ( _1 )}
| _1 = LPAREN _2 = expression _3 = RPAREN
    {                           ( _2 )}
214 215

call_expression:
216 217 218 219
| _1 = IDENT _2 = LPAREN _3 = arguments _4 = RPAREN
    {                                      ( Function_call (_1, _3) )}
| _1 = ALLOC _2 = LPAREN _3 = expression _4 = COLON _5 = type_expr _6 = RPAREN
    {                                      ( Alloc (_3,_5) )}
220 221

type_expr:
222 223 224 225 226 227 228 229
| _1 = INTEGER
    {                                       ( Integer )}
| _1 = REAL
    {                                       ( Real )}
| _1 = BOOLEAN
    {                                       ( Boolean )}
| _1 = ARRAY _2 = OF _3 = type_expr
    {                                       ( Array (_3) )}
230 231 232 233 234

%%