Analyse grammaticale OK

This commit is contained in:
Foussats Morgane 2021-03-22 12:45:21 +01:00
parent 1214af43d7
commit 6ab787820b
14 changed files with 6928 additions and 1310 deletions

BIN
a.out Executable file

Binary file not shown.

View file

@ -1,3 +1,14 @@
%{
#include "analyse_syntaxique.tab.h"
int yywrap(void){
return 1;
}
%}
ADD "+"
SUB "-"
MUL "*"
@ -32,8 +43,9 @@ DIGIT [0-9]
VARIABLE [A-Za-z0-9_]+
CONST "const"
DECIMAL {DIGIT}+
EXPONENTIEL {DIGIT}+"^"{DIGIT}+
ENTIER {DECIMAL}|{EXPONENTIEL}
EXPONENTIEL {DIGIT}+"e"{DIGIT}+
ENTIER {DECIMAL}
ENTIEREXP {EXPONENTIEL}
OPERATION {ADD}|{SUB}|{MUL}|{DIV}
COMPARATEUR {EGAL}|{LT}|{GT}
SEPARATOR {SPACE}|{TAB}
@ -79,13 +91,12 @@ SEPARATOR {SPACE}|{TAB}
{tWHILE} {return tWHILE ;}
{CONST} {return tCONST ;}
{ENTIER} {return tENTIER ;}
{VARIABLE} {return tVAR ;}
{ENTIER} {yylval.nombre = atoi(yytext); return tENTIER ;}
{ENTIEREXP} {yylval.nombre = -1; return tENTIEREXP;}
{VARIABLE} {strcpy(yylval.id, yytext); return tVAR ;}
%%
int yywrap(void){
return 1;
}
//int main(void){
// yylex();
//}

File diff suppressed because it is too large Load diff

View file

