Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / parsers / parser_lustre.mly @ 19a1e66b

History | View | Annotate | Download (19.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
%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 INCLUDE QUOTE POINT 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

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

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

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

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

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

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

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

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

    
166
type_ident:
167
  IDENT { $1 }
168

    
169
prog:
170
 open_list typ_def_prog top_decl_list EOF { $1 @ $2 @ (List.rev $3) }
171

    
172
typ_def_prog:
173
 typ_def_list { $1 false }
174

    
175
header:
176
 open_list typ_def_header top_decl_header_list EOF { $1 @ $2 @ (List.rev $3) }
177

    
178
typ_def_header:
179
 typ_def_list { $1 true }
180

    
181
open_list:
182
  { [] }
183
| open_lusi open_list { $1 :: $2 }
184

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

    
190
top_decl_list:
191
   {[]}
192
| top_decl_list top_decl {$2@$1}
193

    
194

    
195
top_decl_header_list:
196
   { [] }
197
| top_decl_header_list top_decl_header { $2@$1 }
198

    
199
state_annot:
200
  FUNCTION { true }
201
| NODE { false }
202

    
203
top_decl_header:
204
| CONST cdecl_list { List.rev ($2 true) }
205
| 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
206
    {let nd = mktop_decl true (ImportedNode
207
				 {nodei_id = $3;
208
				  nodei_type = Types.new_var ();
209
				  nodei_clock = Clocks.new_var true;
210
				  nodei_inputs = List.rev $5;
211
				  nodei_outputs = List.rev $10;
212
				  nodei_stateless = $2;
213
				  nodei_spec = $1;
214
				  nodei_prototype = $13;
215
				  nodei_in_lib = $14;})
216
     in
217
     (*add_imported_node $3 nd;*) [nd] } 
218
| CONTRACT node_ident LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR SCOL_opt LET contract TEL 
219
    {let nd = mktop_decl true (ImportedNode
220
				 {nodei_id = $2;
221
				  nodei_type = Types.new_var ();
222
				  nodei_clock = Clocks.new_var true;
223
				  nodei_inputs = List.rev $4;
224
				  nodei_outputs = List.rev $9;
225
				  nodei_stateless = false (* By default we assume contracts as stateful *);
226
				  nodei_spec = Some $14;
227
				  nodei_prototype = None;
228
				  nodei_in_lib = [];})
229
     in
230
     (*add_imported_node $3 nd;*) [nd] }
231

    
232
prototype_opt:
233
 { None }
234
| PROTOTYPE node_ident { Some $2}
235

    
236
in_lib_list:
237
{ [] }
238
| LIB module_ident in_lib_list { $2::$3 } 
239

    
240
top_decl:
241
| CONST cdecl_list { List.rev ($2 false) }
242
| 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 
243
    {
244
     let stmts, asserts, annots = $16 in
245
      (* Declaring eqs annots *)
246
      List.iter (fun ann -> 
247
	List.iter (fun (key, _) -> 
248
	  Annotations.add_node_ann $2 key
249
	) ann.annots
250
      ) annots;
251
     (* Building the node *)
252
     let nd = mktop_decl false (Node
253
				  {node_id = $2;
254
				   node_type = Types.new_var ();
255
				   node_clock = Clocks.new_var true;
256
				   node_inputs = List.rev $4;
257
				   node_outputs = List.rev $9;
258
				   node_locals = List.rev $14;
259
				   node_gencalls = [];
260
				   node_checks = [];
261
				   node_asserts = asserts; 
262
				   node_stmts = stmts;
263
				   node_dec_stateless = $1;
264
				   node_stateless = None;
265
				   node_spec = $13;
266
				   node_annot = annots})
267
     in
268
     pop_node ();
269
     (*add_node $3 nd;*) [nd] }
270

    
271
nodespec_list:
272
 { None }
273
| NODESPEC nodespec_list { 
274
  (function 
275
  | None    -> (fun s1 -> Some s1) 
276
  | Some s2 -> (fun s1 -> Some (merge_contracts s1 s2))) $2 $1 }
277

    
278
typ_def_list:
279
    /* empty */             { (fun itf -> []) }
280
| typ_def SCOL typ_def_list { (fun itf -> let ty1 = ($1 itf) in ty1 :: ($3 itf)) }
281

    
282
typ_def:
283
  TYPE type_ident EQ typ_def_rhs { (fun itf ->
284
			       let typ = mktop_decl itf (TypeDef { tydef_id = $2;
285
								   tydef_desc = $4
286
							})
287
			       in (*add_type itf $2 typ;*) typ) }
288

    
289
typ_def_rhs:
290
  typeconst                   { $1 }
291
| ENUM LCUR tag_list RCUR     { Tydec_enum (List.rev $3) }
292
| STRUCT LCUR field_list RCUR { Tydec_struct (List.rev $3) }
293

    
294
array_typ_decl:
295
 %prec POWER                { fun typ -> typ }
296
 | POWER dim array_typ_decl { fun typ -> $3 (Tydec_array ($2, typ)) }
297

    
298
typeconst:
299
  TINT array_typ_decl   { $2 Tydec_int }
300
| TBOOL array_typ_decl  { $2 Tydec_bool  }
301
| TREAL array_typ_decl  { $2 Tydec_real  }
302
/* | TFLOAT array_typ_decl { $2 Tydec_float } */
303
| type_ident array_typ_decl  { $2 (Tydec_const $1) }
304
| TBOOL TCLOCK          { Tydec_clock Tydec_bool }
305
| IDENT TCLOCK          { Tydec_clock (Tydec_const $1) }
306

    
307
tag_list:
308
  UIDENT                { $1 :: [] }
309
| tag_list COMMA UIDENT { $3 :: $1 }
310
      
311
field_list:                           { [] }
312
| field_list IDENT COL typeconst SCOL { ($2, $4) :: $1 }
313
      
314
stmt_list:
315
  { [], [], [] }
316
| eq stmt_list {let eql, assertl, annotl = $2 in ((Eq $1)::eql), assertl, annotl}
317
| assert_ stmt_list {let eql, assertl, annotl = $2 in eql, ($1::assertl), annotl}
318
| ANNOT stmt_list {let eql, assertl, annotl = $2 in eql, assertl, $1::annotl}
319
| automaton stmt_list {let eql, assertl, annotl = $2 in ((Aut $1)::eql), assertl, annotl}
320

    
321
automaton:
322
 AUTOMATON type_ident handler_list { Automata.mkautomata (get_loc ()) $2 $3 }
323

    
324
handler_list:
325
     { [] }
326
| handler handler_list { $1::$2 }
327

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

    
331
unless_list:
332
    { [] }
333
| unless unless_list { $1::$2 }
334

    
335
until_list:
336
    { [] }
337
| until until_list { $1::$2 }
338

    
339
unless:
340
  UNLESS expr RESTART UIDENT { (get_loc (), $2, true, $4)  }
341
| UNLESS expr RESUME UIDENT  { (get_loc (), $2, false, $4) }
342

    
343
until:
344
  UNTIL expr RESTART UIDENT { (get_loc (), $2, true, $4)  }
345
| UNTIL expr RESUME UIDENT  { (get_loc (), $2, false, $4) }
346

    
347
assert_:
348
| ASSERT expr SCOL {mkassert ($2)}
349

    
350
eq:
351
       ident_list      EQ expr SCOL {mkeq (List.rev (List.map fst $1), $3)}
352
| LPAR ident_list RPAR EQ expr SCOL {mkeq (List.rev (List.map fst $2), $5)}
353

    
354
lustre_spec:
355
| contract EOF { $1 }
356

    
357
contract:
358
{ empty_contract }
359
| CONTRACT contract { $2 }
360
| CONST IDENT EQ expr SCOL contract
361
    { merge_contracts (mk_contract_var $2 true None $4 (get_loc())) $6 }
362
| CONST IDENT COL typeconst EQ expr SCOL contract
363
    { merge_contracts (mk_contract_var $2 true (Some(mktyp $4)) $6 (get_loc())) $8 }
364
| VAR IDENT EQ expr SCOL contract
365
    { merge_contracts (mk_contract_var $2 false None $4 (get_loc())) $6 }
366
| VAR IDENT COL typeconst EQ expr SCOL contract
367
    { merge_contracts (mk_contract_var $2 false (Some(mktyp $4)) $6 (get_loc())) $8 }
368
| ASSUME qexpr SCOL contract
369
    { merge_contracts (mk_contract_assume $2) $4 }
370
| GUARANTEES qexpr SCOL contract	
371
    { merge_contracts (mk_contract_guarantees $2) $4 }
372
| MODE IDENT LPAR mode_content RPAR SCOL contract
373
	{ merge_contracts (
374
	  let r, e = $4 in 
375
	  mk_contract_mode $2 r e (get_loc())) $7 }	
376
| IMPORT IDENT LPAR tuple_expr RPAR RETURNS LPAR tuple_expr RPAR SCOL contract
377
    { merge_contracts (mk_contract_import $2  $4  $8 (get_loc())) $11 }
378

    
379
mode_content:
380
{ [], [] }
381
| REQUIRE qexpr SCOL mode_content { let (r,e) = $4 in $2::r, e }
382
| ENSURE qexpr SCOL mode_content { let (r,e) = $4 in r, $2::e }
383

    
384
/* WARNING: UNUSED RULES */
385
tuple_qexpr:
386
| qexpr COMMA qexpr {[$3;$1]}
387
| tuple_qexpr COMMA qexpr {$3::$1}
388

    
389
qexpr:
390
| expr { mkeexpr $1 }
391
  /* Quantifiers */
392
| EXISTS vdecl SCOL qexpr %prec prec_exists { extend_eexpr [Exists, $2] $4 } 
393
| FORALL vdecl SCOL qexpr %prec prec_forall { extend_eexpr [Forall, $2] $4 }
394

    
395

    
396
tuple_expr:
397
    expr COMMA expr {[$3;$1]}
398
| tuple_expr COMMA expr {$3::$1}
399

    
400
// Same as tuple expr but accepting lists with single element
401
array_expr:
402
  expr {[$1]}
403
| expr COMMA array_expr {$1::$3}
404

    
405
dim_list:
406
  dim RBRACKET { fun base -> mkexpr (Expr_access (base, $1)) }
407
| dim RBRACKET LBRACKET dim_list { fun base -> $4 (mkexpr (Expr_access (base, $1))) }
408

    
409
expr:
410
/* constants */
411
  INT {mkexpr (Expr_const (Const_int $1))}
412
| REAL {let c,e,s = $1 in mkexpr (Expr_const (Const_real (c,e,s)))}
413
| STRING {mkexpr (Expr_const (Const_string $1))}
414
| COLCOL IDENT {mkexpr (Expr_const (Const_modeid $2))} 
415
    
416
/* | FLOAT {mkexpr (Expr_const (Const_float $1))}*/
417
/* Idents or type enum tags */
418
| IDENT { mkexpr (Expr_ident $1) }
419
| tag_ident { mkexpr (Expr_ident $1) (*(Expr_const (Const_tag $1))*) }
420
| LPAR ANNOT expr RPAR
421
    {update_expr_annot (get_current_node ()) $3 $2}
422
| LPAR expr RPAR
423
    {$2}
424
| LPAR tuple_expr RPAR
425
    {mkexpr (Expr_tuple (List.rev $2))}
426

    
427
/* Array expressions */
428
| LBRACKET array_expr RBRACKET { mkexpr (Expr_array $2) }
429
| expr POWER dim { mkexpr (Expr_power ($1, $3)) }
430
| expr LBRACKET dim_list { $3 $1 }
431

    
432
/* Temporal operators */
433
| PRE expr 
434
    {mkexpr (Expr_pre $2)}
435
| expr ARROW expr 
436
    {mkexpr (Expr_arrow ($1,$3))}
437
| expr FBY expr 
438
    {(*mkexpr (Expr_fby ($1,$3))*)
439
      mkexpr (Expr_arrow ($1, mkexpr (Expr_pre $3)))}
440
| expr WHEN vdecl_ident
441
    {mkexpr (Expr_when ($1,fst $3,tag_true))}
442
| expr WHENNOT vdecl_ident
443
    {mkexpr (Expr_when ($1,fst $3,tag_false))}
444
| expr WHEN tag_ident LPAR vdecl_ident RPAR
445
    {mkexpr (Expr_when ($1, fst $5, $3))}
446
| MERGE vdecl_ident handler_expr_list
447
    {mkexpr (Expr_merge (fst $2,$3))}
448

    
449
/* Applications */
450
| node_ident LPAR expr RPAR
451
    {mkexpr (Expr_appl ($1, $3, None))}
452
| node_ident LPAR expr RPAR EVERY expr
453
    {mkexpr (Expr_appl ($1, $3, Some $6))}
454
| node_ident LPAR tuple_expr RPAR
455
    {
456
      let id=$1 in
457
      let args=List.rev $3 in
458
      match id, args with
459
      | "fbyn", [expr;n;init] ->
460
	let n = match n.expr_desc with
461
	  | Expr_const (Const_int n) -> n
462
	  | _ -> assert false
463
	in
464
	fby expr n init
465
      | _ -> mkexpr (Expr_appl ($1, mkexpr (Expr_tuple args), None))
466
    }
467
| node_ident LPAR tuple_expr RPAR EVERY expr
468
    {
469
      let id=$1 in
470
      let args=List.rev $3 in
471
      let clock=$6 in
472
      if id="fby" then
473
	assert false (* TODO Ca veut dire quoi fby (e,n,init) every c *)
474
      else
475
	mkexpr (Expr_appl (id, mkexpr (Expr_tuple args), Some clock)) 
476
    }
477

    
478
/* Boolean expr */
479
| expr AND expr 
480
    {mkpredef_call "&&" [$1;$3]}
481
| expr AMPERAMPER expr 
482
    {mkpredef_call "&&" [$1;$3]}
483
| expr OR expr 
484
    {mkpredef_call "||" [$1;$3]}
485
| expr BARBAR expr 
486
    {mkpredef_call "||" [$1;$3]}
487
| expr XOR expr 
488
    {mkpredef_call "xor" [$1;$3]}
489
| NOT expr 
490
    {mkpredef_call "not" [$2]}
491
| expr IMPL expr 
492
    {mkpredef_call "impl" [$1;$3]}
493

    
494
/* Comparison expr */
495
| expr EQ expr 
496
    {mkpredef_call "=" [$1;$3]}
497
| expr LT expr 
498
    {mkpredef_call "<" [$1;$3]}
499
| expr LTE expr 
500
    {mkpredef_call "<=" [$1;$3]}
501
| expr GT expr 
502
    {mkpredef_call ">" [$1;$3]}
503
| expr GTE  expr 
504
    {mkpredef_call ">=" [$1;$3]}
505
| expr NEQ expr 
506
    {mkpredef_call "!=" [$1;$3]}
507

    
508
/* Arithmetic expr */
509
| expr PLUS expr 
510
    {mkpredef_call "+" [$1;$3]}
511
| expr MINUS expr 
512
    {mkpredef_call "-" [$1;$3]}
513
| expr MULT expr 
514
    {mkpredef_call "*" [$1;$3]}
515
| expr DIV expr 
516
    {mkpredef_call "/" [$1;$3]}
517
| MINUS expr %prec UMINUS
518
  {mkpredef_call "uminus" [$2]}
519
| expr MOD expr 
520
    {mkpredef_call "mod" [$1;$3]}
521

    
522
/* If */
523
| IF expr THEN expr ELSE expr
524
    {mkexpr (Expr_ite ($2, $4, $6))}
525

    
526
handler_expr_list:
527
   { [] }
528
| handler_expr handler_expr_list { $1 :: $2 }
529

    
530
handler_expr:
531
 LPAR tag_ident ARROW expr RPAR { ($2, $4) }
532

    
533
signed_const_array:
534
| signed_const { [$1] }
535
| signed_const COMMA signed_const_array { $1 :: $3 }
536

    
537
signed_const_struct:
538
| IDENT EQ signed_const { [ ($1, $3) ] }
539
| IDENT EQ signed_const COMMA signed_const_struct { ($1, $3) :: $5 }
540

    
541
signed_const:
542
  INT {Const_int $1}
543
| REAL {let c,e,s =$1 in Const_real (c,e,s)}
544
/* | FLOAT {Const_float $1} */
545
| tag_ident {Const_tag $1}
546
| MINUS INT {Const_int (-1 * $2)}
547
| MINUS REAL {let c,e,s = $2 in Const_real (Num.minus_num c, e, "-" ^ s)}
548
/* | MINUS FLOAT {Const_float (-1. *. $2)} */
549
| LCUR signed_const_struct RCUR { Const_struct $2 }
550
| LBRACKET signed_const_array RBRACKET { Const_array $2 }
551

    
552
dim:
553
   INT { mkdim_int $1 }
554
| LPAR dim RPAR { $2 }
555
| UIDENT { mkdim_ident $1 }
556
| IDENT { mkdim_ident $1 }
557
| dim AND dim 
558
    {mkdim_appl "&&" [$1;$3]}
559
| dim AMPERAMPER dim 
560
    {mkdim_appl "&&" [$1;$3]}
561
| dim OR dim 
562
    {mkdim_appl "||" [$1;$3]}
563
| dim BARBAR dim 
564
    {mkdim_appl "||" [$1;$3]}
565
| dim XOR dim 
566
    {mkdim_appl "xor" [$1;$3]}
567
| NOT dim 
568
    {mkdim_appl "not" [$2]}
569
| dim IMPL dim 
570
    {mkdim_appl "impl" [$1;$3]}
571

    
572
/* Comparison dim */
573
| dim EQ dim 
574
    {mkdim_appl "=" [$1;$3]}
575
| dim LT dim 
576
    {mkdim_appl "<" [$1;$3]}
577
| dim LTE dim 
578
    {mkdim_appl "<=" [$1;$3]}
579
| dim GT dim 
580
    {mkdim_appl ">" [$1;$3]}
581
| dim GTE  dim 
582
    {mkdim_appl ">=" [$1;$3]}
583
| dim NEQ dim 
584
    {mkdim_appl "!=" [$1;$3]}
585

    
586
/* Arithmetic dim */
587
| dim PLUS dim 
588
    {mkdim_appl "+" [$1;$3]}
589
| dim MINUS dim 
590
    {mkdim_appl "-" [$1;$3]}
591
| dim MULT dim 
592
    {mkdim_appl "*" [$1;$3]}
593
| dim DIV dim 
594
    {mkdim_appl "/" [$1;$3]}
595
| MINUS dim %prec UMINUS
596
  {mkdim_appl "uminus" [$2]}
597
| dim MOD dim 
598
    {mkdim_appl "mod" [$1;$3]}
599
/* If */
600
| IF dim THEN dim ELSE dim
601
    {mkdim_ite $2 $4 $6}
602

    
603
locals:
604
  {[]}
605
| VAR local_vdecl_list SCOL {$2}
606

    
607
vdecl_list:
608
  vdecl {$1}
609
| vdecl_list SCOL vdecl {$3 @ $1}
610

    
611
vdecl:
612
  ident_list COL typeconst clock 
613
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None, None) loc) $1 }
614
| CONST ident_list /* static parameters don't have clocks */
615
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, None, None) loc) $2 }
616
| CONST ident_list COL typeconst /* static parameters don't have clocks */
617
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, None, None) loc) $2 }
618

    
619
local_vdecl_list:
620
  local_vdecl {$1}
