Project

General

Profile

Revision 53206908 src/parser_lustre.mly

View differences:

src/parser_lustre.mly
18 18

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

  
21
let mkident x = x, get_loc ()
21 22
let mktyp x = mktyp (get_loc ()) x
22 23
let mkclock x = mkclock (get_loc ()) x
23
let mkvar_decl x = mkvar_decl (get_loc ()) ~orig:true x
24
let mkvar_decl x loc = mkvar_decl loc ~orig:true x
24 25
let mkexpr x = mkexpr (get_loc ()) x
25 26
let mkeexpr x = mkeexpr (get_loc ()) x 
26 27
let mkeq x = mkeq (get_loc ()) x
......
52 53
%}
53 54

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

  
57 58
%token <string> STRING
58 59
%token AUTOMATON STATE UNTIL UNLESS RESTART RESUME LAST
59 60
%token STATELESS ASSERT OPEN QUOTE FUNCTION
......
69 70
%token MERGE FBY WHEN WHENNOT EVERY
70 71
%token NODE LET TEL RETURNS VAR IMPORTED SENSOR ACTUATOR WCET TYPE CONST
71 72
%token STRUCT ENUM
72
%token TINT TFLOAT TREAL TBOOL TCLOCK
73
%token TINT TREAL TBOOL TCLOCK
73 74
%token RATE DUE
74 75
%token EQ LT GT LTE GTE NEQ
75 76
%token AND OR XOR IMPL
......
116 117
%start lustre_spec
117 118
%type <LustreSpec.node_annot> lustre_spec
118 119

  
120
%start signed_const
121
%type <LustreSpec.constant> signed_const
122

  
119 123
%%
120 124

  
121 125
module_ident:
......
135 139
 node_ident { push_node $1; $1 }
136 140

  
137 141
vdecl_ident:
138
  UIDENT { $1 }
139
| IDENT  { $1 }
142
  UIDENT { mkident $1 }
143
| IDENT  { mkident $1 }
140 144

  
141 145
const_ident:
142 146
  UIDENT { $1 }