@ -99,36 +99,37 @@ extern int yydebug;
enum yytokentype
{
tENTIER = 258,
tADD = 259,
tSUB = 260,
tMUL = 261,
tDIV = 262,
tPO = 263,
tPF = 264,
tAO = 265,
tAF = 266,
tERROR = 267,
tPV = 268,
tVIRGULE = 269,
tAFFECTATION = 270,
tEGAL = 271,
tDIFF = 272,
tLT = 273,
tGT = 274,
tGTE = 275,
tLTE = 276,
tMAIN = 277,
tINT = 278,
tPRINT = 279,
tRETURN = 280,
tOR = 281,
tAND = 282,
tIF = 283,
tELSE = 284,
tWHILE = 285,
tCONST = 286,
tVAR = 287,
tNOT = 288
tENTIEREXP = 259,
tADD = 260,
tSUB = 261,
tMUL = 262,
tDIV = 263,
tPO = 264,
tPF = 265,
tAO = 266,
tAF = 267,
tERROR = 268,
tPV = 269,
tVIRGULE = 270,
tAFFECTATION = 271,
tEGAL = 272,
tDIFF = 273,
tLT = 274,
tGT = 275,
tGTE = 276,
tLTE = 277,
tMAIN = 278,
tINT = 279,
tPRINT = 280,
tRETURN = 281,
tOR = 282,
tAND = 283,
tIF = 284,
tELSE = 285,
tWHILE = 286,
tCONST = 287,
tVAR = 288,
tNOT = 289
};
#endif
@ -140,8 +141,9 @@ union YYSTYPE
#line 1 "analyse_syntaxique.y" /* yacc.c:355 */
int nombre;
char id[30];
#line 145 "analyse_syntaxique.tab.c" /* yacc.c:355 */
#line 147 "analyse_syntaxique.tab.c" /* yacc.c:355 */
};
typedef union YYSTYPE YYSTYPE;
@ -157,8 +159,11 @@ int yyparse (void);
#endif /* !YY_YY_ANALYSE_SYNTAXIQUE_TAB_H_INCLUDED */
/* Copy the second part of user declarations. */
#line 6 "analyse_syntaxique.y" /* yacc.c:358 */
#line 162 "analyse_syntaxique.tab.c" /* yacc.c:358 */
#include <stdio.h>
#line 167 "analyse_syntaxique.tab.c" /* yacc.c:358 */
#ifdef short
# undef short
@ -398,23 +403,23 @@ union yyalloc
#endif /* !YYCOPY_NEEDED */
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 6
#define YYFINAL 4
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 130
#define YYLAST 132
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 34
#define YYNTOKENS 35
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 25
#define YYNNTS 24
/* YYNRULES -- Number of rules. */
#define YYNRULES 57
#define YYNRULES 54
/* YYNSTATES -- Number of states. */
#define YYNSTATES 117
#define YYNSTATES 125
/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
by yylex, with out-of-bounds checking. */
#define YYUNDEFTOK 2
#define YYMAXUTOK 288
#define YYMAXUTOK 289
#define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@ -451,19 +456,19 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 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
25, 26, 27, 28, 29, 30, 31, 32, 33, 34
};
#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
0, 47, 47, 48, 48, 48, 50, 52, 54, 54,
55, 63, 63, 65, 67, 67, 69, 69, 69, 69,
69, 69, 69, 71, 73, 73, 75, 75, 77, 77,
79, 81, 83, 83, 83, 83, 83, 83, 83, 83,
83, 87, 89, 89, 89, 91, 93, 93, 93, 93,
93, 93, 93, 93, 93, 95, 97, 99
0, 63, 63, 65, 66, 68, 71, 72, 75, 77,
78, 80, 81, 82, 83, 84, 85, 87, 89, 90,
92, 93, 95, 96, 98, 100, 102, 103, 104, 105,
106, 107, 108, 109, 110, 112, 113, 115, 116, 118,
120, 121, 123, 125, 126, 127, 128, 129, 130, 131,
132, 133, 135, 137, 139
};
#endif
@ -472,14 +477,14 @@ static const yytype_uint8 yyrline[] =
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
"$end", "error", "$undefined", "tENTIER", "tADD", "tSUB", "tMUL",
"tDIV", "tPO", "tPF", "tAO", "tAF", "tERROR", "tPV", "tVIRGULE",
"$end", "error", "$undefined", "tENTIER", "tENTIEREXP", "tADD", "tSUB",
"tMUL", "tDIV", "tPO", "tPF", "tAO", "tAF", "tERROR", "tPV", "tVIRGULE",
"tAFFECTATION", "tEGAL", "tDIFF", "tLT", "tGT", "tGTE", "tLTE", "tMAIN",
"tINT", "tPRINT", "tRETURN", "tOR", "tAND", "tIF", "tELSE", "tWHILE",
"tCONST", "tVAR", "tNOT", "$accept", "C", "Fonctions", "Fonction",
"Main", "Params", "Param", "SuiteParams", "Body", "Instructions",
"Instruction", "Decl", "SuiteDecl", "Type", "Valeur", "Affbis", "Aff",
"E", "If", "Else", "While", "Cond", "Print", "Invocation", "Args", YY_NULLPTR
"tCONST", "tVAR", "tNOT", "$accept", "Main", "Params", "Param",
"SuiteParams", "Body", "Instructions", "Instruction", "Decl",
"SuiteDecl", "Type", "Valeur", "Affbis", "Aff", "E", "Args", "SuiteArgs",
"If", "Else", "While", "Cond", "Invocation", "Print", "Return", YY_NULLPTR
};
#endif
@ -491,14 +496,14 @@ static const yytype_uint16 yytoknum[] =
0, 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
285, 286, 287, 288, 289
};
# endif
#define YYPACT_NINF -47
#define YYPACT_NINF -36
#define yypact_value_is_default(Yystate) \
(!!((Yystate) == (-47)))
(!!((Yystate) == (-36)))
#define YYTABLE_NINF -1
@ -509,18 +514,19 @@ static const yytype_uint16 yytoknum[] =
STATE-NUM. */
static const yytype_int8 yypact[] =
{
-17, -24, 40, 23, -17, 57, -47, 47, -47, -47,
43, 71, 48, 73, 72, 78, -47, 83, 43, -47,
83, 53, -47, 72, -47, -47, 87, -47, 88, 89,
75, 37, 90, 53, -47, 67, 91, -47, -47, -47,
-47, 92, -47, 68, 11, 11, -47, -47, 15, -47,
-47, 93, 95, -47, -47, -47, 94, -47, 15, 15,
98, 11, 54, -5, -47, -2, 101, 85, 67, 99,
100, 4, 44, 36, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 83, 11, 11, 83, -47, 95,
-47, -47, -47, 49, 4, 85, 85, 85, 85, 85,
85, 85, 85, 82, 36, 36, -47, -47, 29, -47,
106, -47, 11, 0, 83, 82, -47
-7, -4, 26, 18, -36, 9, 12, 40, 36, -36,
50, 9, -36, 54, -36, 36, -36, 55, 68, 79,
39, -2, 63, 54, -36, 60, 80, -36, -36, -36,
81, -36, 82, 64, 15, 15, -36, 65, 19, 19,
88, -36, 86, 89, -36, -36, -36, -36, 93, -36,
19, 19, 96, 15, 48, 97, -36, 99, 91, 100,
24, 66, -36, 60, 98, 101, 1, 52, -36, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 15,
15, 102, 103, 78, -36, -36, -36, 89, -36, -36,
-36, 5, 1, 108, -36, 24, 24, 24, 24, 24,
24, -36, -36, 54, 54, 91, -36, 105, 106, -36,
90, -36, -6, -36, 54, 110, 109, 15, -36, 112,
113, 54, 111, 90, -36
};
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
@ -528,34 +534,35 @@ static const yytype_int8 yypact[] =
means the default is an error. */
static const yytype_uint8 yydefact[] =
{
0, 0, 0, 0, 0, 0, 1, 0, 2, 3,
8, 0, 0, 0, 12, 0, 10, 0, 0, 9,
0, 15, 6, 12, 7, 26, 0, 19, 0, 0,
0, 0, 0, 15, 21, 0, 0, 16, 17, 18,
20, 0, 11, 0, 0, 0, 27, 57, 0, 13,
14, 28, 25, 29, 31, 22, 0, 32, 0, 0,
33, 0, 0, 0, 38, 0, 0, 30, 0, 0,
0, 40, 0, 54, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 56, 25,
23, 55, 39, 34, 36, 35, 37, 48, 49, 50,
51, 53, 52, 42, 47, 46, 45, 24, 0, 41,
0, 43, 0, 0, 0, 42, 44
0, 0, 0, 0, 1, 3, 0, 0, 7, 5,
0, 0, 4, 10, 2, 7, 20, 0, 0, 0,
0, 0, 0, 10, 15, 0, 0, 11, 12, 13,
0, 14, 0, 0, 0, 0, 21, 36, 0, 0,
0, 9, 22, 19, 23, 25, 16, 6, 0, 26,
0, 0, 27, 0, 0, 0, 32, 0, 38, 0,
24, 0, 8, 0, 0, 0, 34, 0, 51, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 35, 52, 54, 19, 17, 53,
33, 28, 30, 29, 31, 43, 44, 45, 46, 48,
47, 50, 49, 10, 10, 38, 18, 0, 0, 37,
0, 42, 0, 39, 10, 0, 0, 0, 40, 0,
0, 10, 0, 0, 41
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
-47, -47, 103, -47, -47, -47, 84, 96, -20, 97,
-47, -47, 26, -47, 50, -30, -47, -46, -47, 1,
-47, -44, -47, -18, -47
-36, -36, -36, 114, 115, -36, -22, -36, -36, 41,
-36, 69, -19, -36, -35, -36, 21, -36, 4, -36,
-33, -13, -36, -36
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
-1, 2, 3, 4, 8, 13, 14, 19, 22, 32,
33, 34, 69, 35, 52, 36, 37, 62, 38, 109,
39, 63, 40, 64, 66
-1, 2, 7, 8, 12, 14, 22, 23, 24, 64,
25, 43, 26, 27, 54, 59, 84, 28, 113, 29,
55, 56, 31, 40
};
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
@ -563,78 +570,79 @@ static const yytype_int8 yydefgoto[] =
number is the opposite. If YYTABLE_NINF, syntax error. */
static const yytype_uint8 yytable[] =
{
24, 65, 67, 41, 84, 53, 1, 87, 5, 114,
76, 77, 71, 72, 57, 41, 58, 73, 57, 59,
58, 85, 86, 59, 85, 86, 85, 86, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 53, 21,
6, 104, 105, 60, 61, 47, 7, 60, 74, 75,
76, 77, 48, 92, 75, 76, 77, 110, 74, 75,
76, 77, 85, 86, 103, 10, 12, 106, 113, 11,
78, 79, 80, 81, 82, 83, 25, 26, 27, 15,
16, 28, 17, 29, 30, 31, 18, 20, 111, 74,
75, 76, 77, 21, 115, 43, 44, 45, 46, 51,
56, 49, 23, 70, 54, 55, 47, 9, 48, 68,
88, 108, 90, 91, 112, 107, 116, 0, 89, 42,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50
30, 41, 57, 60, 61, 114, 44, 37, 71, 72,
30, 70, 71, 72, 38, 66, 67, 1, 49, 3,
68, 50, 49, 115, 51, 50, 4, 5, 51, 69,
70, 71, 72, 6, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 44, 9, 101, 102, 52, 53,
10, 11, 52, 69, 70, 71, 72, 69, 70, 71,
72, 13, 90, 36, 33, 73, 74, 75, 76, 77,
78, 69, 70, 71, 72, 79, 80, 34, 16, 17,
86, 107, 108, 18, 119, 19, 20, 21, 35, 39,
30, 30, 116, 42, 45, 46, 47, 48, 58, 122,
62, 30, 38, 65, 63, 37, 83, 81, 30, 82,
85, 105, 88, 103, 104, 89, 72, 110, 111, 117,
112, 118, 120, 123, 121, 15, 109, 124, 106, 0,
32, 0, 87
};
static const yytype_int8 yycheck[] =
{
20, 45, 48, 21, 9, 35, 23, 9, 32, 9,
6, 7, 58, 59, 3, 33, 5, 61, 3, 8,
5, 26, 27, 8, 26, 27, 26, 27, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 68, 10,
0, 85, 86, 32, 33, 8, 23, 32, 4, 5,
6, 7, 15, 9, 5, 6, 7, 28, 4, 5,
6, 7, 26, 27, 84, 8, 23, 87, 112, 22,
16, 17, 18, 19, 20, 21, 23, 24, 25, 8,
32, 28, 9, 30, 31, 32, 14, 9, 108, 4,
5, 6, 7, 10, 114, 8, 8, 8, 23, 32,
32, 11, 18, 9, 13, 13, 8, 4, 15, 14,
9, 29, 13, 13, 8, 89, 115, -1, 68, 23,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
33
13, 23, 35, 38, 39, 11, 25, 9, 7, 8,
23, 6, 7, 8, 16, 50, 51, 24, 3, 23,
53, 6, 3, 29, 9, 6, 0, 9, 9, 5,
6, 7, 8, 24, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 63, 33, 79, 80, 33, 34,
10, 15, 33, 5, 6, 7, 8, 5, 6, 7,
8, 11, 10, 24, 9, 17, 18, 19, 20, 21,
22, 5, 6, 7, 8, 27, 28, 9, 24, 25,
14, 103, 104, 29, 117, 31, 32, 33, 9, 26,
103, 104, 114, 33, 14, 14, 14, 33, 33, 121,
12, 114, 16, 10, 15, 9, 15, 10, 121, 10,
10, 33, 14, 11, 11, 14, 8, 12, 12, 9,
30, 12, 10, 12, 11, 11, 105, 123, 87, -1,
15, -1, 63
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
0, 23, 35, 36, 37, 32, 0, 23, 38, 36,
8, 22, 23, 39, 40, 8, 32, 9, 14, 41,
9, 10, 42, 40, 42, 23, 24, 25, 28, 30,
31, 32, 43, 44, 45, 47, 49, 50, 52, 54,
56, 57, 41, 8, 8, 8, 23, 8, 15, 11,
43, 32, 48, 49, 13, 13, 32, 3, 5, 8,
32, 33, 51, 55, 57, 55, 58, 51, 14, 46,
9, 51, 51, 55, 4, 5, 6, 7, 16, 17,
18, 19, 20, 21, 9, 26, 27, 9, 9, 48,
13, 13, 9, 51, 51, 51, 51, 51, 51, 51,
51, 51, 51, 42, 55, 55, 42, 46, 29, 53,
28, 42, 8, 55, 9, 42, 53
0, 24, 36, 23, 0, 9, 24, 37, 38, 33,
10, 15, 39, 11, 40, 38, 24, 25, 29, 31,
32, 33, 41, 42, 43, 45, 47, 48, 52, 54,
56, 57, 39, 9, 9, 9, 24, 9, 16, 26,
58, 41, 33, 46, 47, 14, 14, 14, 33, 3,
6, 9, 33, 34, 49, 55, 56, 55, 33, 50,
49, 49, 12, 15, 44, 10, 49, 49, 55, 5,
6, 7, 8, 17, 18, 19, 20, 21, 22, 27,
28, 10, 10, 15, 51, 10, 14, 46, 14, 14,
10, 49, 49, 49, 49, 49, 49, 49, 49, 49,
49, 55, 55, 11, 11, 33, 44, 41, 41, 51,
12, 12, 30, 53, 11, 29, 41, 9, 12, 55,
10, 11, 41, 12, 53
};
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
0, 34, 35, 36, 36, 36, 37, 38, 39, 39,
40, 41, 41, 42, 43, 43, 44, 44, 44, 44,
44, 44, 44, 45, 46, 46, 47, 47, 48, 48,
49, 50, 51, 51, 51, 51, 51, 51, 51, 51,
51, 52, 53, 53, 53, 54, 55, 55, 55, 55,
55, 55, 55, 55, 55, 56, 57, 58
0, 35, 36, 37, 37, 38, 39, 39, 40, 41,
41, 42, 42, 42, 42, 42, 42, 43, 44, 44,
45, 45, 46, 46, 47, 48, 49, 49, 49, 49,
49, 49, 49, 49, 49, 50, 50, 51, 51, 52,
53, 53, 54, 55, 55, 55, 55, 55, 55, 55,
55, 55, 56, 57, 58
};
/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
static const yytype_uint8 yyr2[] =
{
0, 2, 2, 2, 1, 0, 6, 5, 0, 2,
2, 3, 0, 3, 2, 0, 1, 1, 1, 1,
1, 1, 2, 4, 3, 0, 1, 2, 1, 1,
3, 2, 1, 1, 3, 3, 3, 3, 1, 3,
2, 6, 0, 2, 7, 5, 3, 3, 3, 3,
3, 3, 3, 3, 2, 5, 4, 0
0, 2, 6, 0, 2, 2, 4, 0, 4, 2,
0, 1, 1, 1, 1, 1, 2, 4, 3, 0,
1, 2, 1, 1, 3, 2, 1, 1, 3, 3,
3, 3, 1, 3, 2, 2, 0, 3, 0, 8,
4, 9, 7, 3, 3, 3, 3, 3, 3, 3,
3, 2, 4, 5, 3
};
@ -1310,8 +1318,206 @@ yyreduce:
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
#line 1315 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
case 2:
#line 63 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Dans main\n");}
#line 1325 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 3:
#line 65 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Sans params\n");}
#line 1331 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 5:
#line 68 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Parametre : %s\n", (yyvsp[0].id));}
#line 1337 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 8:
#line 75 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Dans body\n");}
#line 1343 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 17:
#line 87 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Declaration\n");}
#line 1349 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 20:
#line 92 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("int\n");}
#line 1355 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 21:
#line 93 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("const int\n");}
#line 1361 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 22:
#line 95 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Declaration %s\n", (yyvsp[0].id));}
#line 1367 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 24:
#line 98 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Affectation : %s\n", (yyvsp[-2].id));}
#line 1373 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 26:
#line 102 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("int %d\n", (yyvsp[0].nombre));}
#line 1379 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 27:
#line 103 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("var %s\n", (yyvsp[0].id));}
#line 1385 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 28:
#line 104 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Addition\n");}
#line 1391 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 29:
#line 105 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Multiplication\n");}
#line 1397 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 30:
#line 106 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Soustraction\n");}
#line 1403 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 31:
#line 107 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Division\n");}
#line 1409 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 33:
#line 109 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Parenthèse\n");}
#line 1415 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 34:
#line 110 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Soustraction\n");}
#line 1421 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 39:
#line 118 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Dans if\n");}
#line 1427 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 40:
#line 120 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("else\n");}
#line 1433 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 41:
#line 121 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("elsif\n");}
#line 1439 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 42:
#line 123 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Dans while\n");}
#line 1445 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 43:
#line 125 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Cond ==\n");}
#line 1451 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 44:
#line 126 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Cond !=\n");}
#line 1457 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 45:
#line 127 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Cond <\n");}
#line 1463 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 46:
#line 128 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Cond >\n");}
#line 1469 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 47:
#line 129 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Cond <=\n");}
#line 1475 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 48:
#line 130 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Cond >=\n");}
#line 1481 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 49:
#line 131 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Cond &&\n");}
#line 1487 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 50:
#line 132 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Cond ||\n");}
#line 1493 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 51:
#line 133 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Cond !\n");}
#line 1499 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 52:
#line 135 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("Dans invocation\n");}
#line 1505 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 53:
#line 137 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("printf de %s\n", (yyvsp[-2].id));}
#line 1511 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
case 54:
#line 139 "analyse_syntaxique.y" /* yacc.c:1646 */
{printf("return\n");}
#line 1517 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
break;
#line 1521 "analyse_syntaxique.tab.c" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@ -1539,5 +1745,10 @@ yyreturn:
#endif
return yyresult;
}
#line 107 "analyse_syntaxique.y" /* yacc.c:1906 */
#line 141 "analyse_syntaxique.y" /* yacc.c:1906 */
#include <stdio.h>
void main(void){
yyparse();
}

