Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / parsers / parser_lustre.mly @ f9f06e7d

History | View | Annotate | Download (19.6 KB)

1
/********************************************************************/
2
/*                                                                  */
3
/*  The LustreC compiler toolset   /  The LustreC Development Team  */
4
/*  Copyright 2012 -    --   ONERA - CNRS - INPT                    */
5
/*                                                                  */
6
/*  LustreC is free software, distributed WITHOUT ANY WARRANTY      */
7
/*  under the terms of the GNU Lesser General Public License        */
8
/*  version 2.1.                                                    */
9
/*                                                                  */
10
/********************************************************************/
11

    
12
%{
13
open Utils
14
open Lustre_types
15
open Corelang
16
open Dimension
17
open Parse
18

    
19
let get_loc () = Location.symbol_rloc ()
20

    
21
let mkident x = x, get_loc ()
22
let mktyp x = mktyp (get_loc ()) x
23
let mkclock x = mkclock (get_loc ()) x
24
let mkvar_decl x loc = mkvar_decl loc ~orig:true x
25
let mkexpr x = mkexpr (get_loc ()) x
26
let mkeexpr x = mkeexpr (get_loc ()) x 
27
let mkeq x = mkeq (get_loc ()) x
28
let mkassert x = mkassert (get_loc ()) x
29
let mktop_decl itf x = mktop_decl (get_loc ()) (Location.get_module ()) itf x
30
let mkpredef_call x = mkpredef_call (get_loc ()) x
31
(*let mkpredef_unary_call x = mkpredef_unary_call (get_loc ()) x*)
32

    
33
let mkdim_int i = mkdim_int (get_loc ()) i
34
let mkdim_bool b = mkdim_bool (get_loc ()) b
35
let mkdim_ident id = mkdim_ident (get_loc ()) id
36
let mkdim_appl f args = mkdim_appl (get_loc ()) f args
37
let mkdim_ite i t e = mkdim_ite (get_loc ()) i t e
38

    
39
let mkannots annots = { annots = annots; annot_loc = get_loc () }
40

    
41
let node_stack : ident list ref = ref []
42
let debug_calls () = Format.eprintf "call stack: %a@.@?" (Utils.fprintf_list ~sep:", " Format.pp_print_string) !node_stack
43
let push_node nd =  node_stack:= nd :: !node_stack
44
let pop_node () = try node_stack := List.tl !node_stack with _ -> assert false
45
let get_current_node () = try List.hd !node_stack with _ -> assert false
46

    
47
let rec fby expr n init =
48
  if n<=1 then
49
    mkexpr (Expr_arrow (init, mkexpr (Expr_pre expr)))
50
  else
51
    mkexpr (Expr_arrow (init, mkexpr (Expr_pre (fby expr (n-1) init))))
52
  
53
%}
54

    
55
%token <int> INT
56
%token <Num.num * int * string> REAL
57

    
58
%token <string> STRING
59
%token AUTOMATON STATE UNTIL UNLESS RESTART RESUME 
60
%token ASSERT OPEN QUOTE FUNCTION
61
%token <string> IDENT
62
%token <string> UIDENT
63
%token TRUE FALSE
64
%token <Lustre_types.expr_annot> ANNOT
65
%token <Lustre_types.contract_desc> NODESPEC
66
%token LBRACKET RBRACKET LCUR RCUR LPAR RPAR SCOL COL COMMA COLCOL 
67
%token AMPERAMPER BARBAR NOT POWER
68
%token IF THEN ELSE
69
%token MERGE FBY WHEN WHENNOT EVERY
70
%token NODE LET TEL RETURNS VAR IMPORTED TYPE CONST
71
%token STRUCT ENUM
72
%token TINT TREAL TBOOL TCLOCK
73
%token EQ LT GT LTE GTE NEQ
74
%token AND OR XOR IMPL
75
%token MULT DIV MOD
76
%token MINUS PLUS UMINUS
77
%token PRE ARROW
78
%token REQUIRE ENSURE ASSUME GUARANTEES IMPORT CONTRACT
79
%token INVARIANT MODE CCODE MATLAB
80
%token EXISTS FORALL
81
%token PROTOTYPE LIB
82
%token EOF
83

    
84
%nonassoc prec_exists prec_forall
85
%nonassoc COMMA
86
%nonassoc EVERY
87
%left MERGE IF
88
%nonassoc ELSE
89
%right ARROW FBY
90
%left WHEN WHENNOT 
91
%right COLCOL
92
%right IMPL
93
%left OR XOR BARBAR
94
%left AND AMPERAMPER
95
%left NOT
96
%nonassoc INT
97
%nonassoc EQ LT GT LTE GTE NEQ
98
%left MINUS PLUS
99
%left MULT DIV MOD
100
%left UMINUS
101
%left POWER
102
%left PRE LAST
103
%nonassoc RBRACKET
104
%nonassoc LBRACKET
105

    
106
%start prog
107
%type <Lustre_types.top_decl list> prog
108

    
109
%start header
110
%type <Lustre_types.top_decl list> header
111

    
112
%start lustre_annot
113
%type <Lustre_types.expr_annot> lustre_annot
114

    
115
%start lustre_spec
116
%type <Lustre_types.contract_desc> lustre_spec
117

    
118
%start signed_const
119
%type <Lustre_types.constant> signed_const
120

    
121
%start expr
122
%type <Lustre_types.expr> expr
123

    
124
%start stmt_list
125
%type <Lustre_types.statement list * Lustre_types.assert_t list * Lustre_types.expr_annot list > stmt_list
126

    
127
%start vdecl_list
128
%type <Lustre_types.var_decl list> vdecl_list
129
%%
130

    
131
module_ident:
132
  UIDENT { $1 }