621
| local_vdecl_list SCOL local_vdecl {$3 @ $1}
622

    
623
local_vdecl:
624
/* Useless no ?*/    ident_list
625
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, false, None, None) loc) $1 }
626
| ident_list COL typeconst clock 
627
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None, None) loc) $1 }
628
| CONST vdecl_ident EQ expr /* static parameters don't have clocks */
629
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, Some $4, None) loc] }
630
| CONST vdecl_ident COL typeconst EQ expr /* static parameters don't have clocks */
631
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, Some $6, None) loc] }
632

    
633
cdecl_list:
634
  cdecl SCOL { (fun itf -> [$1 itf]) }
635
| cdecl cdecl_list SCOL { (fun itf -> let c1 = ($1 itf) in c1::($2 itf)) }
636

    
637
cdecl:
638
    const_ident EQ signed_const {
639
      (fun itf -> 
640
       let c = mktop_decl itf (Const {
641
				   const_id = $1;
642
				   const_loc = Location.symbol_rloc ();
643
				   const_type = Types.new_var ();
644
				   const_value = $3})
645
       in
646
       (*add_const itf $1 c;*) c)
647
    }
648

    
649
clock:
650
    {mkclock Ckdec_any}
651
| when_list
652
    {mkclock (Ckdec_bool (List.rev $1))}
