This commit is contained in:
Foussats Morgane 2021-03-18 12:18:42 +01:00
parent 1fde03c4c1
commit 1214af43d7
11 changed files with 3529 additions and 198 deletions

BIN
Lex/a.out

Binary file not shown.

View file

@ -1,80 +0,0 @@
ADD "+"
SUB "-"
MUL "*"
DIV "/"
tPO "("
tPF ")"
tAO "{"
tAF "}"
EOL "\n"
EOI ";"
SPACE " "
TAB "\t"
VIRGULE ","
EGAL "="
LT "<"
GT ">"
tINT "int"
tMAIN "main"
tPRINT "printf"
tRETURN "return"
tIF "if"
tELSE "else"
tWHILE "while"
tNOT "!"
tAND "&&"
tOR "||"
DIGIT [0-9]
VARIABLE [A-Za-z0-9_]+
DECIMAL {DIGIT}+
EXPONENTIEL {DIGIT}+"^"{DIGIT}+
ENTIER {DECIMAL}|{EXPONENTIEL}
OPERATION {ADD}|{SUB}|{MUL}|{DIV}
COMPARATEUR {EGAL}|{LT}|{GT}
SEPARATOR {SPACE}|{TAB}
%%
{ADD} {printf("tADD ");}
{SUB} {printf("tSUB ");}
{MUL} {printf("tMUL ");}
{DIV} {printf("tDIV ");}
{tPO} {printf("tPO ");}
{tPF} {printf("tPF ");}
{tAO} {printf("tAO ");}
{tAF} {printf("tAF ");}
{EOI} {printf("tPV ");}
{SEPARATOR} {}
{EOL} {}
{VIRGULE} {printf("tVIRGULE ");}
{EGAL} {printf("tEGAL ");}
{LT} {printf("tLT ");}
{GT} {printf("tGT ");}
{tMAIN} {printf("tMAIN ");}
{tINT} {printf("tINT ");}
{tPRINT} {printf("tPRINT ");}
{tRETURN} {printf("tRETURN ");}
{tOR} {printf("tOR ");}
{tAND} {printf("tAND ");}
{tIF} {printf("tIF ");}
{tELSE} {printf("tELSE ");}
{tWHILE} {printf("tWHILE ");}
{ENTIER} {printf("tENTIER ");}
{VARIABLE} {printf("tVAR ");}
%%
int yywrap(void){
return 1;
}
int main(void){
yylex();
}

93
analyse_lexicale.lex Normal file
View file

@ -0,0 +1,93 @@
ADD "+"
SUB "-"
MUL "*"
DIV "/"
tPO "("
tPF ")"
tAO "{"
tAF "}"
EOL "\n"
EOI ";"
SPACE " "
TAB "\t"
VIRGULE ","
AFFECTATION "="
EQUAL "=="
LT "<"
GT ">"
LTE "<="
GTE ">="
tINT "int"
tMAIN "main"
tPRINT "printf"
tRETURN "return"
tIF "if"
tELSE "else"
tWHILE "while"
tNOT "!"
tAND "&&"
tOR "||"
tDIFF "!="
DIGIT [0-9]
VARIABLE [A-Za-z0-9_]+
CONST "const"
DECIMAL {DIGIT}+
EXPONENTIEL {DIGIT}+"^"{DIGIT}+
ENTIER {DECIMAL}|{EXPONENTIEL}
OPERATION {ADD}|{SUB}|{MUL}|{DIV}
COMPARATEUR {EGAL}|{LT}|{GT}
SEPARATOR {SPACE}|{TAB}
%%
{ADD} {return tADD ;}
{SUB} {return tSUB ;}
{MUL} {return tMUL ;}
{DIV} {return tDIV ;}
{tPO} {return tPO ;}
{tPF} {return tPF ;}
{tAO} {return tAO ;}
{tAF} {return tAF ;}
{EOI} {return tPV ;}
{SEPARATOR} {}
{EOL} {}
{VIRGULE} {return tVIRGULE ;}
{AFFECTATION} {return tAFFECTATION ;}
{EQUAL} {return tEGAL ;}
{tDIFF} {return tDIFF ;}
{LT} {return tLT ;}
{GT} {return tGT ;}
{LTE} {return tLTE ;}
{GTE} {return tGTE ;}
{tNOT} {return tNOT ;}
{tMAIN} {return tMAIN ;}
{tINT} {return tINT ;}
{tPRINT} {return tPRINT ;}
{tRETURN} {return tRETURN ;}
{tOR} {return tOR ;}
{tAND} {return tAND ;}
{tIF} {return tIF ;}
{tELSE} {return tELSE ;}
{tWHILE} {return tWHILE ;}
{CONST} {return tCONST ;}
{ENTIER} {return tENTIER ;}
{VARIABLE} {return tVAR ;}
%%
int yywrap(void){
return 1;
}
//int main(void){
// yylex();
//}