133
| IDENT  { $1 }
134

    
135
tag_ident:
136
  UIDENT  { $1 }
137
| TRUE    { tag_true }
138
| FALSE   { tag_false }
139

    
140
node_ident:
141
  UIDENT { $1 }
142
| IDENT  { $1 }
143

    
144
node_ident_decl:
145
 node_ident { push_node $1; $1 }
146

    
147
vdecl_ident:
148
  UIDENT { mkident $1 }
149
| IDENT  { mkident $1 }
150

    
151
const_ident:
152
  UIDENT { $1 }
153
| IDENT  { $1 }
154

    
155
type_ident:
156
  IDENT { $1 }
157

    
158
prog:
159
 open_list typ_def_prog top_decl_list EOF { $1 @ $2 @ (List.rev $3) }
160

    
161
typ_def_prog:
162
 typ_def_list { $1 false }
163

    
164
header:
165
 open_list typ_def_header top_decl_header_list EOF { $1 @ $2 @ (List.rev $3) }
166

    
167
typ_def_header:
168
 typ_def_list { $1 true }
169

    
170
open_list:
171
  { [] }
172
| open_lusi open_list { $1 :: $2 }
173

    
174
open_lusi:
175
| OPEN QUOTE module_ident QUOTE { mktop_decl false (Open (true, $3))}
176
| OPEN LT module_ident GT { mktop_decl false (Open (false, $3)) }
177

    
178
top_decl_list:
179
   {[]}
180
| top_decl_list top_decl {$2@$1}
181

    
182

    
183
top_decl_header_list:
184
   { [] }
185
| top_decl_header_list top_decl_header { $2@$1 }
186

    
187
state_annot:
188
  FUNCTION { true }
189
| NODE { false }
190

    
191
top_decl_header:
192
| CONST cdecl_list { List.rev ($2 true) }
193
| nodespec_list state_annot node_ident LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR  prototype_opt in_lib_list SCOL
194
    {let nd = mktop_decl true (ImportedNode
195
				 {nodei_id = $3;
196
				  nodei_type = Types.new_var ();
197
				  nodei_clock = Clocks.new_var true;
198
				  nodei_inputs = List.rev $5;
199
				  nodei_outputs = List.rev $10;
200
				  nodei_stateless = $2;
201
				  nodei_spec = $1;
202
				  nodei_prototype = $13;
203
				  nodei_in_lib = $14;})
204
     in
205
     (*add_imported_node $3 nd;*) [nd] } 