View file

@ -46,36 +46,37 @@ extern int yydebug;
enum yytokentype
{
tENTIER = 258,
tADD = 259,
tSUB = 260,
tMUL = 261,
tDIV = 262,
tPO = 263,
tPF = 264,
tAO = 265,
tAF = 266,
tERROR = 267,
tPV = 268,
tVIRGULE = 269,
tAFFECTATION = 270,
tEGAL = 271,
tDIFF = 272,
tLT = 273,
tGT = 274,
tGTE = 275,
tLTE = 276,
tMAIN = 277,
tINT = 278,
tPRINT = 279,
tRETURN = 280,
tOR = 281,
tAND = 282,
tIF = 283,
tELSE = 284,
tWHILE = 285,
tCONST = 286,
tVAR = 287,
tNOT = 288
tENTIEREXP = 259,
tADD = 260,
tSUB = 261,
tMUL = 262,
tDIV = 263,
tPO = 264,
tPF = 265,
tAO = 266,
tAF = 267,
tERROR = 268,
tPV = 269,
tVIRGULE = 270,
tAFFECTATION = 271,
tEGAL = 272,
tDIFF = 273,
tLT = 274,
tGT = 275,
tGTE = 276,
tLTE = 277,
tMAIN = 278,
tINT = 279,
tPRINT = 280,
tRETURN = 281,
tOR = 282,
tAND = 283,
tIF = 284,
tELSE = 285,
tWHILE = 286,
tCONST = 287,
tVAR = 288,
tNOT = 289
};
#endif
@ -87,8 +88,9 @@ union YYSTYPE
#line 1 "analyse_syntaxique.y" /* yacc.c:1909 */
int nombre;
char id[30];
#line 92 "analyse_syntaxique.tab.h" /* yacc.c:1909 */
#line 94 "analyse_syntaxique.tab.h" /* yacc.c:1909 */
};
typedef union YYSTYPE YYSTYPE;

