Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / parsers / parser_lustre.mly @ f4cba4b8

History | View | Annotate | Download (20.9 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

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

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

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

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

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

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

    
116
%start lustre_spec
117
%type <Lustre_types.spec_types> lustre_spec
118

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

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

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

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

    
132

    
133
module_ident:
134
  UIDENT { $1 }
135
| IDENT  { $1 }
136

    
137
file_ident:
138
module_ident { $1 } 
139
| module_ident POINT file_ident { $1 ^ "." ^ $3 } 
140

    
141
path_ident:
142
POINT DIV path_ident { "./" ^ $3 }
143
| file_ident DIV path_ident { $1 ^ "/" ^ $3 }
144
| DIV path_ident { "/" ^ $2 }
145
| file_ident { $1 }
146

    
147
tag_ident:
148
  UIDENT  { $1 }
149
| TRUE    { tag_true }
150
| FALSE   { tag_false }
151

    
152
node_ident:
153
  UIDENT { $1 }
154
| IDENT  { $1 }
155

    
156
node_ident_decl:
157
 node_ident { push_node $1; $1 }
158

    
159
vdecl_ident:
160
  UIDENT { mkident $1 }
161
| IDENT  { mkident $1 }
162

    
163
const_ident:
164
  UIDENT { $1 }
165
| IDENT  { $1 }
166

    
167
type_ident:
168
  IDENT { $1 }
169

    
170
prog:
171
 prefix_prog top_decl_list EOF { $1 @ (List.rev $2) }
172

    
173
prefix_prog:
174
    { [] }
175
  | open_lusi prefix_prog { $1 :: $2 }
176
  | typ_def prefix_prog   { ($1 false (* not a header *)) :: $2 }
177

    
178
prefix_header:
179
    { [] }
180
  | open_lusi prefix_header { $1 :: $2 }
181
  | typ_def prefix_header   { ($1 true (* is a header *)) :: $2 }
182

    
183
header:
184
 prefix_header top_decl_header_list EOF { $1 @ (List.rev $2) }
185

    
186

    
187
open_lusi:
188
  | OPEN QUOTE path_ident QUOTE { mktop_decl false (Open (true, $3)) }
189
  | INCLUDE QUOTE path_ident QUOTE { mktop_decl false (Include ($3)) }
190
  | OPEN LT path_ident GT { mktop_decl false (Open (false, $3))  }
191

    
192
top_decl_list:
193
   {[]}
194
| top_decl_list top_decl {$2@$1}
195

    
196

    
197
top_decl_header_list:
198
   { [] }
199
| top_decl_header_list top_decl_header { $2@$1 }
200

    
201
state_annot:
202
  FUNCTION { true }
203
| NODE { false }
204

    
205
top_decl_header:
206
| CONST cdecl_list { List.rev ($2 true) }
207
| nodespecs state_annot node_ident_decl LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR  prototype_opt in_lib_list SCOL
208
    {
209
      let inputs = List.rev $5 in
210
      let outputs = List.rev $10 in
211
      let nd = mktop_decl true (ImportedNode
212
				 {nodei_id = $3;
213
				  nodei_type = Types.new_var ();
214
				  nodei_clock = Clocks.new_var true;
215
				  nodei_inputs = inputs;
216
				  nodei_outputs = outputs;
217
				  nodei_stateless = $2;
218
				  nodei_spec = $1;
219
				  nodei_prototype = $13;
220
				  nodei_in_lib = $14;})
221
     in
222
     pop_node ();
223
     [nd] } 
224
| top_contract { [$1] }
225

    
226

    
227
prototype_opt:
228
 { None }
229
| PROTOTYPE node_ident { Some $2}
230

    
231
in_lib_list:
232
{ [] }
233
| LIB module_ident in_lib_list { $2::$3 } 
234

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

    
270

    
271
| NODESPEC
272
    { match $1 with
273
      | LocalContract c -> assert false
274
      | TopContract c   -> c
275
			 
276
    }
277

    
278
nodespecs:
279
nodespec_list {
280
  match $1 with
281
  | None -> None 
282
  | Some c -> Some (Contract c)
283
}
284

    
285
nodespec_list:
286
 { None }
287
  | NODESPEC nodespec_list {
288
	       let extract x = match x with LocalContract c -> c | _ -> assert false in
289
	       let s1 = extract $1 in
290
	       match $2 with
291
	       | None -> Some s1
292
	       | Some s2 -> Some (merge_contracts s1 s2) }
293

    
294
typ_def_list:
295
    /* empty */             { (fun itf -> []) }
296
| typ_def typ_def_list { (fun itf -> let ty1 = ($1 itf) in ty1 :: ($2 itf)) }
297

    
298
typ_def:
299
  TYPE type_ident EQ typ_def_rhs SCOL { (fun itf ->
300
			       let typ = mktop_decl itf (TypeDef { tydef_id = $2;
301
								   tydef_desc = $4
302
							})
303
			       in (*add_type itf $2 typ;*) typ) }
304

    
305
typ_def_rhs:
306
  typeconst                   { $1 }
307
| ENUM LCUR tag_list RCUR     { Tydec_enum (List.rev $3) }
308
| STRUCT LCUR field_list RCUR { Tydec_struct (List.rev $3) }
309

    
310
array_typ_decl:
311
 %prec POWER                { fun typ -> typ }
312
 | POWER dim array_typ_decl { fun typ -> $3 (Tydec_array ($2, typ)) }
313

    
314
typeconst:
315
  TINT array_typ_decl   { $2 Tydec_int }
316
| TBOOL array_typ_decl  { $2 Tydec_bool  }
317
| TREAL array_typ_decl  { $2 Tydec_real  }
318
/* | TFLOAT array_typ_decl { $2 Tydec_float } */
319
| type_ident array_typ_decl  { $2 (Tydec_const $1) }
320
| TBOOL TCLOCK          { Tydec_clock Tydec_bool }
321
| IDENT TCLOCK          { Tydec_clock (Tydec_const $1) }
322

    
323
tag_list:
324
  UIDENT                { $1 :: [] }
325
| tag_list COMMA UIDENT { $3 :: $1 }
326
      
327
field_list:                           { [] }
328
| field_list IDENT COL typeconst SCOL { ($2, $4) :: $1 }
329
      
330
stmt_list:
331
  { [], [], [] }
332
| eq stmt_list {let eql, assertl, annotl = $2 in ((Eq $1)::eql), assertl, annotl}
333
| assert_ stmt_list {let eql, assertl, annotl = $2 in eql, ($1::assertl), annotl}
334
| ANNOT stmt_list {let eql, assertl, annotl = $2 in eql, assertl, $1::annotl}
335
| automaton stmt_list {let eql, assertl, annotl = $2 in ((Aut $1)::eql), assertl, annotl}
336

    
337
automaton:
338
 AUTOMATON type_ident handler_list { Automata.mkautomata (get_loc ()) $2 $3 }
339

    
340
handler_list:
341
     { [] }
342
| handler handler_list { $1::$2 }
343

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

    
347
unless_list:
348
    { [] }
349
| unless unless_list { $1::$2 }
350

    
351
until_list:
352
    { [] }
353
| until until_list { $1::$2 }
354

    
355
unless:
356
  UNLESS expr RESTART UIDENT { (get_loc (), $2, true, $4)  }
357
| UNLESS expr RESUME UIDENT  { (get_loc (), $2, false, $4) }
358

    
359
until:
360
  UNTIL expr RESTART UIDENT { (get_loc (), $2, true, $4)  }
361
| UNTIL expr RESUME UIDENT  { (get_loc (), $2, false, $4) }
362

    
363
assert_:
364
| ASSERT expr SCOL {mkassert ($2)}
365

    
366
eq:
367
       ident_list      EQ expr SCOL {mkeq (List.rev (List.map fst $1), $3)}
368
| LPAR ident_list RPAR EQ expr SCOL {mkeq (List.rev (List.map fst $2), $5)}
369

    
370
lustre_spec:
371
| top_contracts EOF     { TopContract $1 }
372
| contract_content EOF { LocalContract $1}
373

    
374
top_contracts:
375
| top_contract { [$1] }
376
| top_contract top_contracts { $1::$2 }
377

    
378
top_contract:
379
| CONTRACT node_ident_decl LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR SCOL_opt LET contract_content TEL 
380
    {
381
      let nd = mktop_decl true (Node
382
				 {node_id = $2;
383
				  node_type = Types.new_var ();
384
				  node_clock = Clocks.new_var true;
385
				  node_inputs = List.rev $4;
386
				  node_outputs = List.rev $9;
387
				  node_locals = []; (* will be filled later *)
388
				  node_gencalls = [];
389
				  node_checks = [];
390
				  node_asserts = [];
391
				  node_stmts = []; (* will be filled later *)
392
				  node_dec_stateless = false;
393
				  (* By default we assume contracts as stateful *)
394
				  node_stateless = None;
395
				  node_spec = Some (Contract $14);
396
				  node_annot = [];
397
				  node_iscontract = true;
398
				 }
399
			       )
400
     in
401
     pop_node ();
402
     (*add_imported_node $3 nd;*)
403
     nd }
404

    
405
contract_content:
406
{ empty_contract }
407
| CONTRACT contract_content { $2 }
408
| CONST IDENT EQ expr SCOL contract_content
409
    { merge_contracts (mk_contract_var $2 true None $4 (get_loc())) $6 }
410
| CONST IDENT COL typeconst EQ expr SCOL contract_content
411
    { merge_contracts (mk_contract_var $2 true (Some(mktyp $4)) $6 (get_loc())) $8 }
412
| VAR IDENT COL typeconst EQ expr SCOL contract_content
413
    { merge_contracts (mk_contract_var $2 false (Some(mktyp $4)) $6 (get_loc())) $8 }
414
| ASSUME qexpr SCOL contract_content
415
    { merge_contracts (mk_contract_assume $2) $4 }
416
| GUARANTEES qexpr SCOL contract_content	
417
    { merge_contracts (mk_contract_guarantees $2) $4 }
418
| MODE IDENT LPAR mode_content RPAR SCOL contract_content
419
	{ merge_contracts (
420
	  let r, e = $4 in 
421
	  mk_contract_mode $2 r e (get_loc())) $7 }	
422
| IMPORT IDENT LPAR expr RPAR RETURNS LPAR expr RPAR SCOL contract_content
423
    { merge_contracts (mk_contract_import $2  $4  $8 (get_loc())) $11 }
424

    
425
mode_content:
426
{ [], [] }
427
| REQUIRE qexpr SCOL mode_content { let (r,e) = $4 in $2::r, e }
428
| ENSURE qexpr SCOL mode_content { let (r,e) = $4 in r, $2::e }
429

    
430
/* WARNING: UNUSED RULES */
431
tuple_qexpr:
432
| qexpr COMMA qexpr {[$3;$1]}
433
| tuple_qexpr COMMA qexpr {$3::$1}
434

    
435
qexpr:
436
| expr { mkeexpr $1 }
437
  /* Quantifiers */
438
| EXISTS vdecl SCOL qexpr %prec prec_exists { extend_eexpr [Exists, $2] $4 } 
439
| FORALL vdecl SCOL qexpr %prec prec_forall { extend_eexpr [Forall, $2] $4 }
440

    
441

    
442
tuple_expr:
443
    expr COMMA expr {[$3;$1]}
444
| tuple_expr COMMA expr {$3::$1}
445

    
446
// Same as tuple expr but accepting lists with single element
447
array_expr:
448
  expr {[$1]}
449
| expr COMMA array_expr {$1::$3}
450

    
451
dim_list:
452
  dim RBRACKET { fun base -> mkexpr (Expr_access (base, $1)) }
453
| dim RBRACKET LBRACKET dim_list { fun base -> $4 (mkexpr (Expr_access (base, $1))) }
454

    
455
expr:
456
/* constants */
457
  INT {mkexpr (Expr_const (Const_int $1))}
458
| REAL {let c,e,s = $1 in mkexpr (Expr_const (Const_real (c,e,s)))}
459
| STRING {mkexpr (Expr_const (Const_string $1))}
460
| COLCOL IDENT {mkexpr (Expr_const (Const_modeid $2))} 
461
    
462
/* | FLOAT {mkexpr (Expr_const (Const_float $1))}*/
463
/* Idents or type enum tags */
464
| IDENT { mkexpr (Expr_ident $1) }
465
| tag_ident { mkexpr (Expr_ident $1) (*(Expr_const (Const_tag $1))*) }
466
| LPAR ANNOT expr RPAR
467
    {update_expr_annot (get_current_node ()) $3 $2}
468
| LPAR expr RPAR
469
    {$2}
470
| LPAR tuple_expr RPAR
471
    {mkexpr (Expr_tuple (List.rev $2))}
472

    
473
/* Array expressions */
474
| LBRACKET array_expr RBRACKET { mkexpr (Expr_array $2) }
475
| expr POWER dim { mkexpr (Expr_power ($1, $3)) }
476
| expr LBRACKET dim_list { $3 $1 }
477

    
478
/* Temporal operators */
479
| PRE expr 
480
    {mkexpr (Expr_pre $2)}
481
| expr ARROW expr 
482
    {mkexpr (Expr_arrow ($1,$3))}
483
| expr FBY expr 
484
    {(*mkexpr (Expr_fby ($1,$3))*)
485
      mkexpr (Expr_arrow ($1, mkexpr (Expr_pre $3)))}
486
| expr WHEN vdecl_ident
487
    {mkexpr (Expr_when ($1,fst $3,tag_true))}
488
| expr WHENNOT vdecl_ident
489
    {mkexpr (Expr_when ($1,fst $3,tag_false))}
490
| expr WHEN tag_ident LPAR vdecl_ident RPAR
491
    {mkexpr (Expr_when ($1, fst $5, $3))}
492
| MERGE vdecl_ident handler_expr_list
493
    {mkexpr (Expr_merge (fst $2,$3))}
494

    
495
/* Applications */
496
| node_ident LPAR expr RPAR
497
    {mkexpr (Expr_appl ($1, $3, None))}
498
| node_ident LPAR expr RPAR EVERY expr
499
    {mkexpr (Expr_appl ($1, $3, Some $6))}
500
| node_ident LPAR tuple_expr RPAR
501
    {
502
      let id=$1 in
503
      let args=List.rev $3 in
504
      match id, args with
505
      | "fbyn", [expr;n;init] ->
506
	let n = match n.expr_desc with
507
	  | Expr_const (Const_int n) -> n
508
	  | _ -> assert false
509
	in
510
	fby expr n init
511
      | _ -> mkexpr (Expr_appl ($1, mkexpr (Expr_tuple args), None))
512
    }
513
| node_ident LPAR tuple_expr RPAR EVERY expr
514
    {
515
      let id=$1 in
516
      let args=List.rev $3 in
517
      let clock=$6 in
518
      if id="fby" then
519
	assert false (* TODO Ca veut dire quoi fby (e,n,init) every c *)
520
      else
521
	mkexpr (Expr_appl (id, mkexpr (Expr_tuple args), Some clock)) 
522
    }
523

    
524
/* Boolean expr */
525
| expr AND expr 
526
    {mkpredef_call "&&" [$1;$3]}
527
| expr AMPERAMPER expr 
528
    {mkpredef_call "&&" [$1;$3]}
529
| expr OR expr 
530
    {mkpredef_call "||" [$1;$3]}
531
| expr BARBAR expr 
532
    {mkpredef_call "||" [$1;$3]}
533
| expr XOR expr 
534
    {mkpredef_call "xor" [$1;$3]}
535
| NOT expr 
536
    {mkpredef_call "not" [$2]}
537
| expr IMPL expr 
538
    {mkpredef_call "impl" [$1;$3]}
539

    
540
/* Comparison expr */
541
| expr EQ expr 
542
    {mkpredef_call "=" [$1;$3]}
543
| expr LT expr 
544
    {mkpredef_call "<" [$1;$3]}
545
| expr LTE expr 
546
    {mkpredef_call "<=" [$1;$3]}
547
| expr GT expr 
548
    {mkpredef_call ">" [$1;$3]}
549
| expr GTE  expr 
550
    {mkpredef_call ">=" [$1;$3]}
551
| expr NEQ expr 
552
    {mkpredef_call "!=" [$1;$3]}
553

    
554
/* Arithmetic expr */
555
| expr PLUS expr 
556
    {mkpredef_call "+" [$1;$3]}
557
| expr MINUS expr 
558
    {mkpredef_call "-" [$1;$3]}
559
| expr MULT expr 
560
    {mkpredef_call "*" [$1;$3]}
561
| expr DIV expr 
562
    {mkpredef_call "/" [$1;$3]}
563
| MINUS expr %prec UMINUS
564
  {mkpredef_call "uminus" [$2]}
565
| expr MOD expr 
566
    {mkpredef_call "mod" [$1;$3]}
567

    
568
/* If */
569
| IF expr THEN expr ELSE expr
570
    {mkexpr (Expr_ite ($2, $4, $6))}
571

    
572
handler_expr_list:
573
   { [] }
574
| handler_expr handler_expr_list { $1 :: $2 }
575

    
576
handler_expr:
577
 LPAR tag_ident ARROW expr RPAR { ($2, $4) }
578

    
579
signed_const_array:
580
| signed_const { [$1] }
581
| signed_const COMMA signed_const_array { $1 :: $3 }
582

    
583
signed_const_struct:
584
| IDENT EQ signed_const { [ ($1, $3) ] }
585
| IDENT EQ signed_const COMMA signed_const_struct { ($1, $3) :: $5 }
586

    
587
signed_const:
588
  INT {Const_int $1}
589
| REAL {let c,e,s =$1 in Const_real (c,e,s)}
590
/* | FLOAT {Const_float $1} */
591
| tag_ident {Const_tag $1}
592
| MINUS INT {Const_int (-1 * $2)}
593
| MINUS REAL {let c,e,s = $2 in Const_real (Num.minus_num c, e, "-" ^ s)}
594
/* | MINUS FLOAT {Const_float (-1. *. $2)} */
595
| LCUR signed_const_struct RCUR { Const_struct $2 }
596
| LBRACKET signed_const_array RBRACKET { Const_array $2 }
597

    
598
dim:
599
   INT { mkdim_int $1 }
600
| LPAR dim RPAR { $2 }
601
| UIDENT { mkdim_ident $1 }
602
| IDENT { mkdim_ident $1 }
603
| dim AND dim 
604
    {mkdim_appl "&&" [$1;$3]}
605
| dim AMPERAMPER dim 
606
    {mkdim_appl "&&" [$1;$3]}
607
| dim OR dim 
608
    {mkdim_appl "||" [$1;$3]}
609
| dim BARBAR dim 
610
    {mkdim_appl "||" [$1;$3]}
611
| dim XOR dim 
612
    {mkdim_appl "xor" [$1;$3]}
613
| NOT dim 
614
    {mkdim_appl "not" [$2]}
615
| dim IMPL dim 
616
    {mkdim_appl "impl" [$1;$3]}
617

    
618
/* Comparison dim */
619
| dim EQ dim 
620
    {mkdim_appl "=" [$1;$3]}
621
| dim LT dim 
622
    {mkdim_appl "<" [$1;$3]}
623
| dim LTE dim 
624
    {mkdim_appl "<=" [$1;$3]}
625
| dim GT dim 
626
    {mkdim_appl ">" [$1;$3]}
627
| dim GTE  dim 
628
    {mkdim_appl ">=" [$1;$3]}
629
| dim NEQ dim 
630
    {mkdim_appl "!=" [$1;$3]}
631

    
632
/* Arithmetic dim */
633
| dim PLUS dim 
634
    {mkdim_appl "+" [$1;$3]}
635
| dim MINUS dim 
636
    {mkdim_appl "-" [$1;$3]}
637
| dim MULT dim 
638
    {mkdim_appl "*" [$1;$3]}
639
| dim DIV dim 
640
    {mkdim_appl "/" [$1;$3]}
641
| MINUS dim %prec UMINUS
642
  {mkdim_appl "uminus" [$2]}
643
| dim MOD dim 
644
    {mkdim_appl "mod" [$1;$3]}
645
/* If */
646
| IF dim THEN dim ELSE dim
647
    {mkdim_ite $2 $4 $6}
648

    
649
locals:
650
  {[]}
651
| VAR local_vdecl_list SCOL {$2}
652

    
653
vdecl_list:
654
  vdecl {$1}
655
| vdecl_list SCOL vdecl {$3 @ $1}
656

    
657
vdecl:
658
  ident_list COL typeconst clock 
659
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None, None) loc) $1 }
660
| CONST ident_list /* static parameters don't have clocks */
661
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, None, None) loc) $2 }
662
| CONST ident_list COL typeconst /* static parameters don't have clocks */
663
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, None, None) loc) $2 }
664

    
665
local_vdecl_list:
666
  local_vdecl {$1}