206
| CONTRACT node_ident LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR SCOL_opt LET contract TEL 
207
    {let nd = mktop_decl true (ImportedNode
208
				 {nodei_id = $2;
209
				  nodei_type = Types.new_var ();
210
				  nodei_clock = Clocks.new_var true;
211
				  nodei_inputs = List.rev $4;
212
				  nodei_outputs = List.rev $9;
213
				  nodei_stateless = false (* By default we assume contracts as stateful *);
214
				  nodei_spec = Some $14;
215
				  nodei_prototype = None;
216
				  nodei_in_lib = [];})
217
     in
218
     (*add_imported_node $3 nd;*) [nd] }
219

    
220
prototype_opt:
221
 { None }
222
| PROTOTYPE node_ident { Some $2}
223

    
224
in_lib_list:
225
{ [] }
226
| LIB module_ident in_lib_list { $2::$3 } 
227

    
228
top_decl:
229
| CONST cdecl_list { List.rev ($2 false) }
230
| state_annot node_ident_decl LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR SCOL_opt nodespec_list locals LET stmt_list TEL 
231
    {
232
     let stmts, asserts, annots = $16 in
233
      (* Declaring eqs annots *)
234
      List.iter (fun ann -> 
235
	List.iter (fun (key, _) -> 
236
	  Annotations.add_node_ann $2 key
237
	) ann.annots
238
      ) annots;
239
     (* Building the node *)
240
     let nd = mktop_decl false (Node
241
				  {node_id = $2;
242
				   node_type = Types.new_var ();
243
				   node_clock = Clocks.new_var true;
244
				   node_inputs = List.rev $4;
245
				   node_outputs = List.rev $9;
246
				   node_locals = List.rev $14;
247
				   node_gencalls = [];
248
				   node_checks = [];
249
				   node_asserts = asserts; 
250
				   node_stmts = stmts;
251
				   node_dec_stateless = $1;
252
				   node_stateless = None;
253
				   node_spec = $13;
254
				   node_annot = annots})
255
     in
256
     pop_node ();
257
     (*add_node $3 nd;*) [nd] }
258

    
259
nodespec_list:
260
 { None }
261
| NODESPEC nodespec_list { 
262
  (function 
263
  | None    -> (fun s1 -> Some s1) 
264
  | Some s2 -> (fun s1 -> Some (merge_contracts s1 s2))) $2 $1 }
265

    
266
typ_def_list:
267
    /* empty */             { (fun itf -> []) }
268
| typ_def SCOL typ_def_list { (fun itf -> let ty1 = ($1 itf) in ty1 :: ($3 itf)) }
269

    
270
typ_def:
271
  TYPE type_ident EQ typ_def_rhs { (fun itf ->
272
			       let typ = mktop_decl itf (TypeDef { tydef_id = $2;
273
								   tydef_desc = $4
274
							})
275
			       in (*add_type itf $2 typ;*) typ) }
276

    
277
typ_def_rhs:
278
  typeconst                   { $1 }
279
| ENUM LCUR tag_list RCUR     { Tydec_enum (List.rev $3) }
280
| STRUCT LCUR field_list RCUR { Tydec_struct (List.rev $3) }
281

    
282
array_typ_decl:
283
 %prec POWER                { fun typ -> typ }
284
 | POWER dim array_typ_decl { fun typ -> $3 (Tydec_array ($2, typ)) }
285

    
286
typeconst:
287
  TINT array_typ_decl   { $2 Tydec_int }
288
| TBOOL array_typ_decl  { $2 Tydec_bool  }
289
| TREAL array_typ_decl  { $2 Tydec_real  }
290
/* | TFLOAT array_typ_decl { $2 Tydec_float } */
291
| type_ident array_typ_decl  { $2 (Tydec_const $1) }
292
| TBOOL TCLOCK          { Tydec_clock Tydec_bool }
293
| IDENT TCLOCK          { Tydec_clock (Tydec_const $1) }
294

    
295
tag_list:
296
  UIDENT                { $1 :: [] }
297
| tag_list COMMA UIDENT { $3 :: $1 }
298
      
299
field_list:                           { [] }
300
| field_list IDENT COL typeconst SCOL { ($2, $4) :: $1 }
301
      
302
stmt_list:
303
  { [], [], [] }
