2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
47 (* Not clear how to allow function declarations to specify a return type
48 and how to allow both to be specified as static, because they are in
49 different rules. The rules seem to have to be combined, which would allow
50 functions to be declared as local variables *)
52 (* Not clear how to let a function have a parameter of type void. At the
53 moment, void is allowed to be the type of a variable, which is wrong, and a
54 parameter needs both a type and an identifier *)
56 module Ast0 = Ast0_cocci
57 module Ast = Ast_cocci
60 if !Flag.verbose_parsing
61 then Common.warning s v
64 let make_info line logical_line =
65 { Ast.line = line; Ast.logical_line = logical_line }
67 let clt2info (_,line,logical_line) = make_info line logical_line
69 let clt2mcode str = function
70 (Data.MINUS,line,lline) ->
72 (Ast.MINUS({Ast.line=line;Ast.logical_line=lline},ref[])))
73 | (Data.OPTMINUS,line,lline) ->
75 (Ast.MINUS({Ast.line=line;Ast.logical_line=lline},ref[])))
76 | (Data.UNIQUEMINUS,line,lline) ->
78 (Ast.MINUS({Ast.line=line;Ast.logical_line=lline},ref[])))
79 | (Data.MULTIMINUS,line,lline) ->
81 (Ast.MINUS({Ast.line=line;Ast.logical_line=lline},ref[])))
82 | (Data.PLUS,line,lline) ->
83 (str,Ast0.NONE,Ast.PLUS({Ast.line=line;Ast.logical_line=lline}))
84 | (Data.CONTEXT,line,lline) ->
86 Ast.CONTEXT({Ast.line=line;Ast.logical_line=lline},ref Ast.NOTHING))
87 | (Data.OPT,line,lline) ->
89 Ast.CONTEXT({Ast.line=line;Ast.logical_line=lline},ref Ast.NOTHING))
90 | (Data.UNIQUE,line,lline) ->
92 Ast.CONTEXT({Ast.line=line;Ast.logical_line=lline},ref Ast.NOTHING))
93 | (Data.MULTI,line,lline) ->
95 Ast.CONTEXT({Ast.line=line;Ast.logical_line=lline},ref Ast.NOTHING))
97 let id2name (name, clt) = name
98 let id2clt (name, clt) = clt
99 let id2info (name, clt) = clt2info clt
100 let id2mcode (name, clt) = clt2mcode name clt
102 let arith_op ast_op left op right =
103 Ast0.Binary(left, clt2mcode (Ast.Arith ast_op) op, right)
105 let logic_op ast_op left op right =
106 Ast0.Binary(left, clt2mcode (Ast.Logical ast_op) op, right)
109 if List.exists (function Ast0.Circles(_) -> true | _ -> false) l
111 else if List.exists (function Ast0.Stars(_) -> true | _ -> false) l
120 %token TIdentifier TExpression TStatement TFunction TLocal TType TParameter
121 %token TWhy0 TPlus0 TBang0 Tlist TFresh TConstant TError TWords
123 %token<Data.line_type * int * int> Tchar Tshort Tint Tdouble Tfloat Tlong Tvoid
124 %token<Data.line_type * int * int> Tstruct Tunion
125 %token<Data.line_type * int * int> Tunsigned Tsigned
127 %token<Data.line_type * int * int> Tstatic Tconst Tvolatile
129 %token <Data.line_type * int * int> TIf TElse TWhile TFor TDo TReturn
130 %token <string * (Data.line_type * int * int)> TIdent TFunName TMetaFunName
131 %token <string * (Data.line_type * int * int)> TMetaId TMetaType TMetaErr
132 %token <string * (Data.line_type * int * int)> TMetaParam TMetaParamList
133 %token <string * (Data.line_type * int * int)> TMetaStm TMetaStmList TMetaFunc
134 %token <string * (Data.line_type * int * int)> TMetaLocalFunc TMetaExpList
135 %token <string * Ast0_cocci.fullType list option * (Data.line_type*int*int)>
139 %token <Data.line_type * int * int> TEllipsis TOEllipsis TCEllipsis
140 %token <Data.line_type * int * int> TWhen
142 %token <Data.line_type * int * int> TCircles TOCircles TCCircles
143 %token <Data.line_type * int * int> TStars TOStars TCStars
145 %token <Data.line_type * int * int> TWhy TDotDot TBang TOPar TOPar0 TMid
146 %token <Data.line_type * int * int> TMid0 TCPar TCPar0
148 %token <string * (Data.line_type * int * int)> TInclude TMinusFile TPlusFile
150 %token <Data.line_type * int * int> TInc TDec
152 %token <string * (Data.line_type * int * int)> TString TChar TFloat TInt
154 %token <Data.line_type * int * int> TOrLog
155 %token <Data.line_type * int * int> TAndLog
156 %token <Data.line_type * int * int> TOr
157 %token <Data.line_type * int * int> TXor
158 %token <Data.line_type * int * int> TAnd
159 %token <Data.line_type * int * int> TEqEq TNotEq
160 %token <Data.line_type * int * int> TInf TSup TInfEq TSupEq
161 %token <Data.line_type * int * int> TShl TShr
162 %token <Data.line_type * int * int> TPlus TMinus
163 %token <Data.line_type * int * int> TMul TDiv TMod
165 %token <Data.line_type * int * int> TOBrace TCBrace
166 %token <Data.line_type * int * int> TOCro TCCro
168 %token <Data.line_type * int * int> TPtrOp
170 %token <Data.line_type * int * int> TEq TDot TComma TPtVirg
171 %token <Ast_cocci.assignOp * (Data.line_type * int * int)> TAssign
173 /* operator precedence */
183 %left TInf TSup TInfEq TSupEq
189 %type <Ast0_cocci.rule> main
192 %type <Ast_cocci.metavar list> meta_main
198 main: body EOF { $1 } | body TArobArob { $1 }
199 meta_main: meta_var_list_opt TArobArob { $1 }
201 /*****************************************************************************
204 *****************************************************************************/
207 arity TIdentifier pure_ident_or_meta_ident_list TPtVirg
210 !Data.add_id_meta name;
211 Ast.MetaIdDecl($1,name))
213 | arity TFresh TIdentifier pure_ident_or_meta_ident_list TPtVirg
216 !Data.add_id_meta name;
217 Ast.MetaFreshIdDecl($1,name))
219 | arity TType pure_ident_or_meta_ident_list TPtVirg
222 !Data.add_type_meta name;
223 Ast.MetaTypeDecl($1,name))
225 | arity TParameter pure_ident_or_meta_ident_list TPtVirg
228 !Data.add_param_meta name;
229 Ast.MetaParamDecl($1,name))
231 | arity TParameter Tlist pure_ident_or_meta_ident_list TPtVirg
234 !Data.add_paramlist_meta name;
235 Ast.MetaParamListDecl($1,name))
237 | arity TError pure_ident_or_meta_ident_list TPtVirg
240 !Data.add_err_meta name;
241 Ast.MetaErrDecl($1,name))
243 | arity TExpression pure_ident_or_meta_ident_list TPtVirg
246 !Data.add_exp_meta None name;
247 Ast.MetaExpDecl($1,name))
249 | arity TExpression Tlist pure_ident_or_meta_ident_list TPtVirg
252 !Data.add_explist_meta name;
253 Ast.MetaExpListDecl($1,name))
255 | arity TStatement pure_ident_or_meta_ident_list TPtVirg
258 !Data.add_stm_meta name;
259 Ast.MetaStmDecl($1,name))
261 | arity TStatement Tlist pure_ident_or_meta_ident_list TPtVirg
264 !Data.add_stmlist_meta name;
265 Ast.MetaStmListDecl($1,name))
267 | arity TFunction pure_ident_or_meta_ident_list TPtVirg
270 !Data.add_func_meta name;
271 Ast.MetaFuncDecl($1,name))
273 | arity TLocal TFunction pure_ident_or_meta_ident_list TPtVirg
276 !Data.add_local_func_meta name;
277 Ast.MetaLocalFuncDecl($1,name))
279 | arity meta_exp_type pure_ident_or_meta_ident_list TPtVirg
282 !Data.add_exp_meta (Some $2) name;
283 Ast.MetaExpDecl($1,name))
285 | arity TConstant meta_exp_type pure_ident_or_meta_ident_list TPtVirg
288 !Data.add_const_meta (Some $3) name;
289 Ast.MetaConstDecl($1,name))
291 | arity TConstant pure_ident_or_meta_ident_list TPtVirg
294 !Data.add_const_meta None name;
295 Ast.MetaConstDecl($1,name))
300 | TOBrace ctype_list TCBrace { $2 }
302 arity: TBang0 { Ast.UNIQUE }
304 | TPlus0 { Ast.MULTI }
305 | /* empty */ { Ast.NONE }
308 { Ast0.BaseType(clt2mcode Ast.VoidType $1, None) }
310 { Ast0.BaseType(clt2mcode Ast.CharType $2, $1) }
311 | ctype_qualif Tshort
312 { Ast0.BaseType(clt2mcode Ast.ShortType $2, $1) }
314 { Ast0.BaseType(clt2mcode Ast.IntType $2, $1) }
316 { Ast0.BaseType(clt2mcode Ast.DoubleType $1, None) }
318 { Ast0.BaseType(clt2mcode Ast.FloatType $1, None) }
320 { Ast0.BaseType(clt2mcode Ast.LongType $2, $1) }
322 { Ast0.StructUnionName(id2mcode $2,clt2mcode Ast.Struct $1) }
324 { Ast0.StructUnionName(id2mcode $2,clt2mcode Ast.Union $1) }
326 { Ast0.Pointer($1,clt2mcode "*" $2) }
328 { let (nm,clt) = $1 in Ast0.MetaType(clt2mcode nm clt) }
332 { Some (clt2mcode Ast.Unsigned $1) }
334 { Some (clt2mcode Ast.Signed $1) }
335 | /* empty */ { None }
339 { Ast0.BaseType(clt2mcode Ast.VoidType $1, None) }
341 { Ast0.BaseType(clt2mcode Ast.CharType $2, $1) }
342 | ctype_qualif Tshort
343 { Ast0.BaseType(clt2mcode Ast.ShortType $2, $1) }
345 { Ast0.BaseType(clt2mcode Ast.IntType $2, $1) }
347 { Ast0.BaseType(clt2mcode Ast.DoubleType $1, None) }
349 { Ast0.BaseType(clt2mcode Ast.FloatType $1, None) }
351 { Ast0.BaseType(clt2mcode Ast.LongType $2, $1) }
353 { Ast0.StructUnionName(id2mcode $2,clt2mcode Ast.Struct $1) }
355 { Ast0.StructUnionName(id2mcode $2,clt2mcode Ast.Union $1) }
356 | pure_ident { Ast0.TypeName(id2mcode $1) }
357 | param_ctype TMul { Ast0.Pointer($1,clt2mcode "*" $2) }
359 { let (nm,clt) = $1 in Ast0.MetaType(clt2mcode nm clt) }
361 /*****************************************************************************/
363 /* have to inline everything to avoid conflicts? switch to proper
364 declarations, statements, and expressions for the subterms */
366 body: function_decl_statement_or_expression { Top_level.top_level $1 }
369 /*****************************************************************************/
372 storage TFunName TOPar decl_list TCPar
373 TOBrace pre_post_decl_statement_and_expression_opt TCBrace
374 { Ast0.FunDecl($1, Ast0.Id(id2mcode $2), clt2mcode "(" $3, $4,
375 clt2mcode ")" $5, clt2mcode "{" $6, $7,
377 | storage TMetaFunName TOPar decl_list TCPar
378 TOBrace pre_post_decl_statement_and_expression_opt TCBrace
379 { Ast0.FunDecl($1, Ast0.MetaFunc(id2mcode $2), clt2mcode "(" $3, $4,
380 clt2mcode ")" $5, clt2mcode "{" $6, $7,
383 storage: Tstatic { Some (clt2mcode Ast.Static $1) }
384 | /* empty */ { None }
386 decl: decl_qualif param_ctype ident
387 { Ast0.Param($3, $1, $2) }
389 { let (nm,clt) = $1 in Ast0.MetaParam(clt2mcode nm clt) }
392 Tconst { Some (clt2mcode Ast.Const $1) }
393 | Tvolatile { Some (clt2mcode Ast.Volatile $1) }
394 | /* empty */ { None }
396 /*****************************************************************************/
400 { let (nm,clt) = $1 in Ast0.MetaStmt(clt2mcode nm clt) }
402 { Ast0.ExprStatement ($1, clt2mcode ";" $2) }
403 | TIf TOPar eexpr TCPar single_statement %prec TIf
404 { Ast0.IfThen(clt2mcode "if" $1,
405 clt2mcode "(" $2,$3,clt2mcode ")" $4,$5) }
406 | TIf TOPar eexpr TCPar single_statement TElse single_statement
407 { Ast0.IfThenElse(clt2mcode "if" $1,
408 clt2mcode "(" $2,$3,clt2mcode ")" $4,$5,
409 clt2mcode "else" $6,$7) }
410 | TFor TOPar eexpr_opt TPtVirg eexpr_opt TPtVirg eexpr_opt TCPar
412 { Ast0.For(clt2mcode "for" $1,clt2mcode "(" $2,$3,
413 clt2mcode ";" $4,$5,clt2mcode ";" $6,$7,clt2mcode ")" $8,$9) }
414 | TWhile TOPar eexpr TCPar single_statement
415 { Ast0.While(clt2mcode "while" $1,
416 clt2mcode "(" $2,$3,clt2mcode ")" $4,$5) }
417 | TDo single_statement TWhile TOPar eexpr TCPar TPtVirg
418 { Ast0.Do(clt2mcode "do" $1,$2,clt2mcode "while" $3,
419 clt2mcode "(" $4,$5,clt2mcode ")" $6, clt2mcode ";" $7) }
420 | TReturn eexpr TPtVirg
421 { Ast0.ReturnExpr(clt2mcode "return" $1,$2,clt2mcode ";" $3) }
423 { Ast0.Return(clt2mcode "return" $1,clt2mcode ";" $2) }
424 | TOBrace pre_post_decl_statement_and_expression_opt TCBrace
425 { Ast0.Seq(clt2mcode "{" $1,$2,clt2mcode "}" $3) }
426 | TOEllipsis decl_statement_or_expression_dots TCEllipsis
427 { Ast0.Nest(Ast0.DOTS($2)) }
428 | TOCircles decl_statement_or_expression_circles TCCircles
429 { Ast0.Nest(Ast0.CIRCLES($2)) }
430 | TOStars decl_statement_or_expression_stars TCStars
431 { Ast0.Nest(Ast0.STARS($2)) }
433 /* In the following, an identifier as a type is not fully supported. Indeed,
434 the language is ambiguous: what is foo * bar; */
435 decl_var: ctype d_ident_list TPtVirg
437 (function (id,fn) -> Ast0.UnInit(fn $1,id,clt2mcode ";" $3))
439 | ctype d_ident TEq eexpr TPtVirg
440 { let (id,fn) = $2 in
441 [Ast0.Init(fn $1,id,clt2mcode "=" $3,$4,clt2mcode ";" $5)] }
442 | pure_ident d_ident TPtVirg
443 { let (id,fn) = $2 in
444 [Ast0.UnInit(fn (Ast0.TypeName(id2mcode $1)),id,clt2mcode ";" $3)] }
445 | pure_ident d_ident TEq eexpr TPtVirg
446 { let (id,fn) = $2 in
447 [Ast0.Init(fn(Ast0.TypeName(id2mcode $1)),id,
448 clt2mcode "=" $3,$4,clt2mcode ";" $5)] }
452 { ($1,function x -> x) }
453 | ident TOCro eexpr_opt TCCro
454 { ($1,function x -> Ast0.Array(x,clt2mcode "[" $2,$3,clt2mcode "]" $4)) }
456 /* a statement on its own */
459 | TOPar0 statement_mid TCPar0
462 /* a statement that is part of a list */
465 { let (nm,clt) = $1 in [Ast0.MetaStmt(clt2mcode nm clt)] }
467 { List.map (function x -> Ast0.Decl(x)) $1 }
469 | TOPar0 pre_post_decl_statement_and_expression_opt_mid TCPar0
470 { if List.for_all (function Ast0.DOTS([]) -> true | _ -> false) $2
472 else [Ast0.Disj($2)] }
474 /*****************************************************************************/
477 /*****************************************************************************/
478 /* The following cannot contain <... ...> at the top level. This can only
479 be allowed as an expression when the expression is delimited on both sides
480 by expression-specific markers. In that case, the rule eexpr is used, which
481 allows <... ...> anywhere. Hopefully, this will not be too much of a problem
484 expr: assign_expr { $1 }
488 | unary_expr TAssign assign_expr
489 { let (op,clt) = $2 in Ast0.Assignment($1,clt2mcode op clt,$3) }
490 | unary_expr TEq assign_expr
491 { Ast0.Assignment($1,clt2mcode Ast.SimpleAssign $2,$3) }
493 cond_expr: arith_expr { $1 }
494 | arith_expr TWhy eexpr_opt TDotDot cond_expr
495 { Ast0.CondExpr ($1, clt2mcode "?" $2, $3, clt2mcode "?" $4, $5) }
497 arith_expr: cast_expr { $1 }
498 | arith_expr TMul arith_expr { arith_op Ast.Mul $1 $2 $3 }
499 | arith_expr TDiv arith_expr { arith_op Ast.Div $1 $2 $3 }
500 | arith_expr TMod arith_expr { arith_op Ast.Mod $1 $2 $3 }
501 | arith_expr TPlus arith_expr { arith_op Ast.Plus $1 $2 $3 }
502 | arith_expr TMinus arith_expr { arith_op Ast.Minus $1 $2 $3 }
503 | arith_expr TShl arith_expr { arith_op Ast.DecLeft $1 $2 $3 }
504 | arith_expr TShr arith_expr { arith_op Ast.DecRight $1 $2 $3 }
505 | arith_expr TInf arith_expr { logic_op Ast.Inf $1 $2 $3 }
506 | arith_expr TSup arith_expr { logic_op Ast.Sup $1 $2 $3 }
507 | arith_expr TInfEq arith_expr { logic_op Ast.InfEq $1 $2 $3 }
508 | arith_expr TSupEq arith_expr { logic_op Ast.SupEq $1 $2 $3 }
509 | arith_expr TEqEq arith_expr { logic_op Ast.Eq $1 $2 $3 }
510 | arith_expr TNotEq arith_expr { logic_op Ast.NotEq $1 $2 $3 }
511 | arith_expr TAnd arith_expr { arith_op Ast.And $1 $2 $3 }
512 | arith_expr TOr arith_expr { arith_op Ast.Or $1 $2 $3 }
513 | arith_expr TXor arith_expr { arith_op Ast.Xor $1 $2 $3 }
514 | arith_expr TAndLog arith_expr { logic_op Ast.AndLog $1 $2 $3 }
515 | arith_expr TOrLog arith_expr { logic_op Ast.OrLog $1 $2 $3 }
517 cast_expr: unary_expr { $1 }
518 | TOPar ctype TCPar cast_expr
519 { Ast0.Cast (clt2mcode "(" $1, $2, clt2mcode ")" $3, $4) }
521 unary_expr: postfix_expr { $1 }
523 { Ast0.Infix ($2, clt2mcode Ast.Inc $1) }
525 { Ast0.Infix ($2, clt2mcode Ast.Dec $1) }
526 | unary_op unary_expr
527 { let mcode = $1 in Ast0.Unary($2, mcode) }
529 unary_op: TAnd { clt2mcode Ast.GetRef $1 }
530 | TMul { clt2mcode Ast.DeRef $1 }
531 | TPlus { clt2mcode Ast.UnPlus $1 }
532 | TMinus { clt2mcode Ast.UnMinus $1 }
533 | TBang { clt2mcode Ast.Not $1 }
535 postfix_expr: primary_expr { $1 }
536 | postfix_expr TOCro eexpr TCCro
537 { Ast0.ArrayAccess ($1,clt2mcode "[" $2,$3,clt2mcode "]" $4) }
538 | postfix_expr TDot ident
539 { Ast0.RecordAccess($1, clt2mcode "." $2, $3) }
540 | postfix_expr TPtrOp ident
541 { Ast0.RecordPtAccess($1, clt2mcode "->" $2, $3) }
543 { Ast0.Postfix ($1, clt2mcode Ast.Inc $2) }
545 { Ast0.Postfix ($1, clt2mcode Ast.Dec $2) }
546 | postfix_expr TOPar eexpr_list_opt TCPar
547 { Ast0.FunCall($1,clt2mcode "(" $2,$3,clt2mcode ")" $4) }
549 primary_expr: ident { Ast0.Ident($1) }
551 { let (x,clt) = $1 in
552 Ast0.Constant (clt2mcode (Ast.Int x) clt) }
554 { let (x,clt) = $1 in
555 Ast0.Constant (clt2mcode (Ast.Float x) clt) }
557 { let (x,clt) = $1 in
558 Ast0.Constant (clt2mcode (Ast.String x) clt) }
560 { let (x,clt) = $1 in
561 Ast0.Constant (clt2mcode (Ast.Char x) clt) }
563 { let (nm,ty,clt) = $1 in Ast0.MetaConst(clt2mcode nm clt,ty) }
565 { let (nm,clt) = $1 in Ast0.MetaErr(clt2mcode nm clt) }
567 { let (nm,ty,clt) = $1 in Ast0.MetaExpr(clt2mcode nm clt,ty) }
569 { Ast0.Paren(clt2mcode "(" $1,$2,clt2mcode ")" $3) }
570 | TOPar0 expr_mid TCPar0 { Ast0.DisjExpr($2) }
572 /*****************************************************************************/
574 eexpr: eassign_expr { $1 }
576 eassign_expr: econd_expr { $1 }
577 | eunary_expr TAssign eassign_expr
578 { let (op,clt) = $2 in
579 Ast0.Assignment($1,clt2mcode op clt,$3) }
580 | eunary_expr TEq eassign_expr
581 { Ast0.Assignment($1,clt2mcode Ast.SimpleAssign $2,$3) }
583 econd_expr: earith_expr { $1 }
584 | earith_expr TWhy eexpr_opt TDotDot econd_expr
585 { Ast0.CondExpr ($1, clt2mcode "?" $2, $3, clt2mcode "?" $4, $5) }
587 earith_expr: ecast_expr { $1 }
588 | earith_expr TMul earith_expr { arith_op Ast.Mul $1 $2 $3 }
589 | earith_expr TDiv earith_expr { arith_op Ast.Div $1 $2 $3 }
590 | earith_expr TMod earith_expr { arith_op Ast.Mod $1 $2 $3 }
591 | earith_expr TPlus earith_expr { arith_op Ast.Plus $1 $2 $3 }
592 | earith_expr TMinus earith_expr { arith_op Ast.Minus $1 $2 $3 }
593 | earith_expr TShl earith_expr { arith_op Ast.DecLeft $1 $2 $3 }
594 | earith_expr TShr earith_expr { arith_op Ast.DecRight $1 $2 $3 }
595 | earith_expr TInf earith_expr { logic_op Ast.Inf $1 $2 $3 }
596 | earith_expr TSup earith_expr { logic_op Ast.Sup $1 $2 $3 }
597 | earith_expr TInfEq earith_expr { logic_op Ast.InfEq $1 $2 $3 }
598 | earith_expr TSupEq earith_expr { logic_op Ast.SupEq $1 $2 $3 }
599 | earith_expr TEqEq earith_expr { logic_op Ast.Eq $1 $2 $3 }
600 | earith_expr TNotEq earith_expr { logic_op Ast.NotEq $1 $2 $3 }
601 | earith_expr TAnd earith_expr { arith_op Ast.And $1 $2 $3 }
602 | earith_expr TOr earith_expr { arith_op Ast.Or $1 $2 $3 }
603 | earith_expr TXor earith_expr { arith_op Ast.Xor $1 $2 $3 }
604 | earith_expr TAndLog earith_expr { logic_op Ast.AndLog $1 $2 $3 }
605 | earith_expr TOrLog earith_expr { logic_op Ast.OrLog $1 $2 $3 }
607 ecast_expr: eunary_expr { $1 }
608 | TOPar ctype TCPar ecast_expr
609 { Ast0.Cast (clt2mcode "(" $1, $2, clt2mcode ")" $3, $4) }
611 eunary_expr: epostfix_expr { $1 }
613 { Ast0.Infix ($2, clt2mcode Ast.Inc $1) }
615 { Ast0.Infix ($2, clt2mcode Ast.Dec $1) }
616 | unary_op eunary_expr
617 { let mcode = $1 in Ast0.Unary($2, mcode) }
619 epostfix_expr: eprimary_expr { $1 }
620 | epostfix_expr TOCro eexpr TCCro
621 { Ast0.ArrayAccess ($1,clt2mcode "[" $2,$3,clt2mcode "]" $4) }
622 | epostfix_expr TDot ident
623 { Ast0.RecordAccess($1, clt2mcode "." $2, $3) }
624 | epostfix_expr TPtrOp ident
625 { Ast0.RecordPtAccess($1, clt2mcode "->" $2, $3) }
627 { Ast0.Postfix ($1, clt2mcode Ast.Inc $2) }
629 { Ast0.Postfix ($1, clt2mcode Ast.Dec $2) }
630 | epostfix_expr TOPar eexpr_list_opt TCPar
631 { Ast0.FunCall($1,clt2mcode "(" $2,$3,clt2mcode ")" $4) }
633 eprimary_expr: ident { Ast0.Ident($1) }
634 | TEllipsis { Ast0.Edots(clt2mcode "..." $1,None) }
636 { let (x,clt) = $1 in
637 Ast0.Constant (clt2mcode (Ast.Int x) clt) }
639 { let (x,clt) = $1 in
640 Ast0.Constant (clt2mcode (Ast.Float x) clt) }
642 { let (x,clt) = $1 in
643 Ast0.Constant (clt2mcode (Ast.String x) clt) }
645 { let (x,clt) = $1 in
646 Ast0.Constant (clt2mcode (Ast.Char x) clt) }
648 { let (nm,ty,clt) = $1 in Ast0.MetaConst(clt2mcode nm clt,ty) }
650 { let (nm,clt) = $1 in Ast0.MetaErr(clt2mcode nm clt) }
652 { let (nm,ty,clt) = $1 in Ast0.MetaExpr(clt2mcode nm clt,ty) }
654 { Ast0.Paren(clt2mcode "(" $1,$2,clt2mcode ")" $3) }
655 | TOPar0 eexpr_mid TCPar0
656 { Ast0.DisjExpr($2) }
657 | TOEllipsis expr_dots TCEllipsis
658 { Ast0.NestExpr(Ast0.DOTS($2)) }
659 | TOCircles expr_circles TCCircles
660 { Ast0.NestExpr(Ast0.CIRCLES($2)) }
661 | TOStars expr_stars TCStars
662 { Ast0.NestExpr(Ast0.STARS($2)) }
664 /*****************************************************************************/
666 dexpr: dassign_expr { $1 }
668 dassign_expr: dcond_expr { $1 }
669 | dunary_expr TAssign dassign_expr
670 { let (op,clt) = $2 in
671 Ast0.Assignment($1,clt2mcode op clt,$3) }
672 | dunary_expr TEq dassign_expr
673 { Ast0.Assignment($1,clt2mcode Ast.SimpleAssign $2,$3) }
675 dcond_expr: darith_expr { $1 }
676 | darith_expr TWhy eexpr_opt TDotDot dcond_expr
677 { Ast0.CondExpr ($1, clt2mcode "?" $2, $3, clt2mcode "?" $4, $5) }
679 darith_expr: dcast_expr { $1 }
680 | darith_expr TMul darith_expr { arith_op Ast.Mul $1 $2 $3 }
681 | darith_expr TDiv darith_expr { arith_op Ast.Div $1 $2 $3 }
682 | darith_expr TMod darith_expr { arith_op Ast.Mod $1 $2 $3 }
683 | darith_expr TPlus darith_expr { arith_op Ast.Plus $1 $2 $3 }
684 | darith_expr TMinus darith_expr { arith_op Ast.Minus $1 $2 $3 }
685 | darith_expr TShl darith_expr { arith_op Ast.DecLeft $1 $2 $3 }
686 | darith_expr TShr darith_expr { arith_op Ast.DecRight $1 $2 $3 }
687 | darith_expr TInf darith_expr { logic_op Ast.Inf $1 $2 $3 }
688 | darith_expr TSup darith_expr { logic_op Ast.Sup $1 $2 $3 }
689 | darith_expr TInfEq darith_expr { logic_op Ast.InfEq $1 $2 $3 }
690 | darith_expr TSupEq darith_expr { logic_op Ast.SupEq $1 $2 $3 }
691 | darith_expr TEqEq darith_expr { logic_op Ast.Eq $1 $2 $3 }
692 | darith_expr TNotEq darith_expr { logic_op Ast.NotEq $1 $2 $3 }
693 | darith_expr TAnd darith_expr { arith_op Ast.And $1 $2 $3 }
694 | darith_expr TOr darith_expr { arith_op Ast.Or $1 $2 $3 }
695 | darith_expr TXor darith_expr { arith_op Ast.Xor $1 $2 $3 }
696 | darith_expr TAndLog darith_expr { logic_op Ast.AndLog $1 $2 $3 }
697 | darith_expr TOrLog darith_expr { logic_op Ast.OrLog $1 $2 $3 }
699 dcast_expr: dunary_expr { $1 }
700 | TOPar ctype TCPar dcast_expr
701 { Ast0.Cast (clt2mcode "(" $1, $2, clt2mcode ")" $3, $4) }
703 dunary_expr: dpostfix_expr { $1 }
705 { Ast0.Infix ($2, clt2mcode Ast.Inc $1) }
707 { Ast0.Infix ($2, clt2mcode Ast.Dec $1) }
708 | unary_op dunary_expr
709 { let mcode = $1 in Ast0.Unary($2, mcode) }
711 dpostfix_expr: dprimary_expr { $1 }
712 | dpostfix_expr TOCro eexpr TCCro
713 { Ast0.ArrayAccess ($1,clt2mcode "[" $2,$3,clt2mcode "]" $4) }
714 | dpostfix_expr TDot ident
715 { Ast0.RecordAccess($1, clt2mcode "." $2, $3) }
716 | dpostfix_expr TPtrOp ident
717 { Ast0.RecordPtAccess($1, clt2mcode "->" $2, $3) }
719 { Ast0.Postfix ($1, clt2mcode Ast.Inc $2) }
721 { Ast0.Postfix ($1, clt2mcode Ast.Dec $2) }
722 | dpostfix_expr TOPar eexpr_list_opt TCPar
723 { Ast0.FunCall($1,clt2mcode "(" $2,$3,clt2mcode ")" $4) }
725 dprimary_expr: ident { Ast0.Ident($1) }
727 { let (x,clt) = $1 in
728 Ast0.Constant (clt2mcode (Ast.Int x) clt) }
730 { let (x,clt) = $1 in
731 Ast0.Constant (clt2mcode (Ast.Float x) clt) }
733 { let (x,clt) = $1 in
734 Ast0.Constant (clt2mcode (Ast.String x) clt) }
736 { let (x,clt) = $1 in
737 Ast0.Constant (clt2mcode (Ast.Char x) clt) }
739 { let (nm,ty,clt) = $1 in Ast0.MetaConst(clt2mcode nm clt,ty) }
741 { let (nm,clt) = $1 in Ast0.MetaErr(clt2mcode nm clt) }
743 { let (nm,ty,clt) = $1 in Ast0.MetaExpr(clt2mcode nm clt,ty) }
745 { Ast0.Paren(clt2mcode "(" $1,$2,clt2mcode ")" $3) }
746 | TOPar0 eexpr_mid TCPar0
747 { Ast0.DisjExpr($2) }
748 | TOEllipsis expr_dots TCEllipsis
749 { Ast0.NestExpr(Ast0.DOTS($2)) }
750 | TOCircles expr_circles TCCircles
751 { Ast0.NestExpr(Ast0.CIRCLES($2)) }
752 | TOStars expr_stars TCStars
753 { Ast0.NestExpr(Ast0.STARS($2)) }
757 | dexpr TEllipsis expr_dots
758 { $1 :: Ast0.Edots(clt2mcode "..." $2,None) :: $3 }
759 | dexpr TEllipsis TWhen TNotEq eexpr TLineEnd expr_dots
760 { $1 :: Ast0.Edots(clt2mcode "..." $2,Some $5) :: $7 }
764 | dexpr TCircles expr_circles
765 { $1 :: Ast0.Ecircles(clt2mcode "ooo" $2,None) :: $3 }
766 | dexpr TCircles TWhen TNotEq eexpr TLineEnd expr_dots
767 { $1 :: Ast0.Ecircles(clt2mcode "ooo" $2,Some $5) :: $7 }
771 | dexpr TStars expr_stars
772 { $1 :: Ast0.Estars(clt2mcode "***" $2,None) :: $3 }
773 | dexpr TStars TWhen TNotEq eexpr TLineEnd expr_dots
774 { $1 :: Ast0.Estars(clt2mcode "***" $2,Some $5) :: $7 }
776 /*****************************************************************************/
778 pure_ident: TIdent { $1 }
780 /* allows redeclaring metavariables. used in @@ @@ */
781 pure_ident_or_meta_ident:
786 | TMetaParamList { $1 }
788 | TMetaStmList { $1 }
790 | TMetaLocalFunc { $1 }
791 | TMetaExpList { $1 }
792 | TMetaConst { let (name,_,info) = $1 in (name,info) }
793 | TMetaExp { let (name,_,info) = $1 in (name,info) }
796 ident: TIdent { Ast0.Id(id2mcode $1) }
797 | TMetaId { Ast0.MetaId(id2mcode $1) }
798 | TMetaFunc { Ast0.MetaFunc(id2mcode $1) }
799 | TMetaLocalFunc { Ast0.MetaLocalFunc(id2mcode $1) }
801 /*****************************************************************************/
803 meta_var_list: meta_var { $1 }
804 | meta_var meta_var_list { $1@$2 }
806 meta_var_list_opt: meta_var_list { $1 }
809 d_ident_list: d_ident { [$1] }
810 | d_ident TComma d_ident_list { $1::$3 }
812 ctype_list: ctype { [$1] }
813 | ctype TComma ctype_list { $1::$3 }
815 pure_ident_or_meta_ident_list:
816 pure_ident_or_meta_ident
818 | pure_ident_or_meta_ident TComma pure_ident_or_meta_ident_list
823 { if List.exists (function Ast0.Pcircles(_) -> true | _ -> false) $1
824 then Ast0.CIRCLES($1)
830 { let (nm,clt) = $1 in [Ast0.MetaParamList(clt2mcode nm clt)] }
832 { [Ast0.Pdots(clt2mcode "..." $1)] }
834 { [Ast0.Pcircles(clt2mcode "ooo" $1)] }
835 | decl TComma decl_list_start
836 { $1::Ast0.PComma(clt2mcode "," $2)::$3 }
837 | TMetaParamList TComma decl_list_start
838 { let (nm,clt) = $1 in
839 Ast0.MetaParamList(clt2mcode nm clt)::
840 Ast0.PComma(clt2mcode "," $2)::$3 }
841 | TEllipsis TComma decl_list_dots
842 { Ast0.Pdots(clt2mcode "..." $1)::
843 Ast0.PComma(clt2mcode "," $2)::
845 | TCircles TComma decl_list_circles
846 { Ast0.Pcircles(clt2mcode "ooo" $1)::
847 Ast0.PComma(clt2mcode "," $2)::
853 { let (nm,clt) = $1 in [Ast0.MetaParamList(clt2mcode nm clt)] }
855 { [Ast0.Pdots(clt2mcode "..." $1)] }
856 | decl TComma decl_list_dots
857 { $1::Ast0.PComma(clt2mcode "," $2)::$3 }
858 | TMetaParamList TComma decl_list_dots
859 { let (nm,clt) = $1 in
860 Ast0.MetaParamList(clt2mcode nm clt)::
861 Ast0.PComma(clt2mcode "," $2)::$3 }
862 | TEllipsis TComma decl_list_dots
863 { Ast0.Pdots(clt2mcode "..." $1)::Ast0.PComma(clt2mcode "," $2)::
869 { let (nm,clt) = $1 in [Ast0.MetaParamList(clt2mcode nm clt)] }
871 { [Ast0.Pcircles(clt2mcode "ooo" $1)] }
872 | decl TComma decl_list_circles
873 { $1::Ast0.PComma(clt2mcode "," $2)::$3 }
874 | TMetaParamList TComma decl_list_circles
875 { let (nm,clt) = $1 in
876 Ast0.MetaParamList(clt2mcode nm clt)::
877 Ast0.PComma(clt2mcode "," $2)::$3 }
878 | TCircles TComma decl_list_circles
879 { Ast0.Pcircles(clt2mcode "ooo" $1)::
880 Ast0.PComma(clt2mcode "," $2)::
883 /* must be a single statement */
885 statement { [Ast0.DOTS([$1])] }
886 | statement TMid0 statement_mid { Ast0.DOTS([$1])::$3 }
888 /* must be a list of declarations or statements, with no ... or expressions
890 pure_decl_statement_list:
891 decl_statement { $1 }
892 | decl_statement pure_decl_statement_list { $1@$2 }
894 /* as above, but allows a single expression - for "or" case */
895 exp_decl_statement_list:
896 expr { [Ast0.Exp($1)] }
897 | decl_statement { $1 }
898 | decl_statement pure_decl_statement_list { $1@$2 }
900 fun_exp_decl_statement_list:
902 { [Ast0.OTHER(Ast0.Exp($1))] }
904 { List.map (function x -> Ast0.OTHER x) $1 }
906 { [Ast0.FUNCTION($1)] }
908 { [Ast0.INCLUDE(clt2mcode "#include" (id2clt $1),id2mcode $1)] }
909 | TMinusFile TPlusFile
910 { [Ast0.FILEINFO(id2mcode $1,id2mcode $2)] }
911 | decl_statement fun_exp_decl_statement_list
912 { (List.map (function x -> Ast0.OTHER x) $1)@$2 }
913 | fundecl fun_exp_decl_statement_list
914 { Ast0.FUNCTION($1)::$2 }
915 | TInclude fun_exp_decl_statement_list
916 { Ast0.INCLUDE(clt2mcode "#include" (id2clt $1),id2mcode $1)::$2 }
917 | TMinusFile TPlusFile fun_exp_decl_statement_list
918 { Ast0.FILEINFO(id2mcode $1,id2mcode $2)::$3 }
920 /* ---------------------------------------------------------------------- */
923 TError TWords TEq TOCro dotless_eexpr_list TCCro
924 { Ast0.ERRORWORDS($5) }
926 /* ---------------------------------------------------------------------- */
927 /* sequences of statements and expressions */
929 /* a mix of declarations, statements and expressions. an expression may
930 appear by itself. always nonempty and cannot just be dots. */
932 function_decl_statement_or_expression:
933 error_words /* only at the end */
935 | fun_exp_decl_statement_list
937 | fun_exp_decl_statement_list TEllipsis
938 function_decl_statement_or_expression_dots
939 { $1@Ast0.OTHER(Ast0.Dots(clt2mcode "..." $2,None))::$3 }
940 | TEllipsis function_decl_statement_or_expression_dots
941 { Ast0.OTHER(Ast0.Dots(clt2mcode "..." $1,None))::$2 }
942 | fun_exp_decl_statement_list TEllipsis
943 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
944 function_decl_statement_or_expression_dots
945 { $1@Ast0.OTHER(Ast0.Dots(clt2mcode "..." $2,Some $5))::$7 }
946 | TEllipsis TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
947 function_decl_statement_or_expression_dots
948 { Ast0.OTHER(Ast0.Dots(clt2mcode "..." $2,Some $4))::$6 }
949 | fun_exp_decl_statement_list TCircles
950 function_decl_statement_or_expression_circles
951 { $1@Ast0.OTHER(Ast0.Circles(clt2mcode "ooo" $2,None))::$3 }
952 | TCircles function_decl_statement_or_expression_circles
953 { Ast0.OTHER(Ast0.Circles(clt2mcode "ooo" $1,None))::$2 }
954 | fun_exp_decl_statement_list TCircles
955 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
956 function_decl_statement_or_expression_circles
957 { $1@Ast0.OTHER(Ast0.Circles(clt2mcode "ooo" $2,Some $5))::$7 }
958 | TCircles TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
959 function_decl_statement_or_expression_circles
960 { Ast0.OTHER(Ast0.Circles(clt2mcode "ooo" $1,Some $4))::$6 }
961 | fun_exp_decl_statement_list TStars
962 function_decl_statement_or_expression_stars
963 { $1@Ast0.OTHER(Ast0.Stars(clt2mcode "***" $2,None))::$3 }
964 | TStars function_decl_statement_or_expression_stars
965 { Ast0.OTHER(Ast0.Stars(clt2mcode "***" $1,None))::$2 }
966 | fun_exp_decl_statement_list TStars
967 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
968 function_decl_statement_or_expression_stars
969 { $1@Ast0.OTHER(Ast0.Stars(clt2mcode "***" $2,Some $5))::$7 }
970 | TStars TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
971 function_decl_statement_or_expression_stars
972 { Ast0.OTHER(Ast0.Stars(clt2mcode "***" $1,Some $4))::$6 }
974 function_decl_statement_or_expression_dots:
976 | fun_exp_decl_statement_list
978 | fun_exp_decl_statement_list TEllipsis
979 function_decl_statement_or_expression_dots
980 { $1@Ast0.OTHER(Ast0.Dots(clt2mcode "..." $2,None))::$3 }
981 | fun_exp_decl_statement_list TEllipsis
982 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
983 function_decl_statement_or_expression_dots
984 { $1@Ast0.OTHER(Ast0.Dots(clt2mcode "..." $2,Some $5))::$7 }
986 function_decl_statement_or_expression_circles:
988 | fun_exp_decl_statement_list
990 | fun_exp_decl_statement_list TCircles
991 function_decl_statement_or_expression_circles
992 { $1@Ast0.OTHER(Ast0.Circles(clt2mcode "ooo" $2,None))::$3 }
993 | fun_exp_decl_statement_list TCircles
994 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
995 function_decl_statement_or_expression_circles
996 { $1@Ast0.OTHER(Ast0.Circles(clt2mcode "ooo" $2,Some $5))::$7 }
998 function_decl_statement_or_expression_stars:
1000 | fun_exp_decl_statement_list
1002 | fun_exp_decl_statement_list TStars
1003 function_decl_statement_or_expression_stars
1004 { $1@Ast0.OTHER(Ast0.Stars(clt2mcode "***" $2,None))::$3 }
1005 | fun_exp_decl_statement_list TStars
1006 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1007 function_decl_statement_or_expression_stars
1008 { $1@Ast0.OTHER(Ast0.Stars(clt2mcode "***" $2,Some $5))::$7 }
1010 decl_statement_or_expression_dots:
1011 exp_decl_statement_list
1013 | exp_decl_statement_list TEllipsis decl_statement_or_expression_dots
1014 { $1@Ast0.Dots(clt2mcode "..." $2,None)::$3 }
1015 | exp_decl_statement_list TEllipsis
1016 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1017 decl_statement_or_expression_dots
1018 { $1@Ast0.Dots(clt2mcode "..." $2,Some $5)::$7 }
1020 decl_statement_or_expression_circles:
1021 exp_decl_statement_list
1023 | exp_decl_statement_list TCircles decl_statement_or_expression_circles
1024 { $1@Ast0.Dots(clt2mcode "..." $2,None)::$3 }
1025 | exp_decl_statement_list TCircles
1026 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1027 decl_statement_or_expression_circles
1028 { $1@Ast0.Dots(clt2mcode "..." $2,Some $5)::$7 }
1030 decl_statement_or_expression_stars:
1031 exp_decl_statement_list
1033 | exp_decl_statement_list TStars decl_statement_or_expression_stars
1034 { $1@Ast0.Stars(clt2mcode "***" $2,None)::$3 }
1035 | exp_decl_statement_list TStars
1036 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1037 decl_statement_or_expression_stars
1038 { $1@Ast0.Stars(clt2mcode "***" $2,Some $5)::$7 }
1040 post_decl_statement_or_expression:
1041 exp_decl_statement_list
1043 | exp_decl_statement_list TEllipsis
1044 { $1@[Ast0.Dots(clt2mcode "..." $2,None)] }
1045 | exp_decl_statement_list TEllipsis
1046 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1047 { $1@[Ast0.Dots(clt2mcode "..." $2,Some $5)] }
1048 | exp_decl_statement_list TCircles
1049 { $1@[Ast0.Circles(clt2mcode "ooo" $2,None)] }
1050 | exp_decl_statement_list TCircles
1051 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1052 { $1@[Ast0.Circles(clt2mcode "ooo" $2,Some $5)] }
1053 | exp_decl_statement_list TStars
1054 { $1@[Ast0.Stars(clt2mcode "***" $2,None)] }
1055 | exp_decl_statement_list TStars
1056 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1057 { $1@[Ast0.Stars(clt2mcode "***" $2,Some $5)] }
1058 | exp_decl_statement_list TEllipsis post_decl_statement_or_expression_dots
1059 { $1@Ast0.Dots(clt2mcode "..." $2,None)::$3 }
1060 | exp_decl_statement_list TEllipsis
1061 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1062 post_decl_statement_or_expression_dots
1063 { $1@Ast0.Dots(clt2mcode "..." $2,Some $5)::$7 }
1064 | exp_decl_statement_list TCircles post_decl_statement_or_expression_dots
1065 { $1@Ast0.Circles(clt2mcode "ooo" $2,None)::$3 }
1066 | exp_decl_statement_list TCircles
1067 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1068 post_decl_statement_or_expression_dots
1069 { $1@Ast0.Circles(clt2mcode "ooo" $2,Some $5)::$7 }
1070 | exp_decl_statement_list TStars post_decl_statement_or_expression_dots
1071 { $1@Ast0.Stars(clt2mcode "***" $2,None)::$3 }
1072 | exp_decl_statement_list TStars
1073 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1074 post_decl_statement_or_expression_dots
1075 { $1@Ast0.Stars(clt2mcode "***" $2,Some $5)::$7 }
1077 post_decl_statement_or_expression_dots:
1078 exp_decl_statement_list
1080 | exp_decl_statement_list TEllipsis
1081 { $1@[Ast0.Dots(clt2mcode "..." $2,None)] }
1082 | exp_decl_statement_list TEllipsis
1083 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1084 { $1@[Ast0.Dots(clt2mcode "..." $2,Some $5)] }
1085 | exp_decl_statement_list TEllipsis post_decl_statement_or_expression_dots
1086 { $1@Ast0.Dots(clt2mcode "..." $2,None)::$3 }
1087 | exp_decl_statement_list TEllipsis
1088 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1089 post_decl_statement_or_expression_dots
1090 { $1@Ast0.Dots(clt2mcode "..." $2,Some $5)::$7 }
1092 post_decl_statement_or_expression_circles:
1093 exp_decl_statement_list
1095 | exp_decl_statement_list TCircles
1096 { $1@[Ast0.Circles(clt2mcode "ooo" $2,None)] }
1097 | exp_decl_statement_list TCircles
1098 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1099 { $1@[Ast0.Circles(clt2mcode "ooo" $2,Some $5)] }
1100 | exp_decl_statement_list TCircles post_decl_statement_or_expression_circles
1101 { $1@Ast0.Circles(clt2mcode "ooo" $2,None)::$3 }
1102 | exp_decl_statement_list TCircles
1103 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1104 post_decl_statement_or_expression_circles
1105 { $1@Ast0.Circles(clt2mcode "ooo" $2,Some $5)::$7 }
1107 post_decl_statement_or_expression_stars:
1108 exp_decl_statement_list
1110 | exp_decl_statement_list TEllipsis
1111 { $1@[Ast0.Stars(clt2mcode "***" $2,None)] }
1112 | exp_decl_statement_list TEllipsis
1113 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1114 { $1@[Ast0.Stars(clt2mcode "***" $2,Some $5)] }
1115 | exp_decl_statement_list TEllipsis post_decl_statement_or_expression_stars
1116 { $1@Ast0.Stars(clt2mcode "***" $2,None)::$3 }
1117 | exp_decl_statement_list TEllipsis
1118 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1119 post_decl_statement_or_expression_stars
1120 { $1@Ast0.Stars(clt2mcode "***" $2,Some $5)::$7 }
1122 pre_post_decl_statement_or_expression:
1123 post_decl_statement_or_expression
1124 { if List.exists (function Ast0.Circles(_) -> true | _ -> false) $1
1125 then Ast0.CIRCLES($1)
1126 else if List.exists (function Ast0.Stars(_) -> true | _ -> false) $1
1128 else Ast0.DOTS($1) }
1129 | TEllipsis post_decl_statement_or_expression_dots
1130 { Ast0.DOTS(Ast0.Dots(clt2mcode "..." $1,None)::$2) }
1131 | TEllipsis TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1132 post_decl_statement_or_expression_dots
1133 { Ast0.DOTS(Ast0.Dots(clt2mcode "..." $1,Some $4)::$6) }
1134 | TCircles post_decl_statement_or_expression_circles
1135 { Ast0.CIRCLES(Ast0.Circles(clt2mcode "ooo" $1,None)::$2) }
1136 | TCircles TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1137 post_decl_statement_or_expression_circles
1138 { Ast0.CIRCLES(Ast0.Circles(clt2mcode "ooo" $1,Some $4)::$6) }
1139 | TStars post_decl_statement_or_expression_stars
1140 { Ast0.STARS(Ast0.Stars(clt2mcode "***" $1,None)::$2) }
1141 | TStars TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1142 post_decl_statement_or_expression_stars
1143 { Ast0.STARS(Ast0.Stars(clt2mcode "***" $1,Some $4)::$6) }
1145 /* a mix of declarations, statements and expressions. an expression must
1146 be surrounded by ... */
1148 post_decl_statement_and_expression_dots:
1150 | pure_decl_statement_list { $1 }
1151 | expr TEllipsis post_decl_statement_and_expression_dots
1152 { Ast0.Exp($1)::Ast0.Dots(clt2mcode "..." $2,None)::$3 }
1154 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1155 post_decl_statement_and_expression_dots
1156 { Ast0.Exp($1)::Ast0.Dots(clt2mcode "..." $2,Some $5)::$7 }
1157 | pure_decl_statement_list TEllipsis post_decl_statement_and_expression_dots
1158 { $1@Ast0.Dots(clt2mcode "..." $2,None)::$3 }
1159 | pure_decl_statement_list TEllipsis
1160 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1161 post_decl_statement_and_expression_dots
1162 { $1@Ast0.Dots(clt2mcode "..." $2,Some $5)::$7 }
1164 post_decl_statement_and_expression_circles:
1166 | pure_decl_statement_list { $1 }
1167 | expr TCircles post_decl_statement_and_expression_circles
1168 { Ast0.Exp($1)::Ast0.Circles(clt2mcode "ooo" $2,None)::$3 }
1170 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1171 post_decl_statement_and_expression_circles
1172 { Ast0.Exp($1)::Ast0.Circles(clt2mcode "ooo" $2,Some $5)::$7 }
1173 | pure_decl_statement_list TCircles
1174 post_decl_statement_and_expression_circles
1175 { $1@Ast0.Circles(clt2mcode "ooo" $2,None)::$3 }
1176 | pure_decl_statement_list TCircles
1177 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1178 post_decl_statement_and_expression_circles
1179 { $1@Ast0.Circles(clt2mcode "ooo" $2,Some $5)::$7 }
1181 post_decl_statement_and_expression_stars:
1183 | pure_decl_statement_list { $1 }
1184 | expr TStars post_decl_statement_and_expression_stars
1185 { Ast0.Exp($1)::Ast0.Stars(clt2mcode "***" $2,None)::$3 }
1187 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1188 post_decl_statement_and_expression_stars
1189 { Ast0.Exp($1)::Ast0.Stars(clt2mcode "***" $2,Some $5)::$7 }
1190 | pure_decl_statement_list TStars post_decl_statement_and_expression_stars
1191 { $1@Ast0.Stars(clt2mcode "***" $2,None)::$3 }
1192 | pure_decl_statement_list TStars
1193 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1194 post_decl_statement_and_expression_stars
1195 { $1@Ast0.Stars(clt2mcode "***" $2,Some $5)::$7 }
1197 pre_post_decl_statement_and_expression:
1198 pure_decl_statement_list
1200 | pure_decl_statement_list TEllipsis post_decl_statement_and_expression_dots
1201 { Ast0.DOTS($1@Ast0.Dots(clt2mcode "..." $2,None)::$3) }
1202 | pure_decl_statement_list TEllipsis
1203 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1204 post_decl_statement_and_expression_dots
1205 { Ast0.DOTS($1@Ast0.Dots(clt2mcode "..." $2,Some $5)::$7) }
1206 | pure_decl_statement_list TCircles
1207 post_decl_statement_and_expression_circles
1208 { Ast0.CIRCLES($1@Ast0.Circles(clt2mcode "ooo" $2,None)::$3) }
1209 | pure_decl_statement_list TCircles
1210 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1211 post_decl_statement_and_expression_circles
1212 { Ast0.CIRCLES($1@Ast0.Circles(clt2mcode "ooo" $2,Some $5)::$7) }
1213 | pure_decl_statement_list TStars post_decl_statement_and_expression_stars
1214 { Ast0.STARS($1@Ast0.Stars(clt2mcode "***" $2,None)::$3) }
1215 | pure_decl_statement_list TStars
1216 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1217 post_decl_statement_and_expression_stars
1218 { Ast0.STARS($1@Ast0.Stars(clt2mcode "***" $2,Some $5)::$7) }
1219 | TEllipsis post_decl_statement_and_expression_dots
1220 { Ast0.DOTS(Ast0.Dots(clt2mcode "..." $1,None)::$2) }
1222 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1223 post_decl_statement_and_expression_dots
1224 { Ast0.DOTS(Ast0.Dots(clt2mcode "..." $1,Some $4)::$6) }
1225 | TCircles post_decl_statement_and_expression_circles
1226 { Ast0.CIRCLES(Ast0.Circles(clt2mcode "ooo" $1,None)::$2) }
1228 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1229 post_decl_statement_and_expression_circles
1230 { Ast0.CIRCLES(Ast0.Circles(clt2mcode "ooo" $1,Some $4)::$6) }
1231 | TStars post_decl_statement_and_expression_stars
1232 { Ast0.STARS(Ast0.Stars(clt2mcode "***" $1,None)::$2) }
1234 TWhen TNotEq pre_post_decl_statement_or_expression TLineEnd
1235 post_decl_statement_and_expression_stars
1236 { Ast0.STARS(Ast0.Stars(clt2mcode "***" $1,Some $4)::$6) }
1238 pre_post_decl_statement_and_expression_opt:
1239 /* empty */ { Ast0.DOTS([]) }
1240 | pre_post_decl_statement_and_expression { $1 }
1242 pre_post_decl_statement_and_expression_opt_mid:
1243 pre_post_decl_statement_and_expression { [$1] }
1244 | /* empty */ { [Ast0.DOTS([])] }
1245 | pre_post_decl_statement_and_expression TMid0
1246 pre_post_decl_statement_and_expression_opt_mid { $1::$3 }
1248 pre_post_decl_statement_and_expression_opt_mid { Ast0.DOTS([])::$2 }
1250 /* ---------------------------------------------------------------------- */
1255 | dexpr TComma dotless_eexpr_list
1256 { $1::Ast0.EComma(clt2mcode "," $2)::$3 }
1260 { if List.exists (function Ast0.Ecircles(_) -> true | _ -> false) $1
1261 then Ast0.CIRCLES($1)
1262 else if List.exists (function Ast0.Estars(_) -> true | _ -> false) $1
1264 else Ast0.DOTS($1) }
1270 { let (nm,clt) = $1 in [Ast0.MetaExprList(clt2mcode nm clt)] }
1272 { [Ast0.Edots(clt2mcode "..." $1,None)] }
1273 | TEllipsis TWhen TNotEq eexpr TLineEnd
1274 { [Ast0.Edots(clt2mcode "..." $1,Some $4)] }
1276 { [Ast0.Ecircles(clt2mcode "ooo" $1,None)] }
1277 | TCircles TWhen TNotEq eexpr TLineEnd
1278 { [Ast0.Ecircles(clt2mcode "ooo" $1,Some $4)] }
1280 { [Ast0.Estars(clt2mcode "***" $1,None)] }
1281 | TStars TWhen TNotEq eexpr TLineEnd
1282 { [Ast0.Estars(clt2mcode "***" $1,Some $4)] }
1283 | dexpr TComma eexpr_list_start
1284 { $1::Ast0.EComma(clt2mcode "," $2)::$3 }
1285 | TMetaExpList TComma eexpr_list_start
1286 { let (nm,clt) = $1 in
1287 Ast0.MetaExprList(clt2mcode nm clt)::Ast0.EComma(clt2mcode "," $2)::$3 }
1288 | TEllipsis TComma eexpr_list_dots
1289 { Ast0.Edots(clt2mcode "..." $1,None)::
1290 Ast0.EComma(clt2mcode "," $2)::$3 }
1291 | TEllipsis TWhen TNotEq eexpr TLineEnd TComma eexpr_list_dots
1292 { Ast0.Edots(clt2mcode "..." $1,Some $4)::
1293 Ast0.EComma(clt2mcode "," $6)::$7 }
1294 | TCircles TComma eexpr_list_circles
1295 { Ast0.Ecircles(clt2mcode "ooo" $1,None)::
1296 Ast0.EComma(clt2mcode "," $2)::$3 }
1297 | TCircles TWhen TNotEq eexpr TLineEnd TComma eexpr_list_circles
1298 { Ast0.Ecircles(clt2mcode "ooo" $1,Some $4)::
1299 Ast0.EComma(clt2mcode "," $6)::$7 }
1300 | TStars TComma eexpr_list_stars
1301 { Ast0.Estars(clt2mcode "***" $1,None)::
1302 Ast0.EComma(clt2mcode "," $2)::$3 }
1303 | TStars TWhen TNotEq eexpr TLineEnd TComma eexpr_list_stars
1304 { Ast0.Estars(clt2mcode "***" $1,Some $4)::
1305 Ast0.EComma(clt2mcode "," $6)::$7 }
1311 { let (nm,clt) = $1 in [Ast0.MetaExprList(clt2mcode nm clt)] }
1313 { [Ast0.Edots(clt2mcode "..." $1,None)] }
1314 | TEllipsis TWhen TNotEq eexpr TLineEnd
1315 { [Ast0.Edots(clt2mcode "..." $1,Some $4)] }
1316 | dexpr TComma eexpr_list_dots
1317 { $1::Ast0.EComma(clt2mcode "," $2)::$3 }
1318 | TMetaExpList TComma eexpr_list_dots
1319 { let (nm,clt) = $1 in
1320 Ast0.MetaExprList(clt2mcode nm clt)::Ast0.EComma(clt2mcode "," $2)::$3 }
1321 | TEllipsis TComma eexpr_list_dots
1322 { Ast0.Edots(clt2mcode "..." $1,None)::
1323 Ast0.EComma(clt2mcode "," $2)::$3 }
1324 | TEllipsis TWhen TNotEq eexpr TLineEnd TComma eexpr_list_dots
1325 { Ast0.Edots(clt2mcode "..." $1,Some $4)::
1326 Ast0.EComma(clt2mcode "," $6)::$7 }
1332 { let (nm,clt) = $1 in [Ast0.MetaExprList(clt2mcode nm clt)] }
1334 { [Ast0.Ecircles(clt2mcode "ooo" $1,None)] }
1335 | TCircles TWhen TNotEq eexpr TLineEnd
1336 { [Ast0.Ecircles(clt2mcode "ooo" $1,Some $4)] }
1337 | dexpr TComma eexpr_list_circles
1338 { $1::Ast0.EComma(clt2mcode "," $2)::$3 }
1339 | TMetaExpList TComma eexpr_list_circles
1340 { let (nm,clt) = $1 in
1341 Ast0.MetaExprList(clt2mcode nm clt)::Ast0.EComma(clt2mcode "," $2)::$3 }
1342 | TCircles TComma eexpr_list_circles
1343 { Ast0.Ecircles(clt2mcode "ooo" $1,None)::
1344 Ast0.EComma(clt2mcode "," $2)::$3 }
1345 | TCircles TWhen TNotEq eexpr TLineEnd TComma eexpr_list_circles
1346 { Ast0.Ecircles(clt2mcode "ooo" $1,Some $4)::
1347 Ast0.EComma(clt2mcode "," $6)::$7 }
1353 { let (nm,clt) = $1 in [Ast0.MetaExprList(clt2mcode nm clt)] }
1355 { [Ast0.Estars(clt2mcode "***" $1,None)] }
1356 | TStars TWhen TNotEq eexpr TLineEnd
1357 { [Ast0.Estars(clt2mcode "***" $1,Some $4)] }
1358 | dexpr TComma eexpr_list_stars
1359 { $1::Ast0.EComma(clt2mcode "," $2)::$3 }
1360 | TMetaExpList TComma eexpr_list_stars
1361 { let (nm,clt) = $1 in
1362 Ast0.MetaExprList(clt2mcode nm clt)::Ast0.EComma(clt2mcode "," $2)::$3 }
1363 | TStars TComma eexpr_list_stars
1364 { Ast0.Estars(clt2mcode "***" $1,None)::
1365 Ast0.EComma(clt2mcode "," $2)::$3 }
1366 | TStars TWhen TNotEq eexpr TLineEnd TComma eexpr_list_stars
1367 { Ast0.Estars(clt2mcode "***" $1,Some $4)::
1368 Ast0.EComma(clt2mcode "," $6)::$7 }
1370 eexpr_list_opt: eexpr_list { $1 }
1371 | /* empty */ { Ast0.DOTS([]) }
1375 | expr TMid0 expr_mid { $1::$3 }
1379 | eexpr TMid0 eexpr_mid { $1::$3 }
1381 eexpr_opt: eexpr { Some ($1) }
1382 | /* empty */ { None }