146 lines
2.8 KiB
Text
146 lines
2.8 KiB
Text
%union {
|
|
int nombre;
|
|
char id[30];
|
|
}
|
|
|
|
%{
|
|
#include <stdio.h>
|
|
%}
|
|
|
|
|
|
%token<nombre> tENTIER
|
|
%token<nombre> tENTIEREXP
|
|
|
|
%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<id> tVAR
|
|
%token tNOT
|
|
|
|
%left tADD
|
|
%left tSUB
|
|
%left tMUL
|
|
%left tDIV
|
|
%right tEGAL
|
|
|
|
|
|
%%
|
|
|
|
//C : Fonctions Main ;
|
|
|
|
//Fonctions : Fonction Fonctions | ;
|
|
//Fonction : tINT tVAR tPO Params tPF Body;
|
|
|
|
|
|
Main : tINT tMAIN tPO Params tPF Body {printf("Dans main\n");};
|
|
|
|
Params : {printf("Sans params\n");} ;
|
|
Params : Param SuiteParams ;
|
|
|
|
Param : tINT tVAR {printf("Parametre : %s\n", $2);} ;
|
|
|
|
|
|
SuiteParams : tVIRGULE Param SuiteParams tPV ;
|
|
SuiteParams : ;
|
|
|
|
|
|
Body : tAO Instructions Return tAF {printf("Dans body\n");} ;
|
|
|
|
Instructions : Instruction Instructions ;
|
|
Instructions : ;
|
|
|
|
Instruction : Aff ;
|
|
Instruction : If ;
|
|
Instruction : While ;
|
|
Instruction : Print ;
|
|
Instruction : Decl ;
|
|
Instruction : Invocation tPV ;
|
|
|
|
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 {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");} ;
|
|
|
|
Args : tVAR SuiteArgs ;
|
|
Args : ;
|
|
|
|
SuiteArgs : tVIRGULE tVAR SuiteArgs ;
|
|
SuiteArgs : ;
|
|
|
|
If : tIF tPO Cond tPF tAO Instructions tAF Else {printf("Dans if\n");};
|
|
|
|
Else : tELSE tAO Instructions tAF {printf("else\n");} ;
|
|
Else : tELSE tIF tPO Cond tPF tAO Instructions tAF Else {printf("elsif\n");} ;
|
|
|
|
While : tWHILE tPO Cond tPF tAO Instructions tAF {printf("Dans while\n");};
|
|
|
|
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 {printf("Dans invocation\n");};
|
|
|
|
Print : tPRINT tPO tVAR tPF tPV {printf("printf de %s\n", $3);};
|
|
|
|
Return : tRETURN E tPV {printf("return\n");};
|
|
|
|
%%
|
|
#include <stdio.h>
|
|
void main(void){
|
|
yyparse();
|
|
}
|
|
|