304
| eq stmt_list {let eql, assertl, annotl = $2 in ((Eq $1)::eql), assertl, annotl}
305
| assert_ stmt_list {let eql, assertl, annotl = $2 in eql, ($1::assertl), annotl}
306
| ANNOT stmt_list {let eql, assertl, annotl = $2 in eql, assertl, $1::annotl}
307
| automaton stmt_list {let eql, assertl, annotl = $2 in ((Aut $1)::eql), assertl, annotl}
308

    
309
automaton:
310
 AUTOMATON type_ident handler_list { Automata.mkautomata (get_loc ()) $2 $3 }
311

    
312
handler_list:
313
     { [] }
314
| handler handler_list { $1::$2 }
315

    
316
handler:
317
 STATE UIDENT COL unless_list locals LET stmt_list TEL until_list { Automata.mkhandler (get_loc ()) $2 $4 $9 $5 $7 }
318

    
319
unless_list:
320
    { [] }
321
| unless unless_list { $1::$2 }
322

    
323
until_list:
324
    { [] }
325
| until until_list { $1::$2 }
326

    
327
unless:
328
  UNLESS expr RESTART UIDENT { (get_loc (), $2, true, $4)  }
329
| UNLESS expr RESUME UIDENT  { (get_loc (), $2, false, $4) }
330

    
331
until:
332
  UNTIL expr RESTART UIDENT { (get_loc (), $2, true, $4)  }
333
| UNTIL expr RESUME UIDENT  { (get_loc (), $2, false, $4) }
334

    
335
assert_:
336
| ASSERT expr SCOL {mkassert ($2)}
337

    
338
eq:
339
       ident_list      EQ expr SCOL {mkeq (List.rev (List.map fst $1), $3)}
340
| LPAR ident_list RPAR EQ expr SCOL {mkeq (List.rev (List.map fst $2), $5)}
341

    
342
lustre_spec:
343
| contract EOF { $1 }
344

    
345
contract:
346
{ empty_contract }
347
| CONTRACT contract { $2 }
348
| CONST IDENT EQ expr SCOL contract
349
    { merge_contracts (mk_contract_var $2 true None $4 (get_loc())) $6 }
350
| CONST IDENT COL typeconst EQ expr SCOL contract
351
    { merge_contracts (mk_contract_var $2 true (Some(mktyp $4)) $6 (get_loc())) $8 }
352
| VAR IDENT EQ expr SCOL contract
353
    { merge_contracts (mk_contract_var $2 false None $4 (get_loc())) $6 }
354
| VAR IDENT COL typeconst EQ expr SCOL contract
355
    { merge_contracts (mk_contract_var $2 false (Some(mktyp $4)) $6 (get_loc())) $8 }
356
| ASSUME qexpr SCOL contract
357
    { merge_contracts (mk_contract_assume $2) $4 }
358
| GUARANTEES qexpr SCOL contract	
359
    { merge_contracts (mk_contract_guarantees $2) $4 }
360
| MODE IDENT LPAR mode_content RPAR SCOL contract
361
	{ merge_contracts (
362
	  let r, e = $4 in 
363
	  mk_contract_mode $2 r e (get_loc())) $7 }	
364
| IMPORT IDENT LPAR tuple_expr RPAR RETURNS LPAR tuple_expr RPAR SCOL contract
365
    { merge_contracts (mk_contract_import $2  $4  $8 (get_loc())) $11 }
366

    
367
mode_content:
368
{ [], [] }
369
| REQUIRE qexpr SCOL mode_content { let (r,e) = $4 in $2::r, e }
370
| ENSURE qexpr SCOL mode_content { let (r,e) = $4 in r, $2::e }
371

    
372
/* WARNING: UNUSED RULES */
373
tuple_qexpr:
374
| qexpr COMMA qexpr {[$3;$1]}
375
| tuple_qexpr COMMA qexpr {$3::$1}
376

    
377
qexpr:
378
| expr { mkeexpr $1 }
379
  /* Quantifiers */
380
| EXISTS vdecl SCOL qexpr %prec prec_exists { extend_eexpr [Exists, $2] $4 } 
381
| FORALL vdecl SCOL qexpr %prec prec_forall { extend_eexpr [Forall, $2] $4 }
382

    
383

    
384
tuple_expr:
385
    expr COMMA expr {[$3;$1]}
386
| tuple_expr COMMA expr {$3::$1}
387

    
388
// Same as tuple expr but accepting lists with single element
389
array_expr:
390
  expr {[$1]}
