-
Notifications
You must be signed in to change notification settings - Fork 1
/
grammar.txt
101 lines (65 loc) · 2.28 KB
/
grammar.txt
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
algo -> "algorithme" "procedure" IDENT
declarations
"debut"
instructions
"fin" "algorithme" "procedure" IDENT
algo -> "algorithme" "fonction" IDENT ":" type
declarations
"debut"
instructions
"fin" "algorithme" "fonction" IDENT
############################### DECLARATIONS #################################
declarations ->
parametres
constantes
types
variables
parametres -> parametres_globaux parametres_locaux
| parametres_locaux parametres_globaux
types -> IDENT = type_def
parametres_globaux -> "parametres" "globaux" decl_var
parametres_locaux -> "parametres" "locaux" decl_var
decl_var -> IDENT identlist
identlist -> IDENT | IDENT "," identlist
variables -> "variables" decl_var
type_def -> enum | tableau | enregistrement | pointeur
enum -> (identlist)
tableau -> IDENT = dimension IDENT
enregistrement -> IDENT = "enregistrement"
decl_var
"fin" "enregistrement" IDENT
pointeur -> IDENT = "^" IDENT
dimension -> NUM | NUM "x" dimension
############################### EXPRESSIONS #################################
expression -> "NUL" | CHAR | STRING | NUM | IDENT | appel_fonction
| expression opbin expression | opun expression | (expression)
| expression "[" identlist "]" | expression "." IDENT | expression "^"
exprlist -> expression | expression "," exprlist
binop -> "+" | "-" | "*" | "/" | "div" | "mod" | "et" | "ou" | "oue" | "="
| "<>" | "<" | ">" | "<=" | ">="
opun -> "+" | "-" | "non"
############################### INSTRUCTIONS #################################
instruction -> appel_fonction | affectation
| si | selon | fairetantque | tantquefaire | pour | retourne
instructions -> instruction | instruction instructions
affectation -> IDENT "<-" expression
appel_fonction -> IDENT "(" exprlist ")"
si -> "si" expression "alors"
instructions
sinon
"fin" "si"
sinon -> | "sinon" instructions
selon -> "selon" expression "faire" liste_cas "fin" "selon"
cas -> exprlist ":" instructions
liste_cas -> cas | cas liste_cas
fairetantque -> "faire"
instructions
TANTQUE expression
tantquefaire -> TANTQUE expression "faire"
instructions
"fin" TANTQUE
pour -> "pour" affectation JUSQUA expression decroissant "faire"
instructions
"fin" "pour"
decroissant -> | "decroissant"
retourne -> "retourne" | "retourne" expression