1452
analyse_syntaxique.output Normal file

File diff suppressed because it is too large Load diff

1543
analyse_syntaxique.tab.c Normal file

File diff suppressed because it is too large Load diff

104
analyse_syntaxique.tab.h Normal file
View file

@ -0,0 +1,104 @@
/* 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_ANALYSE_SYNTAXIQUE_TAB_H_INCLUDED
# define YY_YY_ANALYSE_SYNTAXIQUE_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
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 1 "analyse_syntaxique.y" /* yacc.c:1909 */
int nombre;
#line 92 "analyse_syntaxique.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_ANALYSE_SYNTAXIQUE_TAB_H_INCLUDED */

107
analyse_syntaxique.y Normal file
View file

@ -0,0 +1,107 @@
%union {
int nombre;
}
%token<nombre> 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
%right tEGAL
%type<nombre> E
%%
C : Fonctions Main ;
Fonctions : Fonction Fonctions | Fonction | ;
Fonction : tINT tVAR tPO Params tPF Body ;
Main : tINT tMAIN tPO tPF Body ;
Params : | Param SuiteParams ;
Param : tINT tVAR ;
// Ps : P Ps | ;
// P : tINT tID ttVIRGULE
// Ps =>* tINT tID ttVIRGULE tINT tID ttVIRGULE
// Ps => P Ps => P P Ps ...
SuiteParams : tVIRGULE Param SuiteParams | ;
Body : tAO Instructions tAF ;
Instructions : Instruction Instructions | ;
Instruction : Aff | If | While | tRETURN | Print | Decl | Invocation tPV ;
Decl : Type Valeur SuiteDecl tPV;
SuiteDecl: tVIRGULE Valeur SuiteDecl | ;
Type : tINT | tCONST tINT ;
Valeur : tVAR | Affbis ;
Affbis : tVAR tAFFECTATION E;
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 : tID tPlus tID | ...
If : tIF tPO Cond tPF Body Else;
Else : | tELSE Body |tELSE tIF tPO Cond tPF Body Else;
While : tWHILE tPO Cond tPF Body ;
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 ;
Print : tPRINT tPO tVAR tPF tPV ;
Invocation : tVAR tPO Args tPF ;
Args : | Arg SuiteArgs ;
Arg : tVAR ;
SuiteArgs : tVIRGULE Arg SuiteArgs ;
RETURN : tRETURN E tPV ;
%%

View file