667
| local_vdecl_list SCOL local_vdecl {$3 @ $1}
668

    
669
local_vdecl:
670
/* Useless no ?*/    ident_list
671
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, false, None, None) loc) $1 }
672
| ident_list COL typeconst clock 
673
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None, None) loc) $1 }
674
| CONST vdecl_ident EQ expr /* static parameters don't have clocks */
675
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, Some $4, None) loc] }
676
| CONST vdecl_ident COL typeconst EQ expr /* static parameters don't have clocks */
677
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, Some $6, None) loc] }
678

    
679
cdecl_list:
680
  cdecl SCOL { (fun itf -> [$1 itf]) }
681
| cdecl cdecl_list SCOL { (fun itf -> let c1 = ($1 itf) in c1::($2 itf)) }
682

    
683
cdecl:
684
    const_ident EQ signed_const {
685
      (fun itf -> 
686
       let c = mktop_decl itf (Const {
687
				   const_id = $1;
688
				   const_loc = Location.symbol_rloc ();
689
				   const_type = Types.new_var ();
690
				   const_value = $3})
691
       in
692
       (*add_const itf $1 c;*) c)
693
    }
694

    
695
clock:
696
    {mkclock Ckdec_any}
697
| when_list
698
    {mkclock (Ckdec_bool (List.rev $1))}