View file

@ -1,8 +1,16 @@
%union {
int nombre;
char id[30];
}
%{
#include <stdio.h>
%}
%token<nombre> tENTIER
%token<nombre> tENTIEREXP
%token tADD
%token tSUB
%token tMUL
@ -34,74 +42,105 @@ int nombre;
%token tELSE
%token tWHILE
%token tCONST
%token tVAR
%token<id> tVAR
%token tNOT
%left tADD
%left tSUB
%left tMUL
%left tDIV
%right tEGAL
%type<nombre> E
%%
C : Fonctions Main ;
Fonctions : Fonction Fonctions | Fonction | ;
//C : Fonctions Main ;
Fonction : tINT tVAR tPO Params tPF Body ;
Main : tINT tMAIN tPO tPF Body ;
Params : | Param SuiteParams ;
Param : tINT tVAR ;
//Fonctions : Fonction Fonctions | ;
//Fonction : tINT tVAR tPO Params tPF Body;
// Ps : P Ps | ;
// P : tINT tID ttVIRGULE
// Ps =>* tINT tID ttVIRGULE tINT tID ttVIRGULE
// Ps => P Ps => P P Ps ...
Main : tINT tMAIN tPO Params tPF Body {printf("Dans main\n");};
SuiteParams : tVIRGULE Param SuiteParams | ;
Params : {printf("Sans params\n");} ;
Params : Param SuiteParams ;
Body : tAO Instructions tAF ;
Param : tINT tVAR {printf("Parametre : %s\n", $2);} ;
Instructions : Instruction Instructions | ;
Instruction : Aff | If | While | tRETURN | Print | Decl | Invocation tPV ;
SuiteParams : tVIRGULE Param SuiteParams tPV ;
SuiteParams : ;
Decl : Type Valeur SuiteDecl tPV;
SuiteDecl: tVIRGULE Valeur SuiteDecl | ;
Body : tAO Instructions Return tAF {printf("Dans body\n");} ;
Type : tINT | tCONST tINT ;
Instructions : Instruction Instructions ;
Instructions : ;
Valeur : tVAR | Affbis ;
Instruction : Aff ;
Instruction : If ;
Instruction : While ;
Instruction : Print ;
Instruction : Decl ;
Instruction : Invocation tPV ;
Affbis : tVAR tAFFECTATION E;
Decl : Type Valeur SuiteDecl tPV {printf("Declaration\n");} ;
SuiteDecl: tVIRGULE Valeur SuiteDecl ;
SuiteDecl: ;
Type : tINT {printf("int\n");} ;
Type : tCONST tINT {printf("const int\n");} ;
Valeur : tVAR {printf("Declaration %s\n", $1);};
Valeur : Affbis ;
Affbis : tVAR tAFFECTATION E {printf("Affectation : %s\n", $1);};
Aff : Affbis tPV ;
E : tENTIER | tVAR | E tADD E | E tMUL E | E tSUB E | E tDIV E | Invocation | tPO E tPF | tSUB E ;
E : tENTIER {printf("int %d\n", $1);};
E : tVAR {printf("var %s\n", $1);};
E : E tADD E {printf("Addition\n");} ;
E : E tMUL E {printf("Multiplication\n");} ;
E : E tSUB E {printf("Soustraction\n");} ;
E : E tDIV E {printf("Division\n");} ;
E : Invocation ;
E : tPO E tPF {printf("Parenthèse\n");} ;
E : tSUB E {printf("Soustraction\n");} ;
// E : tID tPlus tID | ...
Args : tVAR SuiteArgs ;
Args : ;
If : tIF tPO Cond tPF Body Else;
SuiteArgs : tVIRGULE tVAR SuiteArgs ;
SuiteArgs : ;
Else : | tELSE Body |tELSE tIF tPO Cond tPF Body Else;
If : tIF tPO Cond tPF tAO Instructions tAF Else {printf("Dans if\n");};
While : tWHILE tPO Cond tPF Body ;
Else : tELSE tAO Instructions tAF {printf("else\n");} ;
Else : tELSE tIF tPO Cond tPF tAO Instructions tAF Else {printf("elsif\n");} ;
Cond : Cond tAND Cond | Cond tOR Cond | E tEGAL E | E tDIFF E | E tLT E | E tGT E | E tLTE E | E tGTE E| tNOT Cond ;
While : tWHILE tPO Cond tPF tAO Instructions tAF {printf("Dans while\n");};
Print : tPRINT tPO tVAR tPF tPV ;
Cond : E tEGAL E {printf("Cond ==\n");} ;
Cond : E tDIFF E {printf("Cond !=\n");} ;
Cond : E tLT E {printf("Cond <\n");} ;
Cond : E tGT E {printf("Cond >\n");} ;
Cond : E tLTE E {printf("Cond <=\n");} ;
Cond : E tGTE E{printf("Cond >=\n");} ;
Cond : E tAND Cond {printf("Cond &&\n");} ;
Cond : E tOR Cond {printf("Cond ||\n");} ;
Cond : tNOT Cond {printf("Cond !\n");} ;
Invocation : tVAR tPO Args tPF ;
Invocation : tVAR tPO Args tPF {printf("Dans invocation\n");};
Args : | Arg SuiteArgs ;
Print : tPRINT tPO tVAR tPF tPV {printf("printf de %s\n", $3);};
Arg : tVAR ;
SuiteArgs : tVIRGULE Arg SuiteArgs ;
RETURN : tRETURN E tPV ;
Return : tRETURN E tPV {printf("return\n");};
%%
#include <stdio.h>
void main(void){
yyparse();
}

