Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

lutParser.mly 19.3 KB
Newer Older
1
2
3
4
5
6
7
%{
(** SYNTAXE : analyse syntaxique

----------------------------------------------------------------*)
open Lexing
open Lexeme
open Syntaxe
8
open LutErrors
9
10
11
12
13
14
15
16
17
18
open Format
open Str


(* init parse *)

let lettab = ref (Hashtbl.create 50)
let nodetab = ref (Hashtbl.create 50)
let excepttab = ref (Hashtbl.create 50)
let deflist    = ref []
19
let included_files_to_handle = ref []
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

let add_info
   (htbl   : (string, 'a ) Hashtbl.t)
   (id  : Syntaxe.ident)   (* le lexeme en question        *)
   (info : 'a)         (* l'info en question           *)
= (
   try
      Some (Hashtbl.find htbl id.it) 
   with Not_found -> (
      Hashtbl.add htbl id.it info ;
		None
   )
)


let add_except (idl : ident list) = (
36
37
38
39
40
41
  let f id = (
    match (add_info !excepttab id id) with
	None -> deflist := (ExceptDef id)  :: !deflist
      | Some ei -> raise (
	  Compile_error ( id.src ,
			  (sprintf "bad exception declaration, ident already linked %s"
42
			     (LutErrors.lexeme_line_col ei.src)))
43
44
45
	)
  ) in
    List.iter f idl
46
47
48
49
50
51
52
53
54
55
56
)

(* N.B. let et extern sont dans le meme espace de nom
	le seule diffrence est qu'on tient une liste  part des externes
*)
let add_extern (id : Syntaxe.ident) (ci : let_info) = (
	match ( add_info !lettab id ci) with
	None -> deflist := (ExternDef id) :: !deflist
	| Some mi -> raise (
		Compile_error ( id.src ,
			(sprintf "bad macro declaration, ident already linked %s"
57
				(LutErrors.lexeme_line_col mi.lti_ident.src))
58
59
60
61
      )
	)
)

62
63
let (add_include : Lexeme.t -> unit) = 
  fun file -> 
Pascal Raymond's avatar
...  
Pascal Raymond committed
64
    (* remove  double quote from string. *)
65
66
67
    let f = String.sub file.str 1 ((String.length file.str) - 2) in
    included_files_to_handle := (f)::!included_files_to_handle

68
69
70
71
72
73
let add_letdef (id : Syntaxe.ident) (ci : let_info) = (
	match ( add_info !lettab id ci) with
	None -> deflist := (LetDef id) :: !deflist
	| Some mi -> raise (
		Compile_error ( id.src ,
			(sprintf "bad macro declaration, ident already linked %s"
74
				(LutErrors.lexeme_line_col mi.lti_ident.src))
75
76
77
78
79
80
81
82
83
84
      )
	)
)

let add_node (id : Syntaxe.ident) (ci : node_info) = (
	match ( add_info !nodetab id ci ) with
	None -> deflist := (NodeDef id) :: !deflist
	| Some ni -> raise (
		Compile_error ( id.src ,
			(sprintf "bad node declaration, ident already linked %s"
85
				(LutErrors.lexeme_line_col ni.ndi_ident.src))
86
87
88
89
90
91
92
93
94
      )
	)
)

let distrib_type idlst texp = (
	let attach_type id = (id, texp) in
	List.map attach_type idlst 
)

95
96
let distrib_type_and_init idlst texp range_opt vexp = (
	let attach_type id = (id, texp, vexp, range_opt) in
97
98
99
100
101
102
103
104
	List.map attach_type idlst 
)

let parse_end () = (
   let res = {
      pck_lettab = !lettab;
      pck_nodetab  = !nodetab;
      pck_excepttab  = !excepttab;
105
106
      pck_deflist  = (List.rev !deflist);
      pck_included_files_to_handle = !included_files_to_handle
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
   } in
   lettab := Hashtbl.create 50;
   nodetab := Hashtbl.create 50;
   deflist := [];
   res
)

let ident_of_token lxm = (
	Lexeme.flagit lxm.str lxm
)

let make_val_exp ven lxm = {
	it = ven;
	src = lxm
}


%}

%token TK_EOF

%token <Lexeme.t> TK_ERROR

%token <Lexeme.t> TK_IDENT
131
%token <Lexeme.t> TK_STRING
132
133
134
135
136
137
138
139
140

%token <Lexeme.t> TK_LET
%token <Lexeme.t> TK_IN
%token <Lexeme.t> TK_EXTERN
%token <Lexeme.t> TK_NODE
%token <Lexeme.t> TK_SYSTEM
%token <Lexeme.t> TK_RETURNS

%token <Lexeme.t> TK_EXIST
Pascal Raymond's avatar
Pascal Raymond committed
141
%token <Lexeme.t> TK_RUN
142
%token <Lexeme.t> TK_ERUN
143
144
%token <Lexeme.t> TK_WEAK
%token <Lexeme.t> TK_STRONG
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
%token <Lexeme.t> TK_ASSERT
%token <Lexeme.t> TK_RAISE
%token <Lexeme.t> TK_TRY
%token <Lexeme.t> TK_CATCH
%token <Lexeme.t> TK_TRAP
%token <Lexeme.t> TK_PARA
%token <Lexeme.t> TK_DO
%token <Lexeme.t> TK_FBY
%token <Lexeme.t> TK_LOOP

%token <Lexeme.t> TK_TYPE
%token <Lexeme.t> TK_BOOL
%token <Lexeme.t> TK_INT
%token <Lexeme.t> TK_REAL
%token <Lexeme.t> TK_TRACE
%token <Lexeme.t> TK_REF
%token <Lexeme.t> TK_EXCEPTION
162
%token <Lexeme.t> TK_INCLUDE
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

%token <Lexeme.t> TK_PRE
%token <Lexeme.t> TK_FALSE
%token <Lexeme.t> TK_TRUE

%token <Lexeme.t> TK_RCONST
%token <Lexeme.t> TK_ICONST

%token <Lexeme.t> TK_EQ
%token <Lexeme.t> TK_NEQ

%token <Lexeme.t> TK_BARSUP

%token <Lexeme.t> TK_PLUS
%token <Lexeme.t> TK_MINUS
%token <Lexeme.t> TK_TIMES
%token <Lexeme.t> TK_SLASH

%token <Lexeme.t> TK_DIV
%token <Lexeme.t> TK_MOD

%token <Lexeme.t> TK_LT
%token <Lexeme.t> TK_LTE
%token <Lexeme.t> TK_GT
%token <Lexeme.t> TK_GTE

%token <Lexeme.t> TK_BAR

%token <Lexeme.t> TK_DOT
%token <Lexeme.t> TK_COMA
%token <Lexeme.t> TK_SEMICOL
%token <Lexeme.t> TK_COLON
%token <Lexeme.t> TK_TILDA
%token <Lexeme.t> TK_OPEN_BRACE
%token <Lexeme.t> TK_CLOSE_BRACE
%token <Lexeme.t> TK_OPEN_BRACKET
%token <Lexeme.t> TK_CLOSE_BRACKET
%token <Lexeme.t> TK_OPEN_PAR
%token <Lexeme.t> TK_CLOSE_PAR

%token <Lexeme.t> TK_NOT
%token <Lexeme.t> TK_OR
%token <Lexeme.t> TK_XOR
%token <Lexeme.t> TK_AND
%token <Lexeme.t> TK_IMPL
208
%token <Lexeme.t> TK_ASSIGN
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
%token <Lexeme.t> TK_ARROW
%token <Lexeme.t> TK_IF
%token <Lexeme.t> TK_THEN
%token <Lexeme.t> TK_ELSE


/* PRIORITIES */

/* dans les traces (statements) */
%nonassoc TK_TRY TK_IN
%left NO_DO_PART
%nonassoc TK_DO
%left TK_FBY 
%nonassoc TK_LOOP


/* dans les expressions */
%left TK_ELSE
%nonassoc TK_IMPL
%left TK_OR
%left TK_XOR
%left TK_AND
%left TK_EQ TK_NEQ
%left TK_LT TK_LTE TK_GTE TK_GT
%left TK_PLUS TK_MINUS
%left TK_TIMES TK_SLASH TK_PCENT TK_MOD TK_DIV
%nonassoc TK_NOT
%nonassoc TK_INT TK_REAL
%nonassoc TK_UMINUS TK_PRE TK_DIESE TK_NOR
%left TK_HAT TK_FIELD TK_DOT

/* %nonassoc TK_OPEN_PAR */

/* affreux hack pour traiter le
   problme de loop ~id ( ...
	On met des priorits de telle
	manire que chaque fois qu'on a
	un '(' qui suit un id, on considre
	a comme un (dbut) de call
*/
%nonassoc HACK_CALL
%nonassoc HACK_ID
%nonassoc TK_OPEN_PAR

/* %nonassoc TK_TILDA TK_COLON */

/* lutEntry point
*/
Pascal Raymond's avatar
Pascal Raymond committed
257
258
%start lutFileTop
%type <Syntaxe.package> lutFileTop
259
260
261
262
263
264
265
266
267


%%

/*-------------------------------------------------------
	GRAMMAR
---------------------------------------------------------
-------------------------------------------------------*/

Pascal Raymond's avatar
Pascal Raymond committed
268
/* ebnf:group=ignore */
269

Pascal Raymond's avatar
Pascal Raymond committed
270
271
lutFileTop:
	|   lutFile TK_EOF
272
273
274
			{ parse_end () }
	;

Pascal Raymond's avatar
Pascal Raymond committed
275
276
/* ebnf:group=decls */

277
278
/* lutDeclarations */

Pascal Raymond's avatar
Pascal Raymond committed
279
lutFile:
280
			{ }
Pascal Raymond's avatar
Pascal Raymond committed
281
	|   lutFile lutOneDecl
282
283
284
			{ }
	;

285
286
287
288
289
290
291

lutInclude: 
  TK_INCLUDE TK_STRING 
            { $2 }
;


292
lutOneDecl:
293
294
295
	|   lutInclude 
		{ add_include $1 } 
	|	lutLetDecl 
296
297
298
		{ add_letdef (fst $1) (snd $1) }
	|	lutExceptDecl 
		{ add_except $1 }
Erwan Jahier's avatar
Erwan Jahier committed
299
300
	|	lutExternNodeDecl 
		{ add_extern (fst $1) (snd $1) }
301
302
303
304
305
306
307
308
309
310
311
	|	lutNodeDecl
		{ add_node (fst $1) (snd $1) }
	;

lutExceptDecl:
	TK_EXCEPTION lutIdentList
			{ List.rev $2 }
	;

/* top level macro def */
lutLetDecl:
Pascal Raymond's avatar
Pascal Raymond committed
312
  TK_LET lutIdent lutOptParams lutOptType TK_EQ lutTraceExp 
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
  {
	  (* let id = ident_of_token $2 in *)
	  let id = $2 in
	  ( id, 
		  {
			  lti_ident = id;
			  lti_inputs = $3;
			  lti_type = $4;
			  lti_def = Some $6;
		  }
	  )
  }
;

/* top level extern def */
Erwan Jahier's avatar
Erwan Jahier committed
328
lutExternNodeDecl:
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
  TK_EXTERN lutIdent lutOptParams lutOptType 
  {
	  (* let id = ident_of_token $2 in *)
	  let id = $2 in
	  ( id, 
		  {
			  lti_ident = id;
			  lti_inputs = $3;
			  lti_type = $4;
			  lti_def = None;
		  }
	  )
  }
;

/* top level node def */

lutNodeStart: /* ebnf:print=short */
	TK_NODE
		{}
|	TK_SYSTEM
		{}
;

lutNodeDecl:

	lutNodeStart lutIdent 
	TK_OPEN_PAR lutTypedIdentListOpt TK_CLOSE_PAR
357
  TK_RETURNS TK_OPEN_PAR lutTypedIdentList TK_CLOSE_PAR 
Pascal Raymond's avatar
Pascal Raymond committed
358
	TK_EQ lutTraceExp
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
	{
		(* let id = ident_of_token $2 in *)
		let id = $2 in
		(id,
			{
				ndi_ident = id;
				ndi_inputs = List.rev $4;
				ndi_outputs = List.rev $8;
				ndi_def = $11
			}
		)
	}
	;



/* lutIdentifiers and lists */

/* ebnf:group=varparams */

Pascal Raymond's avatar
Pascal Raymond committed
379
lutIdent: /* ebnf:print=ignore */
380
381
382
383
384
385
386
387
388
389
390
	TK_IDENT
		{ ident_of_token $1 }
	;

lutIdentList:
		lutIdent
			{ [$1] }
	|   lutIdentList TK_COMA lutIdent
			{ $3::$1 }
	;

391
392
393
/* opt parenthesis */
lutIdentTuple:
	lutIdentList
Pascal Raymond's avatar
Pascal Raymond committed
394
		{ List.rev $1 }
395
396
397
398
399
400
401
402
403
|  TK_OPEN_PAR lutIdentList TK_CLOSE_PAR
		{ List.rev $2 }
;

lutERunVars:
	TK_OPEN_PAR lutERunVarList TK_CLOSE_PAR
		{ $2 }
	|	lutERunVarList
		{ $1 }
Pascal Raymond's avatar
Pascal Raymond committed
404
405
	;

406
407
lutERunVarList:
	lutERunVar
Pascal Raymond's avatar
Pascal Raymond committed
408
		{ [$1] }
409
	| lutERunVarList TK_COMA lutERunVar
Pascal Raymond's avatar
Pascal Raymond committed
410
411
412
		{ $3::$1 }
	;

413

414
lutRangeOpt: /* ebnf:print=expand */
415
416
/* nada */
	{ None }
417
|	TK_OPEN_BRACKET lutExp TK_SEMICOL lutExp TK_CLOSE_BRACKET
418
419
420
	{ Some($2,$4) }
;

421
lutTypedIdent:
422
423
424
425
	lutIdentList TK_COLON lutType lutRangeOpt 
		{ distrib_type_and_init $1 $3 $4  None}
|	lutIdentList TK_COLON lutType lutRangeOpt TK_EQ lutExp
		{ distrib_type_and_init $1 $3 $4 (Some $6) }
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
	;

lutTypedIdentListOpt: /* nada */
			{ [] }
	|	lutTypedIdentList
			{ $1 }
	;


lutTypedIdentList: lutTypedIdentListA
			{ $1 }
	|   lutTypedIdentListA TK_SEMICOL
			{ $1 }
	;

erwan's avatar
erwan committed
441
lutTypedIdentListA: /* ebnf:print=expand */  lutTypedIdent
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
			{ $1 }
	|   lutTypedIdentListA TK_SEMICOL lutTypedIdent
			{ $3@$1 }
	;

/*
lutTypedIdentList: lutTypedIdent
			{ $1 }
	|   lutTypedIdentList TK_SEMICOL lutTypedIdent lutOptSemicol
			{ $3@$1 }
	;

lutOptSemicol:
		{}
	| TK_SEMICOL
		{}
	;
*/
460
lutOptParams: /* ebnf:print=expand */
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
	  /* nada */
	  { None }
| TK_OPEN_PAR TK_CLOSE_PAR
	  { Some [] }
| TK_OPEN_PAR lutTypedParamList TK_CLOSE_PAR
		{ Some (List.rev $2) }
;

lutTypedParamList: lutTypedParam
	{ $1 }
|   lutTypedParamList TK_SEMICOL lutTypedParam
	{ $3@$1 }
;

lutTypedParam:
476
477
lutIdentList TK_COLON lutParamType 
	{ distrib_type $1 $3}
478
479
;

480
lutERunVar:
Pascal Raymond's avatar
Pascal Raymond committed
481
482
483
484
	lutIdent lutOptType lutOptInit
		{ ($1, $2, $3) }
	;

485
lutOptInit:  /* ebnf:print=expand */
Pascal Raymond's avatar
Pascal Raymond committed
486
487
488
489
490
	/* nada */
		{ None }
	| TK_EQ lutExp
		{ Some $2 }
	;
491

492
493
494
495
496

/* Immediate type */

/* ebnf:group=types */

497
lutOptType:  /* ebnf:print=expand */
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
/* nada */
	{ None }
|	TK_COLON lutType
	{ Some $2 }
;


lutType: /* ebnf:print=short */
	lutPredefType
		{TEXP_predef $1}
|	TK_TRACE
		{ (TEXP_trace) }
;

lutPredefType: /* ebnf:print=short */
  TK_BOOL 
	  { Bool }
|  TK_INT 
	  { Int }
|  TK_REAL
	  { Real }
;

/* Parameter type */
lutParamType: /* ebnf:print=short */
	lutType
		{$1}
|	lutPredefType TK_REF
		{TEXP_ref $1}
;
/*

lutFunctionType:
		lutFunctionInType TK_ARROW lutPredefType
		{ (List.rev $1, TEXP_predef $3) }
	|	TK_OPEN_PAR TK_CLOSE_PAR TK_ARROW lutPredefType
		{ ([], TEXP_predef $4) }
;
lutFunctionInType:
		lutPredefType
		{ [TEXP_predef $1] }
	|  lutFunctionInType TK_TIMES lutPredefType
		{ (TEXP_predef $3)::$1 }
;
*/


Pascal Raymond's avatar
Pascal Raymond committed
545
546
/* TraceExp :
- lutTraceExp = a priori un statement, c'est--dire
547
548
549
550
551
552
553
554
555
556
  une expression parenthse en {}
- lutExp = une expression algbrique classique
  parenthse en () 
- cas particulier : les idents et plus gnralement 
  les "call" sont traits dans lutExp
  (voir + bas)
*/

/* ebnf:group=statements */

557
lutAssertFlag:  /* ebnf:print=expand */
558
559
560
561
562
563
564
565
	TK_STRONG
		{ Strong }
|	TK_WEAK	
		{ Weak }
|	/* nada */
		{ Weak }
;

Pascal Raymond's avatar
Pascal Raymond committed
566
lutTraceExp:
567
568
569
570
571
572
573
574
575
/* ``feuilles''
*/
		lutExp
			{ $1 }
	|	TK_RAISE lutIdent
			{ make_val_exp (RAISE_n $2) $1 }
/* les combinateurs de traces referment ds que possible, e.g.:
	loop x fby y   <-->  {loop {x}} fby y
*/
Pascal Raymond's avatar
Pascal Raymond committed
576
	|	lutTraceExp TK_FBY lutTraceExp
577
			{ make_val_exp (FBY_n ($1,$3)) $2}
Pascal Raymond's avatar
Pascal Raymond committed
578
	|	lutLoopExp
579
			{ $1 }
580
581
	|	lutLoopStatExp
			{ $1 }
582
583
584
/*
	les combinateurs entre accolades
*/
Pascal Raymond's avatar
Pascal Raymond committed
585
	|	lutBraceExp
586
587
588
589
590
			{ $1 }
/*
	en gnral les statement en "in" referment AU PLUS TARD, e.g.
	assert e in x fby y fby 
*/
Pascal Raymond's avatar
Pascal Raymond committed
591
	|	lutLetDecl TK_IN lutTraceExp
592
			{ make_val_exp (LET_n (snd $1,$3)) ((fst $1).src) }
593
594
	|	lutAssertFlag TK_ASSERT lutExp TK_IN lutTraceExp
			{ make_val_exp (ASSERT_n ($1,$3,$5)) $2 }
595
596
597
598
599
600
601
602
603
/* first run attemps: exist + run = erun */
	|	TK_ERUN lutERunVars TK_ASSIGN lutExp TK_IN lutTraceExp
			{ make_val_exp (ERUN_n (List.rev $2, $4, $6)) $1 }
/* RUN, id list already in right order */
	|	TK_RUN lutIdentTuple TK_ASSIGN lutExp TK_IN lutTraceExp
			{ make_val_exp (RUN_n ($2, $4, Some $6)) $1 }
/* RUN without "in" is a shortcut for "in loop { true }" */
	|	TK_RUN lutIdentTuple TK_ASSIGN lutExp
			{ make_val_exp (RUN_n ($2, $4, None)) $1 }
Pascal Raymond's avatar
Pascal Raymond committed
604
	|	TK_EXIST lutTypedIdentList TK_IN lutTraceExp
605
			{ make_val_exp (EXIST_n (List.rev $2,$4)) $1 }
Pascal Raymond's avatar
Pascal Raymond committed
606
	|	TK_EXCEPTION lutIdentList TK_IN lutTraceExp
607
608
609
610
611
			{ make_val_exp (EXCEPT_n (List.rev $2,$4)) $1 }
/*
	ceux qui ont une continuation	
*/
/*
Pascal Raymond's avatar
Pascal Raymond committed
612
	|	TK_TRY lutTraceExp
613
			{ make_val_exp (TRY_n ($2,None)) $1 }
Pascal Raymond's avatar
Pascal Raymond committed
614
	|	TK_TRY lutTraceExp TK_DO lutTraceExp
615
			{ make_val_exp (TRY_n ($2,Some $4)) $1 }
Pascal Raymond's avatar
Pascal Raymond committed
616
	|	TK_CATCH lutIdent TK_IN lutTraceExp 
617
			{ make_val_exp (CATCH_n($2,$4,None)) $1}
Pascal Raymond's avatar
Pascal Raymond committed
618
	|	TK_CATCH lutIdent TK_IN lutTraceExp TK_DO lutTraceExp
619
			{ make_val_exp (CATCH_n($2,$4,Some $6)) $1}
Pascal Raymond's avatar
Pascal Raymond committed
620
	|	TK_TRAP lutIdent TK_IN lutTraceExp
621
			{ make_val_exp (TRAP_n($2,$4,None)) $1}
Pascal Raymond's avatar
Pascal Raymond committed
622
	|	TK_TRAP lutIdent TK_IN lutTraceExp TK_DO lutTraceExp
623
624
			{ make_val_exp (TRAP_n($2,$4,Some $6)) $1}
*/
Pascal Raymond's avatar
Pascal Raymond committed
625
	|	TK_TRY lutTraceExp lutDoPart
626
			{ make_val_exp (TRY_n ($2,$3)) $1 }
Pascal Raymond's avatar
Pascal Raymond committed
627
	|	TK_CATCH lutIdent TK_IN lutTraceExp lutDoPart
628
			{ make_val_exp (CATCH_n($2,$4, $5)) $1}
Pascal Raymond's avatar
Pascal Raymond committed
629
	|	TK_TRAP lutIdent TK_IN lutTraceExp lutDoPart
630
631
632
			{ make_val_exp (TRAP_n($2,$4,$5)) $1}

/*
Pascal Raymond's avatar
Pascal Raymond committed
633
	|	TK_PARAHEAD lutTraceExp TK_PARA lutParaList1
634
			{ make_val_exp (PARA_n ($2::(List.rev $4))) $1 }
Pascal Raymond's avatar
Pascal Raymond committed
635
	|	TK_PARAHEAD TK_OPEN_BRACE lutTraceExp TK_PARA lutParaList1
636
637
638
639
640
				TK_CLOSE_BRACE
			{ make_val_exp (PARA_n ($3::(List.rev $5))) $1 }
*/
	;

Pascal Raymond's avatar
...  
Pascal Raymond committed
641
lutDoPart:  /* ebnf:print=expand */
642
643
	/* nada */ %prec NO_DO_PART
		{ None }
Pascal Raymond's avatar
Pascal Raymond committed
644
	|	TK_DO lutTraceExp
645
646
647
		{ Some $2 }
	;

Pascal Raymond's avatar
Pascal Raymond committed
648
lutLoopExp:
649
650
651
652
653
654
655
656
657
658
659
	TK_LOOP lutTraceExp
		{  make_val_exp (LOOP_n (Weak,$2)) $1 }
|  TK_STRONG TK_LOOP lutTraceExp
		{  make_val_exp (LOOP_n (Strong,$3)) $2 }
|  TK_WEAK TK_LOOP lutTraceExp
		{  make_val_exp (LOOP_n (Weak,$3)) $2 }

;

lutLoopStatExp:
		TK_LOOP lutAverage lutTraceExp
660
			{ make_val_exp (LOOPI_n (fst $2, snd $2, $3)) $1 }
Pascal Raymond's avatar
Pascal Raymond committed
661
	|	TK_LOOP lutGaussian  lutTraceExp
662
663
664
			{ make_val_exp (LOOPA_n (fst $2, snd $2, $3)) $1 }
	;

665
666
667
/* lutExact:
		lutExp { ($1) } ;
*/
668

669
lutAverage:
670
671
672
	TK_OPEN_BRACKET lutExp TK_CLOSE_BRACKET
		{ ($2, $2) }
	| TK_OPEN_BRACKET lutExp TK_COMA lutExp TK_CLOSE_BRACKET
673
674
675
676
677
678
679
680
681
682
		{ ($2, $4) }
	;

lutGaussian:
		TK_TILDA lutExp %prec TK_NOT
		{ ($2, None) }
	|	TK_TILDA lutExp TK_COLON lutExp %prec TK_NOT
		{ ($2, Some $4) }
	;
	
683
684
685
686
/* VIELLE SYNTAXE */
/* OBSOLETE
lutWeightOptOBSO:
	//nada
687
688
689
690
		{ None }
	|	TK_WEIGHT lutExp
		{ Some {it = $2; src = $1} }
	;
691
lutChoiceList:
Pascal Raymond's avatar
Pascal Raymond committed
692
		lutTraceExp lutWeightOptOBSO
693
			{ [ ($1, $2) ] }
Pascal Raymond's avatar
Pascal Raymond committed
694
	|	lutChoiceList TK_BAR lutTraceExp lutWeightOptOBSO
695
696
697
			{ ($3,$4) :: $1 }
	;
lutPrioList:
Pascal Raymond's avatar
Pascal Raymond committed
698
	lutTraceExp
699
		{ [$1] }
Pascal Raymond's avatar
Pascal Raymond committed
700
	|	lutPrioList TK_BARSUP lutTraceExp 
701
702
703
		{ $3::$1 }
	;
lutParaList:
Pascal Raymond's avatar
Pascal Raymond committed
704
		lutTraceExp
705
			{ [$1] }
Pascal Raymond's avatar
Pascal Raymond committed
706
	|	lutParaList TK_PARA lutTraceExp
707
708
709
			{ $3::$1 }
	;

Pascal Raymond's avatar
Pascal Raymond committed
710
711
lutBraceExpOBSO:
		TK_OPEN_BRACE lutTraceExp TK_CLOSE_BRACE
712
		{ $2 }
Pascal Raymond's avatar
Pascal Raymond committed
713
	|	TK_OPEN_BRACE lutTraceExp TK_BARSUP lutPrioList TK_CLOSE_BRACE
714
715
716
717
		{
			let args = $2::(List.rev $4) in
			make_val_exp (PRIO_n args) $1
		}
Pascal Raymond's avatar
Pascal Raymond committed
718
719
720
721
722
	|	TK_OPEN_BRACE TK_BARSUP lutPrioList TK_CLOSE_BRACE
		{
			let args = (List.rev $3) in
			make_val_exp (PRIO_n args) $1
		}
Pascal Raymond's avatar
Pascal Raymond committed
723
	|	TK_OPEN_BRACE lutTraceExp lutWeightOptOBSO TK_BAR lutChoiceList TK_CLOSE_BRACE
724
725
726
		{
			let args = ($2, $3)::(List.rev $5) in
			make_val_exp (CHOICE_n args) $1 
Pascal Raymond's avatar
Pascal Raymond committed
727
		}	
728
	|	TK_OPEN_BRACE TK_BAR lutChoiceList TK_CLOSE_BRACE
Pascal Raymond's avatar
Pascal Raymond committed
729
730
731
		{
			let args = (List.rev $3) in
			make_val_exp (CHOICE_n args) $1 
732
		}
Pascal Raymond's avatar
Pascal Raymond committed
733
	|	TK_OPEN_BRACE lutTraceExp TK_PARA lutParaList TK_CLOSE_BRACE
734
735
736
737
		{
			let args = $2::(List.rev $4) in
			make_val_exp (PARA_n args) $1
		}
Pascal Raymond's avatar
Pascal Raymond committed
738
739
740
741
742
	|	TK_OPEN_BRACE TK_PARA lutParaList TK_CLOSE_BRACE
		{
			let args = (List.rev $3) in
			make_val_exp (PARA_n args) $1
		}
743
744
	;

745
746
747
*/

lutChoice:
Pascal Raymond's avatar
Pascal Raymond committed
748
		TK_BAR lutTraceExp 
749
			{ [ ($2, None) ] }
Pascal Raymond's avatar
Pascal Raymond committed
750
	|	TK_BAR lutExp TK_COLON lutTraceExp 
751
			{ let w = Some {it = $2; src = $3} in [ ($4, w) ] }
Pascal Raymond's avatar
Pascal Raymond committed
752
	|	lutChoice TK_BAR lutTraceExp
753
			{ ($3, None)::$1 }
Pascal Raymond's avatar
Pascal Raymond committed
754
	|	lutChoice TK_BAR lutExp TK_COLON lutTraceExp
755
756
757
758
759
760
761
762
763
764
765
			{ let w = Some {it = $3; src = $4} in ($5,w)::$1 }
	;

/* trop de conflits ...
lutWeightOpt:
	//nada
		{ None }
	|	lutExp TK_COLON
		{ Some {it = $1; src = $2} }
	;
lutChoice1:
Pascal Raymond's avatar
Pascal Raymond committed
766
		TK_BAR lutWeightOpt lutTraceExp 
767
			{ [ ($3, $2) ] }
Pascal Raymond's avatar
Pascal Raymond committed
768
	|	lutChoice TK_BAR lutWeightOpt lutTraceExp
769
770
771
772
773
			{ ($4,$3)::$1 }
	;
*/

lutPrio:
Pascal Raymond's avatar
Pascal Raymond committed
774
		TK_BARSUP lutTraceExp
775
			{ [ $2 ] }
Pascal Raymond's avatar
Pascal Raymond committed
776
	|	lutPrio TK_BARSUP lutTraceExp
777
778
779
780
			{ $3::$1 }
	;

lutPara:
Pascal Raymond's avatar
Pascal Raymond committed
781
		TK_PARA lutTraceExp
782
			{ [ $2 ] }
Pascal Raymond's avatar
Pascal Raymond committed
783
	|	lutPara TK_PARA lutTraceExp
784
785
786
787
788
			{ $3::$1 }
	;
	

/* on peut omettre le premier symbole, mais du coup pas de poids possible pour Choice */
Pascal Raymond's avatar
Pascal Raymond committed
789
790
lutBraceExp:
		TK_OPEN_BRACE lutTraceExp TK_CLOSE_BRACE
791
792
793
794
795
796
		{ $2 }
	|	TK_OPEN_BRACE lutPrio TK_CLOSE_BRACE
		{
			let args = (List.rev $2) in
			make_val_exp (PRIO_n args) $1
		}
Pascal Raymond's avatar
Pascal Raymond committed
797
	|	TK_OPEN_BRACE lutTraceExp lutPrio TK_CLOSE_BRACE
798
		{
799
			let args = $2::(List.rev $3) in
800
801
802
803
804
805
806
			make_val_exp (PRIO_n args) $1
		}
	|	TK_OPEN_BRACE lutChoice TK_CLOSE_BRACE
		{
			let args = (List.rev $2) in
			make_val_exp (CHOICE_n args) $1 
		}	
Pascal Raymond's avatar
Pascal Raymond committed
807
	|	TK_OPEN_BRACE lutTraceExp lutChoice TK_CLOSE_BRACE
808
		{
809
			let args = ($2,None)::(List.rev $3) in
810
811
812
813
814
815
816
			make_val_exp (CHOICE_n args) $1
		}	
	|	TK_OPEN_BRACE lutPara TK_CLOSE_BRACE
		{
			let args = (List.rev $2) in
			make_val_exp (PARA_n args) $1
		}
Pascal Raymond's avatar
Pascal Raymond committed
817
	|	TK_OPEN_BRACE lutTraceExp lutPara TK_CLOSE_BRACE
818
		{
819
			let args = $2::(List.rev $3) in
820
821
822
823
824
			make_val_exp (PARA_n args) $1
		}	
	;


825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
/* Expresssions algbriques classique s
*/


/* ebnf:group=expressions */

lutExp:
	/* identificateurs, constantes et call */ 
		lutConst { $1 }
	|	lutIdentRef { $1 }
	|	TK_PRE lutIdent { make_val_exp (PRE_n $2) $1 }

	/* simple parenthese */
	|	TK_OPEN_PAR lutExp TK_CLOSE_PAR { $2 }	

	/* unaire */
	|	lutUnExp { $1 }

	/* oprateurs binaires infixs */
	|	lutBinExp { $1 }

	/* oprateurs ternaires */
	|	TK_IF lutExp TK_THEN lutExp TK_ELSE lutExp
			{ make_val_exp (CALL_n (flagit "ite" $1, [$2;$4;$6])) $1 }
	;

lutUnExp:
		TK_MINUS lutExp %prec TK_UMINUS { make_val_exp (CALL_n (flagit "uminus" $1, [$2])) $1 }
	|	TK_NOT lutExp { make_val_exp (CALL_n (flagit "not" $1, [$2])) $1 }
	;


lutBinExp:
		lutExp TK_EQ lutExp { make_val_exp (CALL_n (flagit "eq" $2, [$1;$3])) $2 }
	|	lutExp TK_NEQ lutExp { make_val_exp (CALL_n (flagit "neq" $2, [$1;$3])) $2 }
	|	lutExp TK_OR lutExp { make_val_exp (CALL_n (flagit "or" $2, [$1;$3])) $2 }
	|	lutExp TK_XOR lutExp { make_val_exp (CALL_n (flagit "xor" $2, [$1;$3])) $2 }
	|	lutExp TK_AND lutExp { make_val_exp (CALL_n (flagit "and" $2, [$1;$3])) $2 }
	|	lutExp TK_IMPL lutExp { make_val_exp (CALL_n (flagit "impl" $2, [$1;$3])) $2 }
	|	lutExp TK_PLUS lutExp { make_val_exp (CALL_n (flagit "plus" $2, [$1;$3])) $2 }
	|	lutExp TK_MINUS lutExp { make_val_exp (CALL_n (flagit "minus" $2, [$1;$3])) $2 }
	|	lutExp TK_TIMES lutExp { make_val_exp (CALL_n (flagit "times" $2, [$1;$3])) $2 }
	|	lutExp TK_SLASH lutExp { make_val_exp (CALL_n (flagit "slash" $2, [$1;$3])) $2 }
	|	lutExp TK_DIV lutExp { make_val_exp (CALL_n (flagit "div" $2, [$1;$3])) $2 }
	|	lutExp TK_MOD lutExp { make_val_exp (CALL_n (flagit "mod" $2, [$1;$3])) $2 }
	|	lutExp TK_LT lutExp { make_val_exp (CALL_n (flagit "lt" $2, [$1;$3])) $2 }
	|	lutExp TK_LTE lutExp { make_val_exp (CALL_n (flagit "lte" $2, [$1;$3])) $2 }
	|	lutExp TK_GT lutExp { make_val_exp (CALL_n (flagit "gt" $2, [$1;$3])) $2 }
	|	lutExp TK_GTE lutExp { make_val_exp (CALL_n (flagit "gte" $2, [$1;$3])) $2 }
	;

Pascal Raymond's avatar
Pascal Raymond committed
876
877
878
879
880
881
882
883
884
885
lutInteger: /* ebnf:print=ignore */
	TK_ICONST 
		{ make_val_exp (ICONST_n (ident_of_token $1)) $1 }
	;

lutFloating: /* ebnf:print=ignore */
	TK_RCONST
		{ make_val_exp (RCONST_n (ident_of_token $1)) $1 }
	;

886
887
888
889
890
lutConst: /* ebnf:print=short */
		TK_TRUE
		{ make_val_exp TRUE_n $1 }
	|   TK_FALSE
		{ make_val_exp FALSE_n $1}
Pascal Raymond's avatar
Pascal Raymond committed
891
892
893
894
	|	lutInteger
		{ $1 }
	|	lutFloating
		{ $1 }
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
	;

/* statement ou exp */

/* ebnf:group=identref */

lutIdentRef:
		lutIdent %prec HACK_ID
			{ make_val_exp (IDENT_n $1) $1.src }
	|	lutIdent TK_OPEN_PAR  TK_CLOSE_PAR %prec HACK_CALL
			{ make_val_exp (CALL_n ($1, [])) $1.src }
	|	lutIdent TK_OPEN_PAR lutArgList TK_CLOSE_PAR %prec HACK_CALL
			{ make_val_exp (CALL_n ($1, List.rev $3)) $1.src }
	;


/*
lutArgListOpt:
			{ [] }
	|   lutArgList
			{ $1 }
	;
*/

lutArgList:
		lutArg
			{ [$1] }
	| lutArgList TK_COMA lutArg
			{ $3::$1 }
;

Pascal Raymond's avatar
Pascal Raymond committed
926
lutArg: lutTraceExp
927
928
		{ $1 }
;