699

    
700
when_cond:
701
  WHEN IDENT {($2, tag_true)}
702
| WHENNOT IDENT {($2, tag_false)}
703
| WHEN tag_ident LPAR IDENT RPAR {($4, $2)}
704

    
705
when_list:
706
    when_cond {[$1]}
707
| when_list when_cond {$2::$1}
708

    
709
ident_list:
710
  vdecl_ident {[$1]}
711
| ident_list COMMA vdecl_ident {$3::$1}
712

    
713
SCOL_opt:
714
    SCOL {} | {}
715

    
716

    
717
lustre_annot:
718
lustre_annot_list EOF { { annots = $1; annot_loc = get_loc () } }
719

    
720
lustre_annot_list:
721
  { [] } 
722
| kwd COL qexpr SCOL lustre_annot_list { ($1,$3)::$5 }
723
| IDENT COL qexpr SCOL lustre_annot_list { ([$1],$3)::$5 }
724
| INVARIANT COL qexpr SCOL lustre_annot_list{ (["invariant"],$3)::$5 }
725
// (* | OBSERVER COL qexpr SCOL lustre_annot_list { (["observer"],$3)::$5 } *)
726
| CCODE COL qexpr SCOL lustre_annot_list{ (["c_code"],$3)::$5 }
727
| MATLAB COL qexpr SCOL lustre_annot_list{ (["matlab"],$3)::$5 }
728

    
729

    
730
kwd:
731
DIV { [] }
732
| DIV IDENT kwd { $2::$3}
733

    
734
%%
735
(* Local Variables: *)
736
(* compile-command:"make -C .." *)
737
(* End: *)
738

    
739