-
Notifications
You must be signed in to change notification settings - Fork 0
/
parserOcamlBig.sam
806 lines (763 loc) · 30.7 KB
/
parserOcamlBig.sam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
208
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
%{
open Ast
open Astype
open Hyper2
let file_name = ref ""
%}
%token <Ast.position*Int64.t> INT
%token <Ast.position*float> FLOAT
%token <Ast.position*string> CHAINE
%token <Ast.position*string> IDENT
%token <Ast.position * int> CHAR
%token EOF
%token <Ast.position> PARG
%token <Ast.position> PARD
%token <Ast.position> CROCHETG
%token <Ast.position> CROCHETD
%token <Ast.position> CURLYG
%token <Ast.position> CURLYD
%token <Ast.position> AFFECT
%token <Ast.position> PLUS_AFFECT
%token <Ast.position> TIMES_AFFECT
%token <Ast.position> MINUS_AFFECT
%token <Ast.position> OR_AFFECT
%token <Ast.position> AND_AFFECT
%token <Ast.position> XOR_AFFECT
%token <Ast.position> SHIFT_LEFT_AFFECT
%token <Ast.position> SHIFT_RIGHT_AFFECT
%token <Ast.position> OR
%token <Ast.position> AND
%token <Ast.position> EQ
%token <Ast.position> NEQ
%token <Ast.position> L
%token <Ast.position> G
%token <Ast.position> LEQ
%token <Ast.position> GEQ
%token <Ast.position> PLUS
%token <Ast.position> MINUS
%token <Ast.position> TIMES
%token <Ast.position> MODULO
%token <Ast.position> EXP
%token <Ast.position> NOT
%token <Ast.position> DOT
%token <Ast.position> ASSERT
%token <Ast.position> CONCAT
%token <Ast.position> BIT_OR
%token <Ast.position> BIT_AND
%token <Ast.position> BIT_XOR
%token <Ast.position> SHIFT_LEFT
%token <Ast.position> SHIFT_RIGHT
%token <Ast.position> ELSE
%token <Ast.position> ELSEIF
%token <Ast.position> END
%token <Ast.position> FALSE
%token <Ast.position> FOR
%token <Ast.position> FUNCTION
%token <Ast.position> IF
%token MUTABLE
%token <Ast.position> RETURN
%token <Ast.position> STRUCT
%token <Ast.position> TRUE
%token <Ast.position> WHILE
%token <Ast.position> DOWHILE
%token <Ast.position*Int64.t * string> ENTIER_IDENT
%token <Ast.position*string> IDENT_PARG
%token <Ast.position*Int64.t> ENTIER_PARG
%token <Ast.position*string> PARD_IDENT
%token TYPE
%token <Ast.position> COLON
%token <Ast.position> SEMICOLON
%token <Ast.position> COMMA
%token <string> DOCSTRING
%nonassoc ASSERT
%nonassoc RETURN
%right AFFECT
%right PLUS_AFFECT
%right TIMES_AFFECT
%right MINUS_AFFECT
%right OR_AFFECT
%right AND_AFFECT
%right XOR_AFFECT
%right SHIFT_LEFT_AFFECT
%right SHIFT_RIGHT_AFFECT
%left BIT_OR
%left BIT_AND
%left BIT_XOR
%left SHIFT_LEFT
%left SHIFT_RIGHT
%left OR
%left AND
%left EQ NEQ
%left L G LEQ GEQ
%left PLUS MINUS
%left TIMES
%left MODULO
%nonassoc NOT
%nonassoc unary_minus
%right EXP
%left CONCAT
%left DOT
%nonassoc calcValArray
%left CROCHETG
%start fichier
%%
fichier<Ast.fichier>:
| declarations = declarations_list {DeclarationList declarations}
;
declarations_list <Ast.declaration list>:
| EOF {[]}
| s = structure SEMICOLON d = declarations_list {s::d}
| f = fonction SEMICOLON d = declarations_list {f::d}
| e = expr SEMICOLON d = declarations_list {(Dexpr e)::d}
| s = structure EOF {[s]}
| f = fonction EOF {[f]}
| e = expr EOF {[Dexpr e]}
;
structure<Ast.declaration>:
| MUTABLE STRUCT pi = IDENT parameters = param_list
{
let (p,i) = pi in
Dstruct (true, p, i, parameters)
}
| STRUCT pi = IDENT parameters = param_list
{
let (p,i) = pi in
Dstruct (false, p, i, parameters)
}
;
param_list<Ast.param list>:
| END {[]}
| SEMICOLON pl = param_list {pl}
| p = param SEMICOLON pl = param_list {p::pl}
| p = param END {[p]}
;
typage<Ast.position * string>:
| TYPE pi = IDENT {pi}
;
fonction<Ast.declaration>:
| FUNCTION pig = IDENT_PARG parameters = separated_list_COMMA_param
PARD pb = bloc_END
{
let (p1,ig) = pig in
let (pEnd, (p,eL)) = pb in
Dfonction (p1,ig, parameters, p1, Any, (p,eL), "")
}
| FUNCTION pig = IDENT_PARG parameters = separated_list_COMMA_param
PARD pt = typage pb = bloc_END
{
let (p1,ig) = pig in
let (pEnd, (p,eL)) = pb in
let typ,p2 = match pt with
| (p, "Int64") -> Int64, p
| (p, "Float64") -> Float64, p
| (p, "Bool") -> Bool, p
| (p, "String") -> Array, p
| (p, "Any") -> Any, p
| (p, "Nothing") -> Nothing, p
| (p, "Array") -> Array, p
| (p, s) -> S s, p
in
Dfonction (p1,ig, parameters, p2, typ, (p,eL), "")
}
| FUNCTION pig = IDENT_PARG parameters = separated_list_COMMA_param
PARD e = expr pb = bloc_END
{
let (p1,ig) = pig in
let (pEnd, (p,eL)) = pb in
Dfonction (p1,ig, parameters, p1, Any, (Hyper2.fusionPos (fst e) p, e::eL), "")
}
| FUNCTION pig = IDENT_PARG parameters = separated_list_COMMA_param
PARD pt = typage e = expr pb = bloc_END
{
let (p1,ig) = pig in
let (pEnd, (p,eL)) = pb in
let typ,p2 = match pt with
| (p, "Int64") -> Int64, p
| (p, "Float64") -> Float64, p
| (p, "Bool") -> Bool, p
| (p, "String") -> Array, p
| (p, "Any") -> Any, p
| (p, "Nothing") -> Nothing, p
| (p, "Array") -> Array, p
| (p, s) -> S s, p
in
Dfonction (p1,ig, parameters, p2, typ, (Hyper2.fusionPos (fst e) p, e::eL), "")
}
| doc = DOCSTRING FUNCTION pig = IDENT_PARG parameters = separated_list_COMMA_param
PARD pb = bloc_END
{
let (p1,ig) = pig in
let (pEnd, (p,eL)) = pb in
Dfonction (p1,ig, parameters, p1, Any, (p,eL), doc)
}
| doc = DOCSTRING FUNCTION pig = IDENT_PARG parameters = separated_list_COMMA_param
PARD pt = typage pb = bloc_END
{
let (p1,ig) = pig in
let (pEnd, (p,eL)) = pb in
let typ,p2 = match pt with
| (p, "Int64") -> Int64, p
| (p, "Float64") -> Float64, p
| (p, "Bool") -> Bool, p
| (p, "String") -> Array, p
| (p, "Any") -> Any, p
| (p, "Nothing") -> Nothing, p
| (p, "Array") -> Array, p
| (p, s) -> S s, p
in
Dfonction (p1,ig, parameters, p2, typ, (p,eL), doc)
}
| doc = DOCSTRING FUNCTION pig = IDENT_PARG parameters = separated_list_COMMA_param
PARD e = expr pb = bloc_END
{
let (p1,ig) = pig in
let (pEnd, (p,eL)) = pb in
Dfonction (p1,ig, parameters, p1, Any, (Hyper2.fusionPos (fst e) p, e::eL), doc)
}
| doc = DOCSTRING FUNCTION pig = IDENT_PARG parameters = separated_list_COMMA_param
PARD pt = typage e = expr pb = bloc_END
{
let (p1,ig) = pig in
let (pEnd, (p,eL)) = pb in
let typ,p2 = match pt with
| (p, "Int64") -> Int64, p
| (p, "Float64") -> Float64, p
| (p, "Bool") -> Bool, p
| (p, "String") -> Array, p
| (p, "Any") -> Any, p
| (p, "Nothing") -> Nothing, p
| (p, "Array") -> Array, p
| (p, s) -> S s, p
in
Dfonction (p1,ig, parameters, p2, typ, (Hyper2.fusionPos (fst e) p, e::eL), doc)
}
;
separated_list_COMMA_param<Ast.param list>:
| {[]}
| p = param pL = separated_list_C_P {p::pL}
;
separated_list_C_P<Ast.param list>:
| {[]}
| COMMA p = param pL = separated_list_C_P {p::pL}
;
param<Ast.param>:
| pi = IDENT pb = typage
{
let (p1,i) = pi in
let typ,p2 = match pb with
| (p, "Float64") -> Float64, p
| (p, "Int64") -> Int64, p
| (p, "Bool") -> Bool, p
| (p, "String") -> Array, p
| (p, "Any") -> Any, p
| (p, "Nothing") -> Nothing, p
| (p, "Array") -> Array, p
| (p, s) -> S s, p
in
Param (p1, i, p2, typ)
}
| pi = IDENT
{
let (p1, i_) = pi in
let (id, type_colle) = Hyper2.separate_string i_ !file_name in
match type_colle with
| None -> Param (p1, id, p1, Any)
| Some "Float64" -> Param (p1, id, p1, Float64)
| Some "Int64" -> Param (p1, id, p1, Int64)
| Some "Bool" -> Param (p1, id, p1, Bool)
| Some "String" -> Param (p1, id, p1, Array)
| Some "Any" -> Param (p1, id, p1, Any)
| Some "Nothing" -> Param (p1, id, p1, Nothing)
| Some "Array" -> Param (p1, id, p1, Array)
| Some s -> Param (p1, id, p1, S s)
}
;
separated_list_COMMA_expr<Ast.expression list>:
| {[]}
| e = expr eL = separated_list_C_E {e::eL}
;
separated_list_C_E<Ast.expression list>:
| {[]}
| COMMA e = expr eL = separated_list_C_E {e::eL}
;
expr_wMin_<Ast.expression>:
| p = ASSERT e = expr {p, EAssert (p.ldeb, !file_name, e)}
| pe1 = expr_wMin_ p = EQ pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Eq, pe1, pe2)) }
| pe1 = expr_wMin_ p = NEQ pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Neq, pe1, pe2)) }
| pe1 = expr_wMin_ p = L pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Lo, pe1, pe2)) }
| pe1 = expr_wMin_ p = G pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Gr, pe1, pe2)) }
| pe1 = expr_wMin_ p = LEQ pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Leq, pe1, pe2)) }
| pe1 = expr_wMin_ p = GEQ pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Geq, pe1, pe2)) }
| pe1 = expr_wMin_ p = PLUS pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Plus, pe1, pe2)) }
| pe1 = expr_wMin_ p = MINUS pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Minus, pe1, pe2)) }
| pe1 = expr_wMin_ p = TIMES pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Times, pe1, pe2)) }
| pe1 = expr_wMin_ p = MODULO pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Modulo, pe1, pe2)) }
| pe1 = expr_wMin_ p = EXP pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Exp, pe1, pe2)) }
| pe1 = expr_wMin_ p = AND pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, And, pe1, pe2)) }
| pe1 = expr_wMin_ p = OR pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Or, pe1, pe2)) }
| pe1 = expr_wMin_ p = CONCAT pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Concat, pe1, pe2)) }
| pe1 = expr_wMin_ p = BIT_OR pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Bit_Or, pe1, pe2)) }
| pe1 = expr_wMin_ p = BIT_AND pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Bit_And, pe1, pe2)) }
| pe1 = expr_wMin_ p = BIT_XOR pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Bit_Xor, pe1, pe2)) }
| pe1 = expr_wMin_ p = SHIFT_LEFT pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Shift_Left, pe1, pe2)) }
| pe1 = expr_wMin_ p = SHIFT_RIGHT pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in ((Hyper2.fusionPos p1 p2) , Ebinop (p, Shift_Right, pe1, pe2)) }
| pi = INT {let (p,i) = pi in (p,Eentier i)}
| pc = CHAR {let (p, c) = pc in (p,Echar c)}
| pf = FLOAT {let (p, f) = pf in (p, Eflottant f)}
| ps = CHAINE {let (p,s) = ps in (p, Echaine s)}
| p = TRUE {(p, Etrue)}
| p = FALSE {(p, Efalse)}
| pb = ENTIER_IDENT {
let (p,i,s) = pb in (p, EentierIdent (p, i, s))
}
| pi = ENTIER_PARG pb = bloc1 p2 = PARD {
let (p,i) = pi in
Hyper2.fusionPos p p2, EentierParG (p, i, pb)}
| p1 = PARG pb = bloc1 p2 = PARD { Hyper2.fusionPos p1 p2, Ebloc1 pb }
| p1 = PARG e = expr pi = PARD_IDENT {
let (p2,i) = pi in
Hyper2.fusionPos p1 p2, EparDIdent (e, p2, i)}
| pi = IDENT_PARG l = separated_list_COMMA_expr p2 = PARD {
let (p1,i) = pi in
if i = "println" then
Hyper2.fusionPos p1 p2, Eapplication (p1, "print", l @ [(p1,Echaine "\n")])
else Hyper2.fusionPos p1 p2, Eapplication (p1, i, l)}
| p = NOT e = expr {Hyper2.fusionPos p (fst e), Enot e}
| pl = expr_wMin_ AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, e)
|_ -> raise Ast.Parsing_Error
}
| pl = expr_wMin_ PLUS_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Plus, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr_wMin_ TIMES_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Times, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr_wMin_ MINUS_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Minus, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr_wMin_ OR_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Bit_Or, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr_wMin_ AND_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Bit_And, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr_wMin_ XOR_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Bit_Xor, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr_wMin_ SHIFT_LEFT_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Shift_Left, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr_wMin_ SHIFT_RIGHT_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Shift_Right, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = lvalue_wMin_ {let (p,l) = pl in p, Elvalue l}
| p = RETURN e = expr {Hyper2.fusionPos p (fst e), Ereturn (p,Some e)}
| p = RETURN {p, Ereturn (p, None)}
| p1 = FOR pi = IDENT AFFECT e1 = expr COLON e2b = expr_bloc p2 = END {
let (p,i) = pi in
let (e2, b) = e2b in
Hyper2.fusionPos p1 p2, Efor ((i : ident), e1, e2, b)
}
| w = whileExp { w }
| w = doWhileExp { w }
| p1 = IF eb = expr_bloc pel = else_exp {
let (e, b) = eb in
let (p2, el) = pel in
Hyper2.fusionPos p1 p2, Eif (e, b, el)
}
| p1 = CROCHETG p2 = CROCHETD {
Hyper2.build_array []
}
| p1 = CROCHETG e1 = expr COMMA e2 = expr arr = separated_list_C_E p2 = CROCHETD {
Hyper2.build_array (e1::e2::arr)
}
;
expr_w_Ret<Ast.expression>:
| p = ASSERT e = expr_w_Ret {p, EAssert (p.ldeb, !file_name, e)}
| pe1 = expr p = EQ pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Eq, pe1, pe2) }
| pe1 = expr p = NEQ pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Neq, pe1, pe2) }
| pe1 = expr p = L pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Lo, pe1, pe2) }
| pe1 = expr p = G pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Gr, pe1, pe2) }
| pe1 = expr p = LEQ pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Leq, pe1, pe2) }
| pe1 = expr p = GEQ pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Geq, pe1, pe2) }
| pe1 = expr p = PLUS pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Plus, pe1, pe2) }
| pe1 = expr p = MINUS pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Minus, pe1, pe2) }
| pe1 = expr p = TIMES pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Times, pe1, pe2) }
| pe1 = expr p = MODULO pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Modulo, pe1, pe2) }
| pe1 = expr p = EXP pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Exp, pe1, pe2) }
| pe1 = expr p = AND pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, And, pe1, pe2) }
| pe1 = expr p = OR pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Or, pe1, pe2) }
| pe1 = expr p = CONCAT pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Concat, pe1, pe2) }
| pe1 = expr p = BIT_OR pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Bit_Or, pe1, pe2) }
| pe1 = expr p = BIT_AND pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Bit_And, pe1, pe2) }
| pe1 = expr p = BIT_XOR pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Bit_Xor, pe1, pe2) }
| pe1 = expr p = SHIFT_LEFT pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Shift_Left, pe1, pe2) }
| pe1 = expr p = SHIFT_RIGHT pe2 = expr_w_Ret { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Shift_Right, pe1, pe2) }
| pi = INT {let (p,i) = pi in p, Eentier i}
| pc = CHAR {let (p, c) = pc in (p,Echar c)}
| pf = FLOAT {let (p, f) = pf in (p, Eflottant f)}
| ps = CHAINE {let (p,s) = ps in p, Echaine s}
| p = TRUE {p, Etrue}
| p = FALSE {p, Efalse}
| pb = ENTIER_IDENT {
let (p,i,s) = pb in p, EentierIdent (p, i, s)
}
| pi = ENTIER_PARG pb = bloc1 p2 = PARD {
let (p1,i) = pi in
(Hyper2.fusionPos p1 p2, EentierParG (p1, i, pb))}
| p1 = PARG b = bloc1 p2 = PARD {Hyper2.fusionPos p1 p2, Ebloc1 b}
| p1 = PARG e = expr pi = PARD_IDENT {
let (p2,i) = pi in
Hyper2.fusionPos p1 p2, EparDIdent (e, p2, i)}
| pi = IDENT_PARG l = separated_list_COMMA_expr p2 = PARD {
let (p1,i) = pi in
if i = "println" then
Hyper2.fusionPos p1 p2, Eapplication (p1, "print", l @ [(p1,Echaine "\n")])
else Hyper2.fusionPos p1 p2, Eapplication (p1, i, l)}
| p = NOT e = expr_w_Ret {Hyper2.fusionPos p (fst e), Enot e}
| pl = expr AFFECT e = expr_w_Ret {
match pl with
|p, Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, e)
| _ -> raise Ast.Parsing_Error
}
| pl = lvalue {let (p,l) = pl in p, Elvalue l}
| p1 = MINUS e = expr_w_Ret %prec unary_minus{Hyper2.fusionPos p1 (fst e),Eminus e}
| p1 = RETURN e = expr_w_Ret {Hyper2.fusionPos p1 (fst e), Ereturn (p1, Some e)}
| p1 = FOR pi = IDENT AFFECT e1 = expr COLON e2b = expr_bloc p2 = END {
let (p,i) = pi in
let (e2, b) = e2b in
Hyper2.fusionPos p1 p2, Efor ((i : ident), e1, e2, b)
}
| w = whileExp { w }
| w = doWhileExp { w }
| p1 = IF eb = expr_bloc pel = else_exp {
let (e,b) = eb in
let (p2, el) = pel in
Hyper2.fusionPos p1 p2, Eif (e, b, el)
}
| p1 = CROCHETG arr = separated_list_COMMA_expr p2 = CROCHETD {
Hyper2.build_array arr
}
| pl = expr PLUS_AFFECT e = expr_w_Ret {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Plus, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr TIMES_AFFECT e = expr_w_Ret {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Times, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr MINUS_AFFECT e = expr_w_Ret {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Minus, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr OR_AFFECT e = expr_w_Ret {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Bit_Or, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr AND_AFFECT e = expr_w_Ret {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Bit_And, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr XOR_AFFECT e = expr_w_Ret {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Bit_Xor, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr SHIFT_LEFT_AFFECT e = expr_w_Ret {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Shift_Left, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr SHIFT_RIGHT_AFFECT e = expr_w_Ret {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Shift_Right, pl, e)))
|_ -> raise Ast.Parsing_Error
}
;
expr<Ast.expression>:
| p = ASSERT e = expr {p, EAssert (p.ldeb, !file_name, e)}
| pe1 = expr p = EQ pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Eq, pe1, pe2) }
| pe1 = expr p = NEQ pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Neq, pe1, pe2) }
| pe1 = expr p = L pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Lo, pe1, pe2) }
| pe1 = expr p = G pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Gr, pe1, pe2) }
| pe1 = expr p = LEQ pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Leq, pe1, pe2) }
| pe1 = expr p = GEQ pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Geq, pe1, pe2) }
| pe1 = expr p = PLUS pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Plus, pe1, pe2) }
| pe1 = expr p = MINUS pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Minus, pe1, pe2) }
| pe1 = expr p = TIMES pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Times, pe1, pe2) }
| pe1 = expr p = MODULO pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Modulo, pe1, pe2) }
| pe1 = expr p = EXP pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Exp, pe1, pe2) }
| pe1 = expr p = AND pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, And, pe1, pe2) }
| pe1 = expr p = OR pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Or, pe1, pe2) }
| pe1 = expr p = CONCAT pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Concat, pe1, pe2) }
| pe1 = expr p = BIT_OR pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Bit_Or, pe1, pe2) }
| pe1 = expr p = BIT_AND pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Bit_And, pe1, pe2) }
| pe1 = expr p = BIT_XOR pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Bit_Xor, pe1, pe2) }
| pe1 = expr p = SHIFT_LEFT pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Shift_Left, pe1, pe2) }
| pe1 = expr p = SHIFT_RIGHT pe2 = expr { let (p1, e1) = pe1 in let (p2,e2) = pe2 in (Hyper2.fusionPos p1 p2) , Ebinop (p, Shift_Right, pe1, pe2) }
| pi = INT {let (p,i) = pi in p, Eentier i}
| pc = CHAR {let (p, c) = pc in (p,Echar c)}
| pf = FLOAT {let (p, f) = pf in (p, Eflottant f)}
| ps = CHAINE {let (p,s) = ps in p, Echaine s}
| p = TRUE {p, Etrue}
| p = FALSE {p, Efalse}
| pb = ENTIER_IDENT {
let (p,i,s) = pb in p, EentierIdent (p, i, s)
}
| pi = ENTIER_PARG b = bloc1 p2 = PARD {
let (p1,i) = pi in
Hyper2.fusionPos p1 p2, EentierParG (p1, i, b)}
| p1 = PARG b = bloc1 p2 = PARD {Hyper2.fusionPos p1 p2, Ebloc1 b}
| p1 = PARG e = expr pi = PARD_IDENT {
let (p2,i) = pi in
Hyper2.fusionPos p1 p2, EparDIdent (e, p2, i)}
| pi = IDENT_PARG l = separated_list_COMMA_expr p2 = PARD {
let (p1,i) = pi in
if i = "println" then
Hyper2.fusionPos p1 p2, Eapplication (p1, "print", l @ [(p1,Echaine "\n")])
else Hyper2.fusionPos p1 p2, Eapplication (p1, i, l)}
| p = NOT e = expr {Hyper2.fusionPos p (fst e), Enot e}
| pl = lvalue {let (p,l) = pl in (p, Elvalue l)}
| p1 = MINUS e = expr %prec unary_minus {Hyper2.fusionPos p1 (fst e), Eminus e}
| p1 = RETURN e = expr {Hyper2.fusionPos p1 (fst e), Ereturn (p1, Some e)}
| p = RETURN {p, Ereturn (p, None)}
| p1 = FOR pi = IDENT AFFECT e1 = expr COLON e2b = expr_bloc p2 = END {
let (p,i) = pi in
let (e2, b) = e2b in
Hyper2.fusionPos p1 p2, Efor ((i : ident), e1, e2, b)
}
| w = whileExp { w }
| w = doWhileExp { w }
| p1 = IF eb = expr_bloc pel = else_exp {
let (e,b) = eb in
let (p2, el) = pel in
Hyper2.fusionPos p1 p2, Eif (e, b, el)
}
| p1 = CROCHETG arr = separated_list_COMMA_expr p2 = CROCHETD {
Hyper2.build_array arr
}
| pl = expr AFFECT e = expr {
match pl with
|p, Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, e)
| _ -> raise Ast.Parsing_Error
}
| pl = expr PLUS_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Plus, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr TIMES_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Times, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr MINUS_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Minus, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr OR_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Bit_Or, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr AND_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Bit_And, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr XOR_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Bit_Xor, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr SHIFT_LEFT_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Shift_Left, pl, e)))
|_ -> raise Ast.Parsing_Error
}
| pl = expr SHIFT_RIGHT_AFFECT e = expr {
match pl with
|p,Elvalue l -> Hyper2.fusionPos p (fst e), ElvalueAffect (p, l, (p, Ebinop (p, Shift_Right, pl, e)))
|_ -> raise Ast.Parsing_Error
}
;
whileExp<Ast.expression>:
| p1 = WHILE e = expr pb = bloc_END {
let (p2,b) = pb in
Hyper2.fusionPos p1 p2, Ewhile (e, b)}
| p1 = WHILE e1 = expr_w_Ret e2 = expr_wMin_ pb = bloc_END {
let (p2,(p,eL)) = pb in
Hyper2.fusionPos p1 p2, Ewhile (e1, (Hyper2.fusionPos (fst e2) p, e2::eL))}
;
doWhileExp<Ast.expression>:
| p1 = DOWHILE b = bloc_END {
let p2,b = b in
Hyper2.fusionPos p1 p2, EdoWhile b
}
| p1 = DOWHILE e = expr b = bloc_END {
let p2, (pb, eL) = b in
Hyper2.fusionPos p1 p2, EdoWhile (Hyper2.fusionPos (fst e) pb, e::eL)
}
;
lvalue<Ast.position * Ast.lvalue>:
| pi = IDENT {let (p,i) = pi in p,Lident (p,i)}
| e = expr DOT pi = IDENT {
let (p,i) = pi in
Hyper2.fusionPos (fst e) p, Lindex (e, p, (i : ident))}
| e1 = expr_w_Ret CROCHETG e2 = expr CROCHETD %prec calcValArray {
Hyper2.fusionPos (fst e1) (fst e2), Larray (e1, e2)
}
;
lvalue_w_Ret<Ast.position * Ast.lvalue>:
| pi = IDENT {let (p,i) = pi in p,Lident (p,i)}
| e = expr_w_Ret DOT pi = IDENT {
let (p,i) = pi in
Hyper2.fusionPos (fst e) p, Lindex (e, p, (i : ident))}
| e1 = expr_w_Ret CROCHETG e2 = expr CROCHETD %prec calcValArray {
Hyper2.fusionPos (fst e1) (fst e2), Larray (e1, e2)
}
;
lvalue_wMin_<Ast.position * Ast.lvalue>:
| pi = IDENT {let (p,i) = pi in p,Lident (p,i)}
| e = expr_wMin_ DOT pi = IDENT {
let (p,i) = pi in
Hyper2.fusionPos (fst e) p, Lindex (e, p, (i : ident))}
| e1 = expr_wMin_ CROCHETG e2 = expr CROCHETD %prec calcValArray {
Hyper2.fusionPos (fst e1) (fst e2), Larray (e1, e2)
}
;
else_exp<Ast.position * Ast.else_>:
| p = END {p, Iend}
| ELSE pb = bloc_END {
let (p2, b) = pb in
p2, Ielse b}
| ELSE e = expr pb = bloc_END {
let (p2, (p,b)) = pb in
p2, Ielse (Hyper2.fusionPos (fst e) p, e::b)}
| ELSEIF eb = expr_bloc el = else_exp {
let (p, el) = el in
let (e,b) = eb in
p, Ielseif (e, b, el)
}
;
operateur<Ast.position * Astype.operateur>:
| p = EQ {(p,Eq)}
| p = NEQ {(p,Neq)}
| p = L {(p,Lo)}
| p = G {(p,Gr)}
| p = LEQ {(p,Leq)}
| p = GEQ {(p,Geq)}
| p = PLUS {(p,Plus)}
| p = MINUS {(p,Minus)}
| p = TIMES {(p,Times)}
| p = MODULO {(p,Modulo)}
| p = EXP {(p,Exp)}
| p = AND {(p,And)}
| p = OR {(p,Or)}
| p = CONCAT {(p, Concat)}
;
bloc<Ast.bloc>:
| e = expr {fst e, [e]}
| e = expr SEMICOLON pb = bloc {
let (p, eL) = pb in
Hyper2.fusionPos (fst e) p, e::eL}
| p = SEMICOLON pb = bloc {
let (p2, eL) = pb in
Hyper2.fusionPos p p2, eL
}
| p = SEMICOLON {
p, []
}
;
expr_bloc<Ast.expression * Ast.bloc>:
| e = expr {(e, (fst e, []))}
| e = expr b = expr_bloc2 %prec priomax {(e,b)}
| e1 = expr_w_Ret pe2 = expr_wMin_ pb = expr_bloc2 {
let (p1, e2) = pe2 in
let (p2, eL) = pb in
(e1, (Hyper2.fusionPos p1 p2, pe2::eL))}
| e1 = expr_w_Ret pe2 = expr_wMin_ {
let (p, e2) = pe2 in
(e1, (p, [pe2]))}
;
bloc_expr_END<Ast.bloc * Ast.expression>:
| e = expr p = END {((fst e,[]),e)}
| e1 = expr_w_Ret e2 = expr_wMin_ END {
(fst e1, [e1]), e2
}
| e = expr SEMICOLON b = bloc_expr_END {
let (b,ef) = b in
let (p2, eL) = b in
(Hyper2.fusionPos (fst e) p2, e::eL), ef
}
| p1 = SEMICOLON b = bloc_expr_END {
let (b,ef) = b in
let (p2, eL) = b in
(Hyper2.fusionPos p1 p2, eL), ef
}
;
expr_bloc2<Ast.bloc>:
| p = SEMICOLON {p, []}
| p1 = SEMICOLON e = expr pb = expr_bloc2 {
let (p2, eL) = pb in
(Hyper2.fusionPos p1 p2, (e::eL))}
| p1 = SEMICOLON pb = expr_bloc2 {
let p2,eL = pb in
(Hyper2.fusionPos p1 p2, eL)}
| p = SEMICOLON e = expr {
(Hyper2.fusionPos p (fst e), [e])}
;
bloc_END<Ast.position * Ast.bloc>:
| p = END {p,(p,[])}
| p1 = SEMICOLON e = expr pb = bloc_END {
let pEnd, (p2, eL) = pb in
pEnd, (Hyper2.fusionPos p1 p2, (e::eL))
}
| p1 = SEMICOLON pb = bloc_END {
let pEnd, (p2, eL) = pb in
(pEnd, (Hyper2.fusionPos p1 p2, eL))}
;
bloc1<Ast.bloc>:
| e = expr pb = bloc1bis {
let (p, eL) = pb in
Hyper2.fusionPos (fst e) p, (e::eL)}
| e = expr {(fst e), [e]}
;
bloc1bis<Ast.bloc>:
| p = SEMICOLON {
(p, [])
}
| p = SEMICOLON e = expr {
(Hyper2.fusionPos p (fst e), [e])
}
| p = SEMICOLON pb = bloc1bis {
let (p2,eL) = pb in (Hyper2.fusionPos p p2, eL)
}
| p = SEMICOLON e = expr pb = bloc1bis {
let (p2,eL) = pb in (Hyper2.fusionPos p p2, e::eL)
}
;