391
| expr COMMA array_expr {$1::$3}
392

    
393
dim_list:
394
  dim RBRACKET { fun base -> mkexpr (Expr_access (base, $1)) }
395
| dim RBRACKET LBRACKET dim_list { fun base -> $4 (mkexpr (Expr_access (base, $1))) }
396

    
397
expr:
398
/* constants */
399
  INT {mkexpr (Expr_const (Const_int $1))}
400
| REAL {let c,e,s = $1 in mkexpr (Expr_const (Const_real (c,e,s)))}
401
| STRING {mkexpr (Expr_const (Const_string $1))}
402
| COLCOL IDENT {mkexpr (Expr_const (Const_modeid $2))} 
403
    
404
/* | FLOAT {mkexpr (Expr_const (Const_float $1))}*/
405
/* Idents or type enum tags */
406
| IDENT { mkexpr (Expr_ident $1) }
407
| tag_ident { mkexpr (Expr_ident $1) (*(Expr_const (Const_tag $1))*) }
408
| LPAR ANNOT expr RPAR
409
    {update_expr_annot (get_current_node ()) $3 $2}
410
| LPAR expr RPAR
411
    {$2}
412
| LPAR tuple_expr RPAR
413
    {mkexpr (Expr_tuple (List.rev $2))}
414

    
415
/* Array expressions */
416
| LBRACKET array_expr RBRACKET { mkexpr (Expr_array $2) }
417
| expr POWER dim { mkexpr (Expr_power ($1, $3)) }
418
| expr LBRACKET dim_list { $3 $1 }
419

    
420
/* Temporal operators */
421
| PRE expr 
422
    {mkexpr (Expr_pre $2)}
423
| expr ARROW expr 
424
    {mkexpr (Expr_arrow ($1,$3))}
425
| expr FBY expr 
426
    {(*mkexpr (Expr_fby ($1,$3))*)
427
      mkexpr (Expr_arrow ($1, mkexpr (Expr_pre $3)))}
428
| expr WHEN vdecl_ident
429
    {mkexpr (Expr_when ($1,fst $3,tag_true))}
430
| expr WHENNOT vdecl_ident
431
    {mkexpr (Expr_when ($1,fst $3,tag_false))}
432
| expr WHEN tag_ident LPAR vdecl_ident RPAR
433
    {mkexpr (Expr_when ($1, fst $5, $3))}
434
| MERGE vdecl_ident handler_expr_list
435
    {mkexpr (Expr_merge (fst $2,$3))}
436

    
437
/* Applications */
438
| node_ident LPAR expr RPAR
439
    {mkexpr (Expr_appl ($1, $3, None))}
440
| node_ident LPAR expr RPAR EVERY expr
441
    {mkexpr (Expr_appl ($1, $3, Some $6))}
442
| node_ident LPAR tuple_expr RPAR
443
    {
444
      let id=$1 in
445
      let args=List.rev $3 in
446
      match id, args with
447
      | "fbyn", [expr;n;init] ->
448
	let n = match n.expr_desc with
449
	  | Expr_const (Const_int n) -> n
450
	  | _ -> assert false
451
	in
452
	fby expr n init
453
      | _ -> mkexpr (Expr_appl ($1, mkexpr (Expr_tuple args), None))
454
    }
455
| node_ident LPAR tuple_expr RPAR EVERY expr
456
    {
457
      let id=$1 in
458
      let args=List.rev $3 in
459
      let clock=$6 in
460
      if id="fby" then
461
	assert false (* TODO Ca veut dire quoi fby (e,n,init) every c *)
462
      else
463
	mkexpr (Expr_appl (id, mkexpr (Expr_tuple args), Some clock)) 
464
    }
465

    
466
/* Boolean expr */
467
| expr AND expr 
468
    {mkpredef_call "&&" [$1;$3]}
469
| expr AMPERAMPER expr 
470
    {mkpredef_call "&&" [$1;$3]}
471
| expr OR expr 
472
    {mkpredef_call "||" [$1;$3]}
473
| expr BARBAR expr 
474
    {mkpredef_call "||" [$1;$3]}
475
| expr XOR expr 
476
    {mkpredef_call "xor" [$1;$3]}