......
180 184

  
181 185
top_decl_header:
182 186
| CONST cdecl_list { List.rev ($2 true) }
183
| nodespec_list state_annot node_ident LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR  prototype_opt in_lib_opt SCOL
187
| 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
184 188
    {let nd = mktop_decl true (ImportedNode
185 189
				 {nodei_id = $3;
186 190
				  nodei_type = Types.new_var ();
......
198 202
 { None }
199 203
| PROTOTYPE node_ident { Some $2}
200 204

  
201
in_lib_opt:
202
{ None }
203
| LIB module_ident {Some $2} 
205
in_lib_list:
206
{ [] }
207
| LIB module_ident in_lib_list { $2::$3 } 
204 208

  
205 209
top_decl:
206 210
| CONST cdecl_list { List.rev ($2 false) }
......
232 236
      in
233 237
      pop_node ();
234 238
     (*add_node $3 nd;*) [nd] }
235
    
236
 nodespec_list:
239

  
240
nodespec_list:
237 241
 { None }
238 242
| NODESPEC nodespec_list { 
239 243
  (function 
......
264 268
  TINT array_typ_decl   { $2 Tydec_int }
265 269
| TBOOL array_typ_decl  { $2 Tydec_bool  }
266 270
| TREAL array_typ_decl  { $2 Tydec_real  }
267
| TFLOAT array_typ_decl { $2 Tydec_float }
271
/* | TFLOAT array_typ_decl { $2 Tydec_float } */
268 272
| type_ident array_typ_decl  { $2 (Tydec_const $1) }
269 273
| TBOOL TCLOCK          { Tydec_clock Tydec_bool }
270 274
| IDENT TCLOCK          { Tydec_clock (Tydec_const $1) }
......
313 317
| ASSERT expr SCOL {mkassert ($2)}
314 318

  
315 319
eq:
316
       ident_list      EQ expr SCOL {mkeq (List.rev $1,$3)}
317
| LPAR ident_list RPAR EQ expr SCOL {mkeq (List.rev $2,$5)}
320
       ident_list      EQ expr SCOL {mkeq (List.rev (List.map fst $1), $3)}
321
| LPAR ident_list RPAR EQ expr SCOL {mkeq (List.rev (List.map fst $2), $5)}
318 322

  
319 323
lustre_spec:
320 324
| contract EOF { $1 }
......
369 373
expr:
370 374
/* constants */
371 375
  INT {mkexpr (Expr_const (Const_int $1))}
372
| REAL {mkexpr (Expr_const (Const_real $1))}
373
| FLOAT {mkexpr (Expr_const (Const_float $1))}
376
| REAL {let c,e,s = $1 in mkexpr (Expr_const (Const_real (c,e,s)))}
377
/* | FLOAT {mkexpr (Expr_const (Const_float $1))}*/
374 378
/* Idents or type enum tags */
375 379
| IDENT { mkexpr (Expr_ident $1) }
376 380
| tag_ident { mkexpr (Expr_ident $1) (*(Expr_const (Const_tag $1))*) }
......
395 399
    {(*mkexpr (Expr_fby ($1,$3))*)
396 400
      mkexpr (Expr_arrow ($1, mkexpr (Expr_pre $3)))}
397 401
| expr WHEN vdecl_ident
398
    {mkexpr (Expr_when ($1,$3,tag_true))}
402
    {mkexpr (Expr_when ($1,fst $3,tag_true))}
399 403
| expr WHENNOT vdecl_ident
400
    {mkexpr (Expr_when ($1,$3,tag_false))}
404
    {mkexpr (Expr_when ($1,fst $3,tag_false))}
401 405
| expr WHEN tag_ident LPAR vdecl_ident RPAR
402
    {mkexpr (Expr_when ($1, $5, $3))}
406
    {mkexpr (Expr_when ($1, fst $5, $3))}
403 407
| MERGE vdecl_ident handler_expr_list
404
    {mkexpr (Expr_merge ($2,$3))}
408
    {mkexpr (Expr_merge (fst $2,$3))}
405 409

  
406 410
/* Applications */
407 411
| node_ident LPAR expr RPAR
......
409 413
| node_ident LPAR expr RPAR EVERY expr
410 414
    {mkexpr (Expr_appl ($1, $3, Some $6))}
411 415
| node_ident LPAR tuple_expr RPAR
412
    {
413
      let id=$1 in
414
      let args=List.rev $3 in
415
      match id, args with
416
      | "fbyn", [expr;n;init] ->
417
	let n = match n.expr_desc with
418
	  | Expr_const (Const_int n) -> n
419
	  | _ -> assert false
420
	in
421
	fby expr n init
422
      | _ -> mkexpr (Expr_appl ($1, mkexpr (Expr_tuple args), None))
423
    }
416
    {mkexpr (Expr_appl ($1, mkexpr (Expr_tuple (List.rev $3)), None))}
424 417
| node_ident LPAR tuple_expr RPAR EVERY expr
425
    {
426
      let id=$1 in
427
      let args=List.rev $3 in
428
      let clock=$6 in
429
      if id="fby" then
430
	assert false (* TODO Ca veut dire quoi fby (e,n,init) every c *)
431
      else
432
	mkexpr (Expr_appl (id, mkexpr (Expr_tuple args), Some clock)) 
433
    }
418
    {mkexpr (Expr_appl ($1, mkexpr (Expr_tuple (List.rev $3)), Some $6)) }
434 419

  
435 420
/* Boolean expr */
436 421
| expr AND expr 
......
497 482

  
498 483
signed_const:
499 484
  INT {Const_int $1}
500
| REAL {Const_real $1}
501
| FLOAT {Const_float $1}
485
| REAL {let c,e,s =$1 in Const_real (c,e,s)}
486
/* | FLOAT {Const_float $1} */
502 487
| tag_ident {Const_tag $1}
503 488
| MINUS INT {Const_int (-1 * $2)}
504
| MINUS REAL {Const_real ("-" ^ $2)}
505
| MINUS FLOAT {Const_float (-1. *. $2)}
489
| MINUS REAL {let c,e,s = $2 in Const_real (Num.minus_num c, e, "-" ^ s)}
490
/* | MINUS FLOAT {Const_float (-1. *. $2)} */
506 491
| LCUR signed_const_struct RCUR { Const_struct $2 }
507 492
| LBRACKET signed_const_array RBRACKET { Const_array $2 }
508 493

  
......
567 552

  
568 553
vdecl:
569 554
  ident_list COL typeconst clock 
570
    { List.map (fun id -> mkvar_decl (id, mktyp $3, $4, false, None)) $1 }
555
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None) loc) $1 }
571 556
| CONST ident_list /* static parameters don't have clocks */
572
    { List.map (fun id -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, None)) $2 }
557
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, None) loc) $2 }
573 558
| CONST ident_list COL typeconst /* static parameters don't have clocks */
574
    { List.map (fun id -> mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, None)) $2 }
559
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, None) loc) $2 }
575 560

  
576 561
local_vdecl_list:
577 562
  local_vdecl {$1}
......
579 564

  
580 565
local_vdecl:
581 566
/* Useless no ?*/    ident_list
582
    { List.map (fun id -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, false, None)) $1 }
567
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, false, None) loc) $1 }
583 568
| ident_list COL typeconst clock 
584
    { List.map (fun id -> mkvar_decl (id, mktyp $3, $4, false, None)) $1 }
569
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None) loc) $1 }
585 570
| CONST vdecl_ident EQ expr /* static parameters don't have clocks */
586
    { [ mkvar_decl ($2, mktyp Tydec_any, mkclock Ckdec_any, true, Some $4) ] }
571
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, Some $4) loc ] }
587 572
| CONST vdecl_ident COL typeconst EQ expr /* static parameters don't have clocks */
588
    { [ mkvar_decl ($2, mktyp $4, mkclock Ckdec_any, true, Some $6) ] }
573
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, Some $6) loc ] }
589 574

  
590 575
cdecl_list:
591 576
  cdecl SCOL { (fun itf -> [$1 itf]) }

Also available in: Unified diff