192
lex.yy.c
View file

@ -351,8 +351,8 @@ static void yynoreturn yy_fatal_error ( const char* msg );
(yy_hold_char) = *yy_cp; \
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 33
#define YY_END_OF_BUFFER 34
#define YY_NUM_RULES 34
#define YY_END_OF_BUFFER 35
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@ -362,13 +362,13 @@ struct yy_trans_info
};
static const flex_int16_t yy_accept[70] =
{ 0,
0, 0, 34, 33, 10, 11, 20, 33, 5, 6,
0, 0, 35, 34, 10, 11, 20, 34, 5, 6,
3, 1, 12, 2, 4, 31, 9, 16, 13, 17,
32, 32, 32, 32, 32, 32, 32, 32, 7, 33,
8, 15, 26, 31, 32, 0, 18, 14, 19, 32,
32, 27, 32, 32, 32, 32, 32, 25, 31, 32,
32, 22, 32, 32, 32, 32, 32, 28, 21, 32,
32, 32, 30, 32, 32, 29, 23, 24, 0
33, 33, 33, 33, 33, 33, 33, 33, 7, 34,
8, 15, 26, 31, 33, 33, 18, 14, 19, 33,
33, 27, 33, 33, 33, 33, 33, 25, 32, 33,
33, 22, 33, 33, 33, 33, 33, 28, 21, 33,
33, 33, 30, 33, 33, 29, 23, 24, 0
} ;
static const YY_CHAR yy_ec[256] =
@ -382,11 +382,11 @@ static const YY_CHAR yy_ec[256] =
17, 18, 1, 1, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
1, 1, 1, 20, 19, 1, 21, 19, 22, 19,
1, 1, 1, 1, 19, 1, 20, 19, 21, 19,
23, 24, 19, 25, 26, 19, 19, 27, 28, 29,
30, 31, 19, 32, 33, 34, 35, 19, 36, 19,
19, 19, 37, 38, 39, 1, 1, 1, 1, 1,
22, 23, 19, 24, 25, 19, 19, 26, 27, 28,
29, 30, 19, 31, 32, 33, 34, 19, 35, 19,
19, 19, 36, 37, 38, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -403,23 +403,23 @@ static const YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1
} ;
static const YY_CHAR yy_meta[40] =
static const YY_CHAR yy_meta[39] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 1, 1, 1, 1, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 1, 1
2, 2, 2, 2, 2, 1, 1, 1
} ;
static const flex_int16_t yy_base[71] =
{ 0,
0, 0, 116, 117, 117, 117, 98, 108, 117, 117,
117, 117, 117, 117, 117, 26, 117, 96, 95, 94,
90, 21, 22, 23, 24, 28, 30, 34, 117, 71,
117, 117, 117, 41, 88, 93, 117, 117, 117, 36,
37, 86, 38, 42, 43, 44, 47, 117, 91, 46,
51, 84, 55, 56, 57, 60, 61, 83, 82, 62,
66, 68, 81, 69, 70, 80, 77, 74, 117, 81
0, 0, 79, 80, 80, 80, 61, 71, 80, 80,
80, 80, 80, 80, 80, 25, 80, 59, 58, 57,
0, 44, 46, 17, 51, 39, 47, 44, 80, 30,
80, 80, 80, 27, 0, 52, 80, 80, 80, 37,
32, 0, 30, 37, 36, 27, 34, 80, 44, 25,
34, 0, 27, 26, 19, 26, 18, 0, 0, 17,
17, 24, 0, 21, 15, 0, 0, 0, 80, 40
} ;
static const flex_int16_t yy_def[71] =
@ -427,52 +427,44 @@ static const flex_int16_t yy_def[71] =
69, 1, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 70, 69, 69, 69, 69,
70, 70, 70, 70, 70, 70, 70, 70, 69, 69,
69, 69, 69, 70, 70, 69, 69, 69, 69, 70,
70, 70, 70, 70, 70, 70, 70, 69, 69, 70,
69, 69, 69, 70, 70, 70, 69, 69, 69, 70,
70, 70, 70, 70, 70, 70, 70, 69, 70, 70,
70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
70, 70, 70, 70, 70, 70, 70, 70, 0, 69
} ;
static const flex_int16_t yy_nxt[157] =
static const flex_int16_t yy_nxt[119] =
{ 0,
4, 5, 6, 5, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 4,
21, 22, 23, 21, 21, 24, 21, 25, 21, 21,
26, 27, 21, 21, 21, 28, 29, 30, 31, 34,
69, 69, 69, 69, 44, 36, 42, 69, 41, 69,
40, 43, 46, 69, 34, 69, 69, 69, 47, 45,
36, 69, 69, 69, 50, 69, 69, 53, 54, 51,
69, 52, 56, 58, 69, 69, 69, 55, 57, 69,
69, 69, 35, 59, 60, 69, 62, 69, 69, 69,
66, 61, 67, 69, 63, 64, 69, 65, 68, 69,
13, 14, 15, 16, 17, 18, 19, 20, 21, 21,
22, 23, 21, 21, 24, 21, 25, 21, 21, 26,
27, 21, 21, 21, 28, 29, 30, 31, 34, 42,
34, 35, 68, 67, 43, 66, 36, 65, 36, 64,
63, 62, 61, 60, 59, 58, 57, 49, 56, 55,
54, 53, 52, 51, 50, 49, 48, 47, 46, 45,
44, 41, 40, 39, 38, 37, 33, 32, 69, 3,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 49, 69, 49, 69, 48, 69,
39, 38, 37, 33, 32, 69, 3, 69, 69, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69
69, 69, 69, 69, 69, 69, 69, 69
} ;
static const flex_int16_t yy_chk[157] =
static const flex_int16_t yy_chk[119] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 16,
22, 23, 24, 25, 25, 16, 24, 26, 23, 27,
22, 24, 27, 28, 34, 40, 41, 43, 28, 26,
34, 44, 45, 46, 40, 50, 47, 44, 45, 41,
51, 43, 47, 51, 53, 54, 55, 46, 50, 56,
57, 60, 70, 53, 54, 61, 56, 62, 64, 65,
62, 55, 64, 68, 57, 60, 67, 61, 65, 66,
1, 1, 1, 1, 1, 1, 1, 1, 16, 24,
34, 70, 65, 64, 24, 62, 16, 61, 34, 60,
57, 56, 55, 54, 53, 51, 50, 49, 47, 46,
45, 44, 43, 41, 40, 36, 30, 28, 27, 26,
25, 23, 22, 20, 19, 18, 8, 7, 3, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
63, 59, 58, 52, 49, 42, 36, 35, 30, 21,
20, 19, 18, 8, 7, 3, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69
69, 69, 69, 69, 69, 69, 69, 69
} ;
static yy_state_type yy_last_accepting_state;
@ -490,7 +482,14 @@ int yy_flex_debug = 0;
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "analyse_lexicale.lex"
#line 494 "lex.yy.c"
#line 2 "analyse_lexicale.lex"
#include "analyse_syntaxique.tab.h"
int yywrap(void){
return 1;
}
#line 492 "lex.yy.c"
#line 493 "lex.yy.c"
#define INITIAL 0
@ -707,10 +706,10 @@ YY_DECL
}
{
#line 41 "analyse_lexicale.lex"
#line 53 "analyse_lexicale.lex"
#line 714 "lex.yy.c"
#line 713 "lex.yy.c"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
@ -743,7 +742,7 @@ yy_match:
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 117 );
while ( yy_base[yy_current_state] != 80 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@ -769,171 +768,176 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 43 "analyse_lexicale.lex"
#line 55 "analyse_lexicale.lex"
{return tADD ;}
YY_BREAK
case 2:
YY_RULE_SETUP
#line 44 "analyse_lexicale.lex"
#line 56 "analyse_lexicale.lex"
{return tSUB ;}
YY_BREAK
case 3:
YY_RULE_SETUP
#line 45 "analyse_lexicale.lex"
#line 57 "analyse_lexicale.lex"
{return tMUL ;}
YY_BREAK
case 4:
YY_RULE_SETUP
#line 46 "analyse_lexicale.lex"
#line 58 "analyse_lexicale.lex"
{return tDIV ;}
YY_BREAK
case 5:
YY_RULE_SETUP
#line 48 "analyse_lexicale.lex"
#line 60 "analyse_lexicale.lex"
{return tPO ;}
YY_BREAK
case 6:
YY_RULE_SETUP
#line 49 "analyse_lexicale.lex"
#line 61 "analyse_lexicale.lex"
{return tPF ;}
YY_BREAK
case 7:
YY_RULE_SETUP
#line 50 "analyse_lexicale.lex"
#line 62 "analyse_lexicale.lex"
{return tAO ;}
YY_BREAK
case 8:
YY_RULE_SETUP
#line 51 "analyse_lexicale.lex"
#line 63 "analyse_lexicale.lex"
{return tAF ;}
YY_BREAK
case 9:
YY_RULE_SETUP
#line 53 "analyse_lexicale.lex"
#line 65 "analyse_lexicale.lex"
{return tPV ;}
YY_BREAK
case 10:
YY_RULE_SETUP
#line 54 "analyse_lexicale.lex"
#line 66 "analyse_lexicale.lex"
{}
YY_BREAK
case 11:
/* rule 11 can match eol */
YY_RULE_SETUP
#line 55 "analyse_lexicale.lex"
#line 67 "analyse_lexicale.lex"
{}
YY_BREAK
case 12:
YY_RULE_SETUP
#line 56 "analyse_lexicale.lex"
#line 68 "analyse_lexicale.lex"
{return tVIRGULE ;}
YY_BREAK
case 13:
YY_RULE_SETUP
#line 58 "analyse_lexicale.lex"
#line 70 "analyse_lexicale.lex"
{return tAFFECTATION ;}
YY_BREAK
case 14:
YY_RULE_SETUP
#line 60 "analyse_lexicale.lex"
#line 72 "analyse_lexicale.lex"
{return tEGAL ;}
YY_BREAK
case 15:
YY_RULE_SETUP
#line 61 "analyse_lexicale.lex"
#line 73 "analyse_lexicale.lex"
{return tDIFF ;}
YY_BREAK
case 16:
YY_RULE_SETUP
#line 62 "analyse_lexicale.lex"
#line 74 "analyse_lexicale.lex"
{return tLT ;}
YY_BREAK
case 17:
YY_RULE_SETUP
#line 63 "analyse_lexicale.lex"
#line 75 "analyse_lexicale.lex"
{return tGT ;}
YY_BREAK
case 18:
YY_RULE_SETUP
#line 64 "analyse_lexicale.lex"
#line 76 "analyse_lexicale.lex"
{return tLTE ;}
YY_BREAK
case 19:
YY_RULE_SETUP
#line 65 "analyse_lexicale.lex"
#line 77 "analyse_lexicale.lex"
{return tGTE ;}
YY_BREAK
case 20:
YY_RULE_SETUP
#line 66 "analyse_lexicale.lex"
#line 78 "analyse_lexicale.lex"
{return tNOT ;}
YY_BREAK
case 21:
YY_RULE_SETUP
#line 69 "analyse_lexicale.lex"
#line 81 "analyse_lexicale.lex"
{return tMAIN ;}
YY_BREAK
case 22:
YY_RULE_SETUP
#line 70 "analyse_lexicale.lex"
#line 82 "analyse_lexicale.lex"
{return tINT ;}
YY_BREAK
case 23:
YY_RULE_SETUP
#line 71 "analyse_lexicale.lex"
#line 83 "analyse_lexicale.lex"
{return tPRINT ;}
YY_BREAK
case 24:
YY_RULE_SETUP
#line 72 "analyse_lexicale.lex"
#line 84 "analyse_lexicale.lex"
{return tRETURN ;}
YY_BREAK
case 25:
YY_RULE_SETUP
#line 74 "analyse_lexicale.lex"
#line 86 "analyse_lexicale.lex"
{return tOR ;}
YY_BREAK
case 26:
YY_RULE_SETUP
#line 75 "analyse_lexicale.lex"
#line 87 "analyse_lexicale.lex"
{return tAND ;}
YY_BREAK
case 27:
YY_RULE_SETUP
#line 77 "analyse_lexicale.lex"
#line 89 "analyse_lexicale.lex"
{return tIF ;}
YY_BREAK
case 28:
YY_RULE_SETUP
#line 78 "analyse_lexicale.lex"
#line 90 "analyse_lexicale.lex"
{return tELSE ;}
YY_BREAK
case 29:
YY_RULE_SETUP
#line 79 "analyse_lexicale.lex"
#line 91 "analyse_lexicale.lex"
{return tWHILE ;}
YY_BREAK
case 30:
YY_RULE_SETUP
#line 81 "analyse_lexicale.lex"
#line 93 "analyse_lexicale.lex"
{return tCONST ;}
YY_BREAK
case 31:
YY_RULE_SETUP
#line 82 "analyse_lexicale.lex"
{return tENTIER ;}
#line 94 "analyse_lexicale.lex"
{yylval.nombre = atoi(yytext); return tENTIER ;}
YY_BREAK
case 32:
YY_RULE_SETUP
#line 83 "analyse_lexicale.lex"
{return tVAR ;}
#line 95 "analyse_lexicale.lex"
{yylval.nombre = -1; return tENTIEREXP;}
YY_BREAK
case 33:
YY_RULE_SETUP
#line 85 "analyse_lexicale.lex"
#line 96 "analyse_lexicale.lex"
{strcpy(yylval.id, yytext); return tVAR ;}
YY_BREAK
case 34:
YY_RULE_SETUP
#line 98 "analyse_lexicale.lex"
ECHO;
YY_BREAK
#line 937 "lex.yy.c"
#line 941 "lex.yy.c"
case YY_STATE_EOF(INITIAL):
yyterminate();
@ -1938,11 +1942,9 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
#line 85 "analyse_lexicale.lex"
#line 98 "analyse_lexicale.lex"
int yywrap(void){
return 1;
}
//int main(void){
// yylex();
//}

64
poubelle/as.y Normal file
View file

@ -0,0 +1,64 @@
%union {
int nombre;
}
%token tENTIER
%token tADD
%token tSUB
%token tMUL
%token tDIV
%token tPO
%token tPF
%token tAO
%token tAF
%token tERROR
%token tPV
%token tVIRGULE
%token tAFFECTATION
%token tEGAL
%token tDIFF
%token tLT
%token tGT
%token tGTE
%token tLTE
%token tMAIN
%token tINT
%token tPRINT
%token tRETURN
%token tOR
%token tAND
%token tIF
%token tELSE
%token tWHILE
%token tCONST
%token tVAR
%token tNOT
%left tADD
%left tSUB
%left tMUL
%left tDIV
%right tEGAL
%%
Prog : tINT tMAIN tPO tPF Body {printf("Dans main\n");};
Body : tAO Instructions Return tAF ;
Instructions : Instruction Instructions | ;
Instruction : Print ;
Type : tINT | tCONST tINT ;
Valeur : tVAR | Affbis ;
Affbis : tVAR tAFFECTATION E;
Aff : Affbis tPV ;

1956
poubelle/lex.yy.c Normal file

File diff suppressed because it is too large Load diff

View file

1474
poubelle/y.output Normal file

File diff suppressed because it is too large Load diff

1705
poubelle/y.tab.c Normal file

File diff suppressed because it is too large Load diff

137
poubelle/y.tab.h Normal file
View file

@ -0,0 +1,137 @@
/* A Bison parser, made by GNU Bison 3.0.4. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_YY_Y_TAB_H_INCLUDED
# define YY_YY_Y_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
tENTIER = 258,
tADD = 259,
tSUB = 260,
tMUL = 261,
tDIV = 262,
tPO = 263,
tPF = 264,
tAO = 265,
tAF = 266,
tERROR = 267,
tPV = 268,
tVIRGULE = 269,
tAFFECTATION = 270,
tEGAL = 271,
tDIFF = 272,
tLT = 273,
tGT = 274,
tGTE = 275,
tLTE = 276,
tMAIN = 277,
tINT = 278,
tPRINT = 279,
tRETURN = 280,
tOR = 281,
tAND = 282,
tIF = 283,
tELSE = 284,
tWHILE = 285,
tCONST = 286,
tVAR = 287,
tNOT = 288
};
#endif
/* Tokens. */
#define tENTIER 258
#define tADD 259
#define tSUB 260
#define tMUL 261
#define tDIV 262
#define tPO 263
#define tPF 264
#define tAO 265
#define tAF 266
#define tERROR 267
#define tPV 268
#define tVIRGULE 269
#define tAFFECTATION 270
#define tEGAL 271
#define tDIFF 272
#define tLT 273
#define tGT 274
#define tGTE 275
#define tLTE 276
#define tMAIN 277
#define tINT 278
#define tPRINT 279
#define tRETURN 280
#define tOR 281
#define tAND 282
#define tIF 283
#define tELSE 284
#define tWHILE 285
#define tCONST 286
#define tVAR 287
#define tNOT 288
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 1 "analyse_syntaxique.y" /* yacc.c:1909 */
int nombre;
char id[30];
#line 125 "y.tab.h" /* yacc.c:1909 */
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_Y_TAB_H_INCLUDED */

View file

@ -1,31 +1,14 @@
bison -d -t analyse_syntaxique.y -v
flex analyse_lexicale.lex
gcc *.c -ly
gcc -w *.c -ly
echo "
int fonction1(int toto){
toto = toto + 1 ;
return toto;
}
int fonction2(){
int i = 0;
while (i <= 2){
printf(i);
i = i +1 ;
}
return i;
}
int main(){
const int toto = 1, mimi, lolo = 6;
int tata = 5, lala;
if (tata == 5){
fonction1(lolo);
} else if (toto == 1){
fonction2();
}
while (tata == 5){
printf(tata);
lala = lolo + 6;
}
return 1;
}
" | ./a.out