Project

General

Profile

Revision 3b2bd83d 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) }
207 211
| nodespec_list state_annot node_ident_decl LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR SCOL_opt locals LET stmt_list TEL 
208 212
    {
209
      let stmts, asserts, annots = $16 in
213
     let stmts, asserts, annots = $16 in
210 214
      (* Declaring eqs annots *)
211 215
      List.iter (fun ann -> 
212 216
	List.iter (fun (key, _) -> 
......
214 218
	) ann.annots
215 219
      ) annots;
216 220
     (* Building the node *)
217
      let nd = mktop_decl false (Node
218
				   {node_id = $3;
219
				    node_type = Types.new_var ();
220
				    node_clock = Clocks.new_var true;
221
				    node_inputs = List.rev $5;
222
				    node_outputs = List.rev $10;
223
				    node_locals = List.rev $14;
224
				    node_gencalls = [];
225
				    node_checks = [];
226
				    node_asserts = asserts; 
227
				    node_stmts = stmts;
228
				    node_dec_stateless = $2;
229
				    node_stateless = None;
230
				    node_spec = $1;
231
				    node_annot = annots})
232
      in
233
      pop_node ();
221
     let nd = mktop_decl false (Node
222
				  {node_id = $3;
223
				   node_type = Types.new_var ();
224
				   node_clock = Clocks.new_var true;
225
				   node_inputs = List.rev $5;
226
				   node_outputs = List.rev $10;
227
				   node_locals = List.rev $14;
228
				   node_gencalls = [];
229
				   node_checks = [];
230
				   node_asserts = asserts; 
231
				   node_stmts = stmts;
232
				   node_dec_stateless = $2;
233
				   node_stateless = None;
234
				   node_spec = $1;
235
				   node_annot = annots})
236
     in
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
......
497 501

  
498 502
signed_const:
499 503
  INT {Const_int $1}
500
| REAL {Const_real $1}
501
| FLOAT {Const_float $1}
504
| REAL {let c,e,s =$1 in Const_real (c,e,s)}
505
/* | FLOAT {Const_float $1} */
502 506
| tag_ident {Const_tag $1}
503 507
| MINUS INT {Const_int (-1 * $2)}
504
| MINUS REAL {Const_real ("-" ^ $2)}
505
| MINUS FLOAT {Const_float (-1. *. $2)}
508
| MINUS REAL {let c,e,s = $2 in Const_real (Num.minus_num c, e, "-" ^ s)}
509
/* | MINUS FLOAT {Const_float (-1. *. $2)} */
506 510
| LCUR signed_const_struct RCUR { Const_struct $2 }
507 511
| LBRACKET signed_const_array RBRACKET { Const_array $2 }
508 512

  
......
567 571

  
568 572
vdecl:
569 573
  ident_list COL typeconst clock 
570
    { List.map (fun id -> mkvar_decl (id, mktyp $3, $4, false, None)) $1 }
574
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None) loc) $1 }
571 575
| 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 }
576
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, None) loc) $2 }
573 577
| 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 }
578
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, None) loc) $2 }
575 579

  
576 580
local_vdecl_list:
577 581
  local_vdecl {$1}
......
579 583

  
580 584
local_vdecl:
581 585
/* Useless no ?*/    ident_list
582
    { List.map (fun id -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, false, None)) $1 }
586
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, false, None) loc) $1 }
583 587
| ident_list COL typeconst clock 
584
    { List.map (fun id -> mkvar_decl (id, mktyp $3, $4, false, None)) $1 }
588
    { List.map (fun (id, loc) -> mkvar_decl (id, mktyp $3, $4, false, None) loc) $1 }
585 589
| CONST vdecl_ident EQ expr /* static parameters don't have clocks */
586
    { [ mkvar_decl ($2, mktyp Tydec_any, mkclock Ckdec_any, true, Some $4) ] }
590
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp Tydec_any, mkclock Ckdec_any, true, Some $4) loc] }
587 591
| 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) ] }
592
    { let (id, loc) = $2 in [ mkvar_decl (id, mktyp $4, mkclock Ckdec_any, true, Some $6) loc] }
589 593

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

Also available in: Unified diff