477
| NOT expr 
478
    {mkpredef_call "not" [$2]}
479
| expr IMPL expr 
480
    {mkpredef_call "impl" [$1;$3]}
481

    
482
/* Comparison expr */
483
| expr EQ expr 
484
    {mkpredef_call "=" [$1;$3]}
485
| expr LT expr 
486
    {mkpredef_call "<" [$1;$3]}
487
| expr LTE expr 
488
    {mkpredef_call "<=" [$1;$3]}
489
| expr GT expr 
490
    {mkpredef_call ">" [$1;$3]}
491
| expr GTE  expr 
492
    {mkpredef_call ">=" [$1;$3]}
493
| expr NEQ expr 
494
    {mkpredef_call "!=" [$1;$3]}
495

    
496
/* Arithmetic expr */
497
| expr PLUS expr 
498
    {mkpredef_call "+" [$1;$3]}
499
| expr MINUS expr 
500
    {mkpredef_call "-" [$1;$3]}
501
| expr MULT expr 
502
    {mkpredef_call "*" [$1;$3]}
503
| expr DIV expr 
504
    {mkpredef_call "/" [$1;$3]}
505
| MINUS expr %prec UMINUS
506
  {mkpredef_call "uminus" [$2]}
507
| expr MOD expr 
508
    {mkpredef_call "mod" [$1;$3]}
509

    
510
/* If */
511
| IF expr THEN expr ELSE expr
512
    {mkexpr (Expr_ite ($2, $4, $6))}
513

    
514
handler_expr_list:
515
   { [] }
516
| handler_expr handler_expr_list { $1 :: $2 }
517

    
518
handler_expr:
519
 LPAR tag_ident ARROW expr RPAR { ($2, $4) }
520

    
521
signed_const_array:
522
| signed_const { [$1] }
523
| signed_const COMMA signed_const_array { $1 :: $3 }
524

    
525
signed_const_struct:
526
| IDENT EQ signed_const { [ ($1, $3) ] }
527
| IDENT EQ signed_const COMMA signed_const_struct { ($1, $3) :: $5 }
528

    
529
signed_const:
530
  INT {Const_int $1}
531
| REAL {let c,e,s =$1 in Const_real (c,e,s)}
532
/* | FLOAT {Const_float $1} */
533
| tag_ident {Const_tag $1}
534
| MINUS INT {Const_int (-1 * $2)}
535
| MINUS REAL {let c,e,s = $2 in Const_real (Num.minus_num c, e, "-" ^ s)}
536
/* | MINUS FLOAT {Const_float (-1. *. $2)} */
537
| LCUR signed_const_struct RCUR { Const_struct $2 }
538
| LBRACKET signed_const_array RBRACKET { Const_array $2 }
539

    
540
dim:
541
   INT { mkdim_int $1 }
542
| LPAR dim RPAR { $2 }
543
| UIDENT { mkdim_ident $1 }
544
| IDENT { mkdim_ident $1 }
545
| dim AND dim 
546
    {mkdim_appl "&&" [$1;$3]}
547
| dim AMPERAMPER dim 
548
    {mkdim_appl "&&" [$1;$3]}
549
| dim OR dim 
550
    {mkdim_appl "||" [$1;$3]}
551
| dim BARBAR dim 
552
    {mkdim_appl "||" [$1;$3]}
553
| dim XOR dim 
554
    {mkdim_appl "xor" [$1;$3]}
555
| NOT dim 
556
    {mkdim_appl "not" [$2]}
557
| dim IMPL dim 
558
    {mkdim_appl "impl" [$1;$3]}
559

    
560
/* Comparison dim */
561
| dim EQ dim 
562
    {mkdim_appl "=" [$1;$3]}
563
| dim LT dim 
564
    {mkdim_appl "<" [$1;$3]}
565
| dim LTE dim 
566
    {mkdim_appl "<=" [$1;$3]}
567
| dim GT dim 
568
    {mkdim_appl ">" [$1;$3]}
569
| dim GTE  dim 
570
    {mkdim_appl ">=" [$1;$3]}
571
| dim NEQ dim 
572
    {mkdim_appl "!=" [$1;$3]}
573

    
574
/* Arithmetic dim */
575
| dim PLUS dim 
576
    {mkdim_appl "+" [$1;$3]}