@ -351,8 +351,8 @@ static void yynoreturn yy_fatal_error ( const char* msg );
(yy_hold_char) = *yy_cp; \ (yy_hold_char) = *yy_cp; \
*yy_cp = '\0'; \ *yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp; (yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 25 #define YY_NUM_RULES 33
#define YY_END_OF_BUFFER 26 #define YY_END_OF_BUFFER 34
/* This struct is not used in this scanner, /* This struct is not used in this scanner,
but its presence is necessary. */ but its presence is necessary. */
struct yy_trans_info struct yy_trans_info
@ -360,13 +360,15 @@ struct yy_trans_info
flex_int32_t yy_verify; flex_int32_t yy_verify;
flex_int32_t yy_nxt; flex_int32_t yy_nxt;
}; };
static const flex_int16_t yy_accept[49] = static const flex_int16_t yy_accept[70] =
{ 0, { 0,
0, 0, 26, 25, 23, 24, 25, 5, 6, 3, 0, 0, 34, 33, 10, 11, 20, 33, 5, 6,
1, 10, 2, 4, 12, 9, 13, 11, 14, 22, 3, 1, 12, 2, 4, 31, 9, 16, 13, 17,
22, 22, 22, 22, 7, 25, 8, 19, 12, 22, 32, 32, 32, 32, 32, 32, 32, 32, 7, 33,
0, 22, 20, 22, 22, 22, 18, 12, 22, 16, 8, 15, 26, 31, 32, 0, 18, 14, 19, 32,
22, 22, 21, 15, 22, 22, 17, 0 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
} ; } ;
static const YY_CHAR yy_ec[256] = static const YY_CHAR yy_ec[256] =
@ -374,17 +376,17 @@ static const YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
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, 1,
1, 4, 1, 1, 1, 1, 1, 5, 1, 6, 1, 4, 5, 1, 1, 1, 1, 6, 1, 7,
7, 8, 9, 10, 11, 1, 12, 13, 13, 13, 8, 9, 10, 11, 12, 1, 13, 14, 14, 14,
13, 13, 13, 13, 13, 13, 13, 1, 14, 15, 14, 14, 14, 14, 14, 14, 14, 1, 15, 16,
16, 17, 1, 1, 18, 18, 18, 18, 18, 18, 17, 18, 1, 1, 19, 19, 19, 19, 19, 19,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
1, 1, 1, 19, 18, 1, 20, 18, 18, 18, 1, 1, 1, 20, 19, 1, 21, 19, 22, 19,
21, 22, 18, 18, 23, 18, 18, 24, 25, 26, 23, 24, 19, 25, 26, 19, 19, 27, 28, 29,
18, 27, 18, 28, 29, 30, 18, 18, 18, 18, 30, 31, 19, 32, 33, 34, 35, 19, 36, 19,
18, 18, 31, 32, 33, 1, 1, 1, 1, 1, 19, 19, 37, 38, 39, 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, 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,
@ -401,64 +403,76 @@ static const YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1 1, 1, 1, 1, 1
} ; } ;
static const YY_CHAR yy_meta[34] = static const YY_CHAR yy_meta[40] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 1, 1, 1, 1, 2, 2, 2, 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, 2, 2, 2, 2,
1, 1, 1 2, 2, 2, 2, 2, 2, 1, 1, 1
} ; } ;
static const flex_int16_t yy_base[50] = static const flex_int16_t yy_base[71] =
{ 0, { 0,
0, 0, 77, 78, 78, 78, 71, 78, 78, 78, 0, 0, 116, 117, 117, 117, 98, 108, 117, 117,
78, 78, 78, 78, 21, 78, 78, 78, 78, 56, 117, 117, 117, 117, 117, 26, 117, 96, 95, 94,
17, 16, 24, 18, 78, 42, 78, 78, 26, 54, 90, 21, 22, 23, 24, 28, 30, 34, 117, 71,
59, 28, 52, 29, 30, 31, 78, 57, 37, 50, 117, 117, 117, 41, 88, 93, 117, 117, 117, 36,
36, 41, 49, 47, 33, 42, 46, 78, 49 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
} ; } ;
static const flex_int16_t yy_def[50] = static const flex_int16_t yy_def[71] =
{ 0, { 0,
48, 1, 48, 48, 48, 48, 48, 48, 48, 48, 69, 1, 69, 69, 69, 69, 69, 69, 69, 69,
48, 48, 48, 48, 49, 48, 48, 48, 48, 49, 69, 69, 69, 69, 69, 70, 69, 69, 69, 69,
49, 49, 49, 49, 48, 48, 48, 48, 49, 49, 70, 70, 70, 70, 70, 70, 70, 70, 69, 69,
48, 49, 49, 49, 49, 49, 48, 48, 49, 49, 69, 69, 69, 70, 70, 69, 69, 69, 69, 70,
49, 49, 49, 49, 49, 49, 49, 0, 48 70, 70, 70, 70, 70, 70, 70, 69, 69, 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[112] = static const flex_int16_t yy_nxt[157] =
{ 0, { 0,
4, 5, 6, 5, 7, 8, 9, 10, 11, 12, 4, 5, 6, 5, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 4, 20, 13, 14, 15, 16, 17, 18, 19, 20, 21, 4,
21, 20, 22, 20, 23, 20, 24, 20, 20, 20, 21, 22, 23, 21, 21, 24, 21, 25, 21, 21,
25, 26, 27, 29, 48, 48, 48, 33, 29, 31, 26, 27, 21, 21, 21, 28, 29, 30, 31, 34,
32, 34, 48, 35, 31, 36, 48, 48, 48, 48, 69, 69, 69, 69, 44, 36, 42, 69, 41, 69,
30, 48, 41, 42, 48, 48, 39, 43, 40, 48, 40, 43, 46, 69, 34, 69, 69, 69, 47, 45,
48, 44, 46, 47, 48, 48, 45, 48, 48, 38, 36, 69, 69, 69, 50, 69, 69, 53, 54, 51,
48, 38, 48, 37, 48, 28, 48, 3, 48, 48, 69, 52, 56, 58, 69, 69, 69, 55, 57, 69,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 69, 69, 35, 59, 60, 69, 62, 69, 69, 69,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 66, 61, 67, 69, 63, 64, 69, 65, 68, 69,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 69, 69, 69, 69, 49, 69, 49, 69, 48, 69,
48 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
} ; } ;
static const flex_int16_t yy_chk[112] = static const flex_int16_t yy_chk[157] =
{ 0, { 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, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 15, 22, 21, 24, 22, 29, 15, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16,
21, 22, 23, 23, 29, 24, 32, 34, 35, 36, 22, 23, 24, 25, 25, 16, 24, 26, 23, 27,
49, 45, 35, 36, 41, 39, 32, 39, 34, 42, 22, 24, 27, 28, 34, 40, 41, 43, 28, 26,
46, 41, 45, 46, 47, 44, 42, 43, 40, 38, 34, 44, 45, 46, 40, 50, 47, 44, 45, 41,
33, 31, 30, 26, 20, 7, 3, 48, 48, 48, 51, 43, 47, 51, 53, 54, 55, 46, 50, 56,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 57, 60, 70, 53, 54, 61, 56, 62, 64, 65,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 62, 55, 64, 68, 57, 60, 67, 61, 65, 66,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 63, 59, 58, 52, 49, 42, 36, 35, 30, 21,
48 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
} ; } ;
static yy_state_type yy_last_accepting_state; static yy_state_type yy_last_accepting_state;
@ -476,7 +490,7 @@ int yy_flex_debug = 0;
#define YY_RESTORE_YY_MORE_OFFSET #define YY_RESTORE_YY_MORE_OFFSET
char *yytext; char *yytext;
#line 1 "analyse_lexicale.lex" #line 1 "analyse_lexicale.lex"
#line 480 "lex.yy.c" #line 494 "lex.yy.c"
#define INITIAL 0 #define INITIAL 0
@ -693,10 +707,10 @@ YY_DECL
} }
{ {
#line 35 "analyse_lexicale.lex" #line 41 "analyse_lexicale.lex"
#line 700 "lex.yy.c" #line 714 "lex.yy.c"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{ {
@ -723,13 +737,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 49 ) if ( yy_current_state >= 70 )
yy_c = yy_meta[yy_c]; yy_c = yy_meta[yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp; ++yy_cp;
} }
while ( yy_base[yy_current_state] != 78 ); while ( yy_base[yy_current_state] != 117 );
yy_find_action: yy_find_action:
yy_act = yy_accept[yy_current_state]; yy_act = yy_accept[yy_current_state];
@ -755,131 +769,171 @@ do_action: /* This label is used only to access EOF actions. */
case 1: case 1:
YY_RULE_SETUP YY_RULE_SETUP
#line 37 "analyse_lexicale.lex" #line 43 "analyse_lexicale.lex"
{printf("tADD");} {return tADD ;}
YY_BREAK YY_BREAK
case 2: case 2:
YY_RULE_SETUP YY_RULE_SETUP
#line 38 "analyse_lexicale.lex" #line 44 "analyse_lexicale.lex"
{printf("tSUB");} {return tSUB ;}
YY_BREAK YY_BREAK
case 3: case 3:
YY_RULE_SETUP YY_RULE_SETUP
#line 39 "analyse_lexicale.lex" #line 45 "analyse_lexicale.lex"
{printf("tMUL");} {return tMUL ;}
YY_BREAK YY_BREAK
case 4: case 4:
YY_RULE_SETUP YY_RULE_SETUP
#line 40 "analyse_lexicale.lex" #line 46 "analyse_lexicale.lex"
{printf("tDIV");} {return tDIV ;}
YY_BREAK YY_BREAK
case 5: case 5:
YY_RULE_SETUP YY_RULE_SETUP
#line 41 "analyse_lexicale.lex" #line 48 "analyse_lexicale.lex"
{printf("tPO");} {return tPO ;}
YY_BREAK YY_BREAK
case 6: case 6:
YY_RULE_SETUP YY_RULE_SETUP
#line 42 "analyse_lexicale.lex" #line 49 "analyse_lexicale.lex"
{printf("tPF");} {return tPF ;}
YY_BREAK YY_BREAK
case 7: case 7:
YY_RULE_SETUP YY_RULE_SETUP
#line 43 "analyse_lexicale.lex" #line 50 "analyse_lexicale.lex"
{printf("tAO");} {return tAO ;}
YY_BREAK YY_BREAK
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
#line 44 "analyse_lexicale.lex" #line 51 "analyse_lexicale.lex"
{printf("tAF");} {return tAF ;}
YY_BREAK YY_BREAK
case 9: case 9:
YY_RULE_SETUP YY_RULE_SETUP
#line 45 "analyse_lexicale.lex" #line 53 "analyse_lexicale.lex"
{printf("tPV");} {return tPV ;}
YY_BREAK YY_BREAK
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
#line 46 "analyse_lexicale.lex" #line 54 "analyse_lexicale.lex"
{printf("tVIRGULE");} {}
YY_BREAK YY_BREAK
case 11: case 11:
/* rule 11 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 47 "analyse_lexicale.lex" #line 55 "analyse_lexicale.lex"
{printf("tEGAL");} {}
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
#line 48 "analyse_lexicale.lex" #line 56 "analyse_lexicale.lex"
{printf("tENTIER");} {return tVIRGULE ;}
YY_BREAK YY_BREAK
case 13: case 13:
YY_RULE_SETUP YY_RULE_SETUP
#line 49 "analyse_lexicale.lex" #line 58 "analyse_lexicale.lex"
{printf("tLT");} {return tAFFECTATION ;}
YY_BREAK YY_BREAK
case 14: case 14:
YY_RULE_SETUP YY_RULE_SETUP
#line 50 "analyse_lexicale.lex" #line 60 "analyse_lexicale.lex"
{printf("tGT");} {return tEGAL ;}
YY_BREAK YY_BREAK
case 15: case 15:
YY_RULE_SETUP YY_RULE_SETUP
#line 51 "analyse_lexicale.lex" #line 61 "analyse_lexicale.lex"
{printf("tMAIN");} {return tDIFF ;}
YY_BREAK YY_BREAK
case 16: case 16:
YY_RULE_SETUP YY_RULE_SETUP
#line 52 "analyse_lexicale.lex" #line 62 "analyse_lexicale.lex"
{printf("tINT");} {return tLT ;}
YY_BREAK YY_BREAK
case 17: case 17:
YY_RULE_SETUP YY_RULE_SETUP
#line 53 "analyse_lexicale.lex" #line 63 "analyse_lexicale.lex"
{printf("tPRINT");} {return tGT ;}
YY_BREAK YY_BREAK
case 18: case 18:
YY_RULE_SETUP YY_RULE_SETUP
#line 54 "analyse_lexicale.lex" #line 64 "analyse_lexicale.lex"
{printf("tOR");} {return tLTE ;}
YY_BREAK YY_BREAK
case 19: case 19:
YY_RULE_SETUP YY_RULE_SETUP
#line 55 "analyse_lexicale.lex" #line 65 "analyse_lexicale.lex"
{printf("tAND");} {return tGTE ;}
YY_BREAK YY_BREAK
case 20: case 20:
YY_RULE_SETUP YY_RULE_SETUP
#line 56 "analyse_lexicale.lex" #line 66 "analyse_lexicale.lex"
{printf("tIF");} {return tNOT ;}
YY_BREAK YY_BREAK
case 21: case 21:
YY_RULE_SETUP YY_RULE_SETUP
#line 57 "analyse_lexicale.lex" #line 69 "analyse_lexicale.lex"
{printf("tELSE");} {return tMAIN ;}
YY_BREAK YY_BREAK
case 22: case 22:
YY_RULE_SETUP YY_RULE_SETUP
#line 58 "analyse_lexicale.lex" #line 70 "analyse_lexicale.lex"
{printf("tVAR");} {return tINT ;}
YY_BREAK YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
#line 59 "analyse_lexicale.lex" #line 71 "analyse_lexicale.lex"
{} {return tPRINT ;}
YY_BREAK YY_BREAK
case 24: case 24:
/* rule 24 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 60 "analyse_lexicale.lex" #line 72 "analyse_lexicale.lex"
{} {return tRETURN ;}
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
#line 61 "analyse_lexicale.lex" #line 74 "analyse_lexicale.lex"
{return tOR ;}
YY_BREAK
case 26:
YY_RULE_SETUP
#line 75 "analyse_lexicale.lex"
{return tAND ;}
YY_BREAK
case 27:
YY_RULE_SETUP
#line 77 "analyse_lexicale.lex"
{return tIF ;}
YY_BREAK
case 28:
YY_RULE_SETUP
#line 78 "analyse_lexicale.lex"
{return tELSE ;}
YY_BREAK
case 29:
YY_RULE_SETUP
#line 79 "analyse_lexicale.lex"
{return tWHILE ;}
YY_BREAK
case 30:
YY_RULE_SETUP
#line 81 "analyse_lexicale.lex"
{return tCONST ;}
YY_BREAK
case 31:
YY_RULE_SETUP
#line 82 "analyse_lexicale.lex"
{return tENTIER ;}
YY_BREAK
case 32:
YY_RULE_SETUP
#line 83 "analyse_lexicale.lex"
{return tVAR ;}
YY_BREAK
case 33:
YY_RULE_SETUP
#line 85 "analyse_lexicale.lex"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 883 "lex.yy.c" #line 937 "lex.yy.c"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
yyterminate(); yyterminate();
@ -1176,7 +1230,7 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 49 ) if ( yy_current_state >= 70 )
yy_c = yy_meta[yy_c]; yy_c = yy_meta[yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
@ -1204,11 +1258,11 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 49 ) if ( yy_current_state >= 70 )
yy_c = yy_meta[yy_c]; yy_c = yy_meta[yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
yy_is_jam = (yy_current_state == 48); yy_is_jam = (yy_current_state == 69);
return yy_is_jam ? 0 : yy_current_state; return yy_is_jam ? 0 : yy_current_state;
} }
@ -1884,14 +1938,14 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
#line 61 "analyse_lexicale.lex" #line 85 "analyse_lexicale.lex"
int yywrap(void){ int yywrap(void){
return 1; return 1;
} }
int main(void){ //int main(void){
yylex(); // yylex();
} //}

31
script.sh Executable file
View file

@ -0,0 +1,31 @@
bison -d -t analyse_syntaxique.y -v
flex analyse_lexicale.lex
gcc *.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();
}
return 1;
}
" | ./a.out

27
test Normal file
View file

@ -0,0 +1,27 @@
int fonction1(int toto){
toto = toto + 1 ;
return toto;
}
int fonction2(){
int i = 0;
while (i <= 2){
print(i);
i = i +1 ;
}
return i;
}
int main(){
const int toto = 1, mimi, lolo = 6;
int tata = 5, lala;
if (tata == 5){
fonction(lolo);
} else if (toto == 1){
fonction2();
}
return 1;
}