653

    
654
when_cond:
655
  WHEN IDENT {($2, tag_true)}
656
| WHENNOT IDENT {($2, tag_false)}
657
| WHEN tag_ident LPAR IDENT RPAR {($4, $2)}
658

    
659
when_list:
660
    when_cond {[$1]}
661
| when_list when_cond {$2::$1}
662

    
663
ident_list:
664
  vdecl_ident {[$1]}
665
| ident_list COMMA vdecl_ident {$3::$1}
666

    
667
SCOL_opt:
668
    SCOL {} | {}
669

    
670

    
671
lustre_annot:
672
lustre_annot_list EOF { { annots = $1; annot_loc = get_loc () } }
673

    
674
lustre_annot_list:
675
  { [] } 
676
| kwd COL qexpr SCOL lustre_annot_list { ($1,$3)::$5 }
677
| IDENT COL qexpr SCOL lustre_annot_list { ([$1],$3)::$5 }
678
| INVARIANT COL qexpr SCOL lustre_annot_list{ (["invariant"],$3)::$5 }
679
// (* | OBSERVER COL qexpr SCOL lustre_annot_list { (["observer"],$3)::$5 } *)
680
| CCODE COL qexpr SCOL lustre_annot_list{ (["c_code"],$3)::$5 }
681
| MATLAB COL qexpr SCOL lustre_annot_list{ (["matlab"],$3)::$5 }
682

    
683

    
684
kwd:
685
DIV { [] }
686
| DIV IDENT kwd { $2::$3}
687

    
688
%%
689
(* Local Variables: *)
690
(* compile-command:"make -C .." *)
691
(* End: *)
692

    
693