577
| dim MINUS dim 
578
    {mkdim_appl "-" [$1;$3]}
579
| dim MULT dim 
580
    {mkdim_appl "*" [$1;$3]}
581
| dim DIV dim 
582
    {mkdim_appl "/" [$1;$3]}
583
| MINUS dim %prec UMINUS
584
  {mkdim_appl "uminus" [$2]}
585
| dim MOD dim 
586
    {mkdim_appl "mod" [$1;$3]}
587
/* If */
588
| IF dim THEN dim ELSE dim
589
    {mkdim_ite $2 $4 $6}
590

    
591
locals:
592
  {[]}
593
| VAR local_vdecl_list SCOL {$2}
594

    
595
vdecl_list:
596
  vdecl {$1}
597
| vdecl_list SCOL vdecl {$3 @ $1}
598

    
599
vdecl:
600
  ident_list COL typeconst clock 
601
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None, None) loc) $1 }
602
| CONST ident_list /* static parameters don't have clocks */
603
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, None, None) loc) $2 }
604
| CONST ident_list COL typeconst /* static parameters don't have clocks */
605
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, None, None) loc) $2 }
606

    
607
local_vdecl_list:
608
  local_vdecl {$1}
609
| local_vdecl_list SCOL local_vdecl {$3 @ $1}
610

    
611
local_vdecl:
612
/* Useless no ?*/    ident_list
613
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, false, None, None) loc) $1 }
614
| ident_list COL typeconst clock 
615
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None, None) loc) $1 }
616
| CONST vdecl_ident EQ expr /* static parameters don't have clocks */
617
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, Some $4, None) loc] }
618
| CONST vdecl_ident COL typeconst EQ expr /* static parameters don't have clocks */
619
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, Some $6, None) loc] }
620

    
621
cdecl_list:
622
  cdecl SCOL { (fun itf -> [$1 itf]) }
623
| cdecl cdecl_list SCOL { (fun itf -> let c1 = ($1 itf) in c1::($2 itf)) }
624

    
625
cdecl:
626
    const_ident EQ signed_const {
627
      (fun itf -> 
628
       let c = mktop_decl itf (Const {
629
				   const_id = $1;
630
				   const_loc = Location.symbol_rloc ();
631
				   const_type = Types.new_var ();
632
				   const_value = $3})
633
       in
634
       (*add_const itf $1 c;*) c)
635
    }
636

    
637
clock:
638
    {mkclock Ckdec_any}
639
| when_list
640
    {mkclock (Ckdec_bool (List.rev $1))}
641

    
642
when_cond:
643
  WHEN IDENT {($2, tag_true)}
644
| WHENNOT IDENT {($2, tag_false)}
645
| WHEN tag_ident LPAR IDENT RPAR {($4, $2)}
646

    
647
when_list:
648
    when_cond {[$1]}
649
| when_list when_cond {$2::$1}
650

    
651
ident_list:
652
  vdecl_ident {[$1]}
653
| ident_list COMMA vdecl_ident {$3::$1}
654

    
655
SCOL_opt:
656
    SCOL {} | {}
657

    
658

    
659
lustre_annot:
660
lustre_annot_list EOF { { annots = $1; annot_loc = get_loc () } }
661

    
662
lustre_annot_list:
663
  { [] } 
664
| kwd COL qexpr SCOL lustre_annot_list { ($1,$3)::$5 }
665
| IDENT COL qexpr SCOL lustre_annot_list { ([$1],$3)::$5 }
666
| INVARIANT COL qexpr SCOL lustre_annot_list{ (["invariant"],$3)::$5 }
667
// (* | OBSERVER COL qexpr SCOL lustre_annot_list { (["observer"],$3)::$5 } *)
668
| CCODE COL qexpr SCOL lustre_annot_list{ (["c_code"],$3)::$5 }
669
| MATLAB COL qexpr SCOL lustre_annot_list{ (["matlab"],$3)::$5 }
670

    
671

    
672
kwd:
673
DIV { [] }
674
| DIV IDENT kwd { $2::$3}
675

    
676
%%
677
(* Local Variables: *)
678
(* compile-command:"make -C .." *)
679
(* End: *)
680

    
681