-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.y
64 lines (58 loc) · 1.04 KB
/
syntax.y
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
%{
#include<stdio.h>
#include <string.h>
#include<math.h>
int nb_lignes=1;
int col=0;
int yyparse();
int yylex();
int yyerror(char *s);
%}
%union {
int entier;
char* str;
}
%left add minus
%left mul division
%nonassoc UM
%token mc_do idf cst aff mc_IF par_ouv par_fer mc_then mc_else
pvg mc_while moins add mul division sup inf inf_eg sup_eg egale mc_id
%%
%start S ;
S:entete body fin pvg
{ printf("\nLe programme est syntaxiquement correcte\n");}
;
entete: mc_do mc_id aff mc_IF par_ouv condt par_fer
;
body: mc_then inst pvg mc_else inst pvg
;
fin: mc_while condt
;
condt: idf sup types
|idf inf types
|idf sup_eg types
|idf inf_eg types
|idf egale types
;
inst: idf aff expr
;
expr: expr minus expr %prec UM
| expr add expr
| expr mul expr
| expr division expr
| types
;
types: idf
|cst;
%%
main()
{
yyparse();
afficher();
}
yywrap()
{}
yyerror (char*msg)
{
printf("Erreur syntaxique a la ligne %d et a la colonne %d \n", nb_lignes, col);
}