From c400284b80e372e8d74cb84d8d3866eb8f858029 Mon Sep 17 00:00:00 2001 From: Xawirses Date: Tue, 1 Mar 2016 16:13:24 +0100 Subject: [PATCH] Mamannnnnnnnn !!!!!!!!!!!!!! --- header/affiche_arbre_abstrait.h | 9 + header/analyseur_syntaxyque.h | 2 + header/syntabs.h | 139 ++++++++++++ src/affiche_arbre_abstrait.c | 362 ++++++++++++++++++++++++++++++++ src/analyseur_syntaxyque.c | 69 ++++-- src/compilateur-l.c | 10 + src/syntabs.c | 236 +++++++++++++++++++++ 7 files changed, 807 insertions(+), 20 deletions(-) create mode 100644 header/affiche_arbre_abstrait.h create mode 100644 header/syntabs.h create mode 100644 src/affiche_arbre_abstrait.c create mode 100644 src/syntabs.c diff --git a/header/affiche_arbre_abstrait.h b/header/affiche_arbre_abstrait.h new file mode 100644 index 0000000..e17293a --- /dev/null +++ b/header/affiche_arbre_abstrait.h @@ -0,0 +1,9 @@ +#ifndef __AFFICHE_ARBRE_ABSTRAIT__ +#define __AFFICHE_ARBRE_ABSTRAIT__ + +#include "syntabs.h" + +void affiche_n_prog(n_prog *n); + +#endif + diff --git a/header/analyseur_syntaxyque.h b/header/analyseur_syntaxyque.h index c281509..60f53c4 100644 --- a/header/analyseur_syntaxyque.h +++ b/header/analyseur_syntaxyque.h @@ -11,6 +11,8 @@ #include "analyseur_lexical.h" #include "premiers.h" #include "suivants.h" +#include "syntabs.h" +#include "affiche_arbre_abstrait.h" void openSection ( const char * section ); void closeSection ( const char * section ); diff --git a/header/syntabs.h b/header/syntabs.h new file mode 100644 index 0000000..fbfd414 --- /dev/null +++ b/header/syntabs.h @@ -0,0 +1,139 @@ +#ifndef __SYNTABS__ +#define __SYNTABS__ + +typedef struct n_l_instr_ n_l_instr; +typedef struct n_instr_ n_instr; +typedef struct n_exp_ n_exp; +typedef struct n_l_exp_ n_l_exp; +typedef struct n_var_ n_var; +typedef struct n_l_dec_ n_l_dec; +typedef struct n_dec_ n_dec; +typedef struct n_prog_ n_prog; +typedef struct n_appel_ n_appel; + +/*-------------------------------------------------------------------------*/ +struct n_prog_ { + n_l_dec *variables; + n_l_dec *fonctions; +}; + +n_prog *cree_n_prog(n_l_dec *variables, n_l_dec *fonctions); +/*-------------------------------------------------------------------------*/ + +struct n_dec_ { + enum{foncDec, varDec, tabDec} type; + char *nom; + union { + struct{n_l_dec *param; n_l_dec *variables; n_instr *corps;}foncDec_; + struct{int type;}varDec_; + struct{int taille;}tabDec_; + } u; +}; + +n_dec *cree_n_dec_var(char *nom); +n_dec *cree_n_dec_tab(char *nom, int taille); +n_dec *cree_n_dec_fonc(char *nom, n_l_dec *param, n_l_dec *variables, n_instr *corps); + +/*-------------------------------------------------------------------------*/ + +/* ATTENTION : negatif => - unaire, comme dans -5 + non => négation logique + Le opérateurs unaires ont op2 = NULL par convention */ +typedef enum {plus, moins, fois, divise, modulo, egal, diff, inf, sup, infeg, supeg, ou, et, non, negatif} operation; + +struct n_exp_ { + enum{varExp, opExp, intExp, appelExp, lireExp, incrExp} type; + union{ + struct{operation op; struct n_exp_ *op1; struct n_exp_ *op2;} opExp_; + n_var *var; + n_var *incr; + int entier; + n_appel *appel; + }u; +}; + +n_exp *cree_n_exp_op(operation type, n_exp *op1, n_exp *op2); +n_exp *cree_n_exp_entier(int entier); +n_exp *cree_n_exp_var(n_var *var); +n_exp *cree_n_exp_appel(n_appel *app); +n_exp *cree_n_exp_lire(void); +n_exp *cree_n_exp_incr(n_var *var); + +/*-------------------------------------------------------------------------*/ + +struct n_instr_ { + enum {incrInst, affecteInst, siInst, faireInst, tantqueInst, appelInst, retourInst, ecrireInst, videInst, blocInst, pourInst } type; /* MODIFIE POUR EVAL*/ + union{ + n_exp *incr; + struct{n_var *var; n_exp *exp;} affecte_; + struct{n_exp *test; struct n_instr_ *alors; struct n_instr_ *sinon;} si_; + struct{n_exp *test; struct n_instr_ *faire;} tantque_; + struct{n_exp *test; struct n_instr_ *faire;} faire_; + struct{n_exp *test; struct n_instr_ *init; + struct n_instr_ *incr; struct n_instr_ *faire;} pour_; + n_appel *appel; + struct{n_exp *expression;} retour_; + struct{n_exp *expression;} ecrire_; + n_l_instr *liste; + }u; +}; + +n_instr *cree_n_instr_incr(n_exp *incr); +n_instr *cree_n_instr_si(n_exp *test, n_instr *alors, n_instr *sinon); +n_instr *cree_n_instr_bloc(n_l_instr *liste); +n_instr *cree_n_instr_tantque(n_exp *test, n_instr *faire); +n_instr *cree_n_instr_faire(n_instr *faire, n_exp *test); +n_instr *cree_n_instr_pour(n_instr *init, n_exp *test, n_instr *incr, n_instr *faire); +n_instr *cree_n_instr_affect(n_var *var, n_exp *exp); +n_instr *cree_n_instr_appel(n_appel *appel); +n_instr *cree_n_instr_retour(n_exp *expression); +n_instr *cree_n_instr_ecrire(n_exp *expression); +n_instr *cree_n_instr_vide(void); + +/*-------------------------------------------------------------------------*/ +struct n_appel_{ + char *fonction; + n_l_exp *args; +}; + +n_appel *cree_n_appel(char *fonction, n_l_exp *args); + +/*-------------------------------------------------------------------------*/ +struct n_var_ { + enum {simple, indicee} type; + char *nom; + union { + struct{n_exp *indice;} indicee_; + }u; +}; + +n_var *cree_n_var_simple(char *nom); +n_var *cree_n_var_indicee(char *nom, n_exp *indice); + +/*-------------------------------------------------------------------------*/ +struct n_l_exp_ { + n_exp *tete; + struct n_l_exp_ *queue; +}; + +n_l_exp *cree_n_l_exp(n_exp *tete, n_l_exp *queue); + +/*-------------------------------------------------------------------------*/ +struct n_l_instr_ { + n_instr *tete; + struct n_l_instr_ *queue; +}; + +n_l_instr *cree_n_l_instr(n_instr *tete, n_l_instr *queue); + +/*-------------------------------------------------------------------------*/ + +struct n_l_dec_{ + n_dec *tete; + struct n_l_dec_ *queue; +}; + +n_l_dec *cree_n_l_dec(n_dec *tete, n_l_dec *queue); +/*-------------------------------------------------------------------------*/ + +#endif diff --git a/src/affiche_arbre_abstrait.c b/src/affiche_arbre_abstrait.c new file mode 100644 index 0000000..090ee82 --- /dev/null +++ b/src/affiche_arbre_abstrait.c @@ -0,0 +1,362 @@ +#include +#include "syntabs.h" +#include "util.h" + +void affiche_n_prog(n_prog *n); +void affiche_l_instr(n_l_instr *n); +void affiche_instr(n_instr *n); +void affiche_instr_si(n_instr *n); +void affiche_instr_tantque(n_instr *n); +void affiche_instr_faire(n_instr *n); /* MODIFIE POUR EVAL */ +void affiche_instr_pour(n_instr *n); /* MODIFIE POUR EVAL */ +void affiche_instr_affect(n_instr *n); +void affiche_instr_appel(n_instr *n); +void affiche_instr_retour(n_instr *n); +void affiche_instr_ecrire(n_instr *n); +void affiche_l_exp(n_l_exp *n); +void affiche_exp(n_exp *n); +void affiche_varExp(n_exp *n); +void affiche_opExp(n_exp *n); +void affiche_intExp(n_exp *n); +void affiche_lireExp(n_exp *n); +void affiche_appelExp(n_exp *n); +void affiche_l_dec(n_l_dec *n); +void affiche_dec(n_dec *n); +void affiche_foncDec(n_dec *n); +void affiche_varDec(n_dec *n); +void affiche_tabDec(n_dec *n); +void affiche_var(n_var *n); +void affiche_var_simple(n_var *n); +void affiche_var_indicee(n_var *n); +void affiche_appel(n_appel *n); + +int trace_abs = 1; + +/*-------------------------------------------------------------------------*/ + +void affiche_n_prog(n_prog *n) +{ + char *fct = "prog"; + affiche_balise_ouvrante(fct, trace_abs); + + affiche_l_dec(n->variables); + affiche_l_dec(n->fonctions); + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------------*/ + +void affiche_l_instr(n_l_instr *n) +{ + char *fct = "l_instr"; + if(n){ + affiche_balise_ouvrante(fct, trace_abs); + affiche_instr(n->tete); + affiche_l_instr(n->queue); + affiche_balise_fermante(fct, trace_abs); + } +} + +/*-------------------------------------------------------------------------*/ + +void affiche_instr(n_instr *n) +{ + if(n){ + if(n->type == blocInst) affiche_l_instr(n->u.liste); + else if(n->type == affecteInst) affiche_instr_affect(n); + else if(n->type == siInst) affiche_instr_si(n); + else if(n->type == tantqueInst) affiche_instr_tantque(n); + else if(n->type == faireInst) affiche_instr_faire(n); + else if(n->type == pourInst) affiche_instr_pour(n); + else if(n->type == appelInst) affiche_instr_appel(n); + else if(n->type == retourInst) affiche_instr_retour(n); + else if(n->type == ecrireInst) affiche_instr_ecrire(n); + } +} + +/*-------------------------------------------------------------------------*/ + +void affiche_instr_si(n_instr *n) +{ + char *fct = "instr_si"; + affiche_balise_ouvrante(fct, trace_abs); + + affiche_exp(n->u.si_.test); + affiche_instr(n->u.si_.alors); + if(n->u.si_.sinon){ + affiche_instr(n->u.si_.sinon); + } + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_instr_tantque(n_instr *n) +{ + char *fct = "instr_tantque"; + affiche_balise_ouvrante(fct, trace_abs); + + affiche_exp(n->u.tantque_.test); + affiche_instr(n->u.tantque_.faire); + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_instr_faire(n_instr *n) /* MODIFIE POUR EVAL */ +{ /* MODIFIE POUR EVAL */ + char *fct = "instr_faire"; /* MODIFIE POUR EVAL */ + affiche_balise_ouvrante(fct, trace_abs); /* MODIFIE POUR EVAL */ + affiche_instr(n->u.faire_.faire); /* MODIFIE POUR EVAL */ + affiche_exp(n->u.faire_.test); /* MODIFIE POUR EVAL */ + affiche_balise_fermante(fct, trace_abs); /* MODIFIE POUR EVAL */ +} /* MODIFIE POUR EVAL */ + +/*-------------------------------------------------------------------------*/ + +void affiche_instr_pour(n_instr *n) /* MODIFIE POUR EVAL */ +{ /* MODIFIE POUR EVAL */ + char *fct = "instr_pour"; /* MODIFIE POUR EVAL */ + affiche_balise_ouvrante(fct, trace_abs); /* MODIFIE POUR EVAL */ + affiche_instr(n->u.pour_.init); /* MODIFIE POUR EVAL */ + affiche_exp(n->u.pour_.test); /* MODIFIE POUR EVAL */ + affiche_instr(n->u.pour_.faire); /* MODIFIE POUR EVAL */ + affiche_instr(n->u.pour_.incr); /* MODIFIE POUR EVAL */ + affiche_balise_fermante(fct, trace_abs); /* MODIFIE POUR EVAL */ +} /* MODIFIE POUR EVAL */ + +/*-------------------------------------------------------------------------*/ + +void affiche_instr_affect(n_instr *n) +{ + char *fct = "instr_affect"; + affiche_balise_ouvrante(fct, trace_abs); + + + affiche_var(n->u.affecte_.var); + affiche_exp(n->u.affecte_.exp); + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_instr_appel(n_instr *n) +{ + char *fct = "instr_appel"; + affiche_balise_ouvrante(fct, trace_abs); + + + affiche_appel(n->u.appel); + affiche_balise_fermante(fct, trace_abs); +} +/*-------------------------------------------------------------------------*/ + +void affiche_appel(n_appel *n) +{ + char *fct = "appel"; + affiche_balise_ouvrante(fct, trace_abs); + affiche_texte( n->fonction, trace_abs); + affiche_l_exp(n->args); + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_instr_retour(n_instr *n) +{ + char *fct = "instr_retour"; + affiche_balise_ouvrante(fct, trace_abs); + affiche_exp(n->u.retour_.expression); + affiche_balise_fermante(fct, trace_abs); + +} + +/*-------------------------------------------------------------------------*/ + +void affiche_instr_ecrire(n_instr *n) +{ + char *fct = "instr_ecrire"; + affiche_balise_ouvrante(fct, trace_abs); + affiche_exp(n->u.ecrire_.expression); + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_l_exp(n_l_exp *n) +{ + char *fct = "l_exp"; + affiche_balise_ouvrante(fct, trace_abs); + + if(n){ + affiche_exp(n->tete); + affiche_l_exp(n->queue); + } + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_exp(n_exp *n) +{ + + if(n->type == varExp) affiche_varExp(n); + else if(n->type == opExp) affiche_opExp(n); + else if(n->type == intExp) affiche_intExp(n); + else if(n->type == appelExp) affiche_appelExp(n); + else if(n->type == lireExp) affiche_lireExp(n); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_varExp(n_exp *n) +{ + char *fct = "varExp"; + affiche_balise_ouvrante(fct, trace_abs); + affiche_var(n->u.var); + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ +void affiche_opExp(n_exp *n) +{ + char *fct = "opExp"; + affiche_balise_ouvrante(fct, trace_abs); + if(n->u.opExp_.op == plus) affiche_texte("plus", trace_abs); + else if(n->u.opExp_.op == moins) affiche_texte("moins", trace_abs); + else if(n->u.opExp_.op == fois) affiche_texte("fois", trace_abs); + else if(n->u.opExp_.op == divise) affiche_texte("divise", trace_abs); + else if(n->u.opExp_.op == egal) affiche_texte("egal", trace_abs); + else if(n->u.opExp_.op == diff) affiche_texte("diff", trace_abs); + else if(n->u.opExp_.op == inf) affiche_texte("inf", trace_abs); + else if(n->u.opExp_.op == infeg) affiche_texte("infeg", trace_abs); + else if(n->u.opExp_.op == ou) affiche_texte("ou", trace_abs); + else if(n->u.opExp_.op == et) affiche_texte("et", trace_abs); + else if(n->u.opExp_.op == non) affiche_texte("non", trace_abs); + if( n->u.opExp_.op1 != NULL ) { + affiche_exp(n->u.opExp_.op1); + } + if( n->u.opExp_.op2 != NULL ) { + affiche_exp(n->u.opExp_.op2); + } + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_intExp(n_exp *n) +{ + char texte[ 50 ]; // Max. 50 chiffres + sprintf(texte, "%d", n->u.entier); + affiche_element( "intExp", texte, trace_abs ); +} + +/*-------------------------------------------------------------------------*/ +void affiche_lireExp(n_exp *n) +{ + char *fct = "lireExp"; + affiche_balise_ouvrante(fct, trace_abs); + affiche_balise_fermante(fct, trace_abs); + +} + +/*-------------------------------------------------------------------------*/ + +void affiche_appelExp(n_exp *n) +{ + char *fct = "appelExp"; + affiche_balise_ouvrante(fct, trace_abs); + affiche_appel(n->u.appel); + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_l_dec(n_l_dec *n) +{ + char *fct = "l_dec"; + + if( n ){ + affiche_balise_ouvrante(fct, trace_abs); + affiche_dec(n->tete); + affiche_l_dec(n->queue); + affiche_balise_fermante(fct, trace_abs); + } +} + +/*-------------------------------------------------------------------------*/ + +void affiche_dec(n_dec *n) +{ + + if(n){ + if(n->type == foncDec) { + affiche_foncDec(n); + } + else if(n->type == varDec) { + affiche_varDec(n); + } + else if(n->type == tabDec) { + affiche_tabDec(n); + } + } +} + +/*-------------------------------------------------------------------------*/ + +void affiche_foncDec(n_dec *n) +{ + char *fct = "foncDec"; + affiche_balise_ouvrante(fct, trace_abs); + affiche_texte( n->nom, trace_abs ); + affiche_l_dec(n->u.foncDec_.param); + affiche_l_dec(n->u.foncDec_.variables); + affiche_instr(n->u.foncDec_.corps); + affiche_balise_fermante(fct, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_varDec(n_dec *n) +{ + affiche_element("varDec", n->nom, trace_abs); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_tabDec(n_dec *n) +{ + char texte[100]; // Max. 100 chars nom tab + taille + sprintf(texte, "%s[%d]", n->nom, n->u.tabDec_.taille); + affiche_element( "tabDec", texte, trace_abs ); +} + +/*-------------------------------------------------------------------------*/ + +void affiche_var(n_var *n) +{ + if(n->type == simple) { + affiche_var_simple(n); + } + else if(n->type == indicee) { + affiche_var_indicee(n); + } +} + +/*-------------------------------------------------------------------------*/ +void affiche_var_simple(n_var *n) +{ + affiche_element("var_simple", n->nom, trace_abs); +} + +/*-------------------------------------------------------------------------*/ +void affiche_var_indicee(n_var *n) +{ + char *fct = "var_indicee"; + affiche_balise_ouvrante(fct, trace_abs); + affiche_element("var_base_tableau", n->nom, trace_abs); + affiche_exp( n->u.indicee_.indice ); + affiche_balise_fermante(fct, trace_abs); +} +/*-------------------------------------------------------------------------*/ diff --git a/src/analyseur_syntaxyque.c b/src/analyseur_syntaxyque.c index db72dc6..854b833 100644 --- a/src/analyseur_syntaxyque.c +++ b/src/analyseur_syntaxyque.c @@ -1,7 +1,7 @@ #include "analyseur_syntaxyque.h" int uniteCourante; -int afficheSyntaxyque = 1; +int afficheSyntaxyque = 0; extern char yytext[100]; extern int nb_ligne; @@ -608,85 +608,113 @@ void comparaisonBis() { closeSection( __func__ ); } -void expArith() +n_exp expArith() { openSection( __func__ ); + n_exp *sreturn; + n_exp *herite_fils; + if( est_premier( _terme_, uniteCourante ) ) { - terme(); - expArithBis(); + herite_fils = terme(); + sreturn = expArithBis(herite_fils); } else { syntaxError(); } closeSection( __func__ ); + return sreturn; } -void expArithBis() { +n_exp expArithBis(n_exp *herite) { openSection( __func__ ); + n_exp *s; + n_exp *sreturn; + n_exp *herite_fils; + if( uniteCourante == PLUS ) { elementConsome(); uniteCourante = yylex(); - terme(); - expArithBis(); + s = terme(); + herite_fils = cree_n_exp_op(plus, herite, s); + sreturn = expArithBis(herite_fils); } else if( uniteCourante == MOINS) { elementConsome(); uniteCourante = yylex(); - terme(); - expArithBis(); + s = terme(); + erite_fils = cree_n_exp_op(moins, herite, s); + sreturn = expArithBis(); } else if( !est_suivant( _expArithBis_, uniteCourante ) ) { syntaxError(); + } else { + sreturn = herite; } closeSection( __func__ ); + return sreturn; } -void terme() { +n_exp terme() { openSection( __func__ ); + n_exp *sreturn; + n_exp *herite_fils; + if( est_premier( _facteur_, uniteCourante ) ) { - facteur(); - termeBis(); + herite_fils = facteur(); + sreturn = termeBis(herite_fils); } else { syntaxError(); } closeSection( __func__ ); + return sreturn; } -void termeBis() { +n_exp *termeBis(n_exp *herite) { openSection( __func__ ); + n_exp *s; + n_exp *sreturn; + n_exp *herite_fils; + if( uniteCourante == FOIS ) { elementConsome(); uniteCourante = yylex(); - facteur(); - termeBis(); + s = facteur(); + herite_fils = cree_n_exp_op(fois, herite, s); + sreturn = termeBis(herite_fils); } else if( uniteCourante == DIVISE) { elementConsome(); uniteCourante = yylex(); - facteur(); - termeBis(); + s = facteur(); + herite_fils = cree_n_exp_op(divise, herite, s); + sreturn = termeBis(herite_fils); } else if( !est_suivant( _termeBis_, uniteCourante ) ) { syntaxError(); + } else { + sreturn = herite; } closeSection( __func__ ); + return sreturn; } -void facteur() { +n_exp facteur() { openSection( __func__ ); + n_exp *sreturn; + if( uniteCourante == PARENTHESE_OUVRANTE ) { elementConsome(); uniteCourante = yylex(); - expression(); + sreturn = expression(); if( uniteCourante == PARENTHESE_FERMANTE ) { elementConsome(); @@ -695,10 +723,11 @@ void facteur() { syntaxErrorMsg( "')' été attendu" ); } } else if( uniteCourante == NOMBRE ) { + sreturn = cree_n_exp_entier(atoi(yytext)); elementConsome(); uniteCourante = yylex(); } else if( est_premier( _appelFct_, uniteCourante ) ) { - appelFct(); + appelFct(); // TODOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO } else if( est_premier( _var_, uniteCourante ) ) { var(); } else if( uniteCourante == LIRE ) { diff --git a/src/compilateur-l.c b/src/compilateur-l.c index e876e8c..e166d2e 100644 --- a/src/compilateur-l.c +++ b/src/compilateur-l.c @@ -2,9 +2,11 @@ #include #include "analyseur_lexical.h" #include "analyseur_syntaxyque.h" +#include "affiche_arbre_abstrait.h" #include "symboles.h" extern int uniteCourante; +extern int afficheSyntaxyque; char yytext[100]; FILE *yyin; @@ -20,14 +22,22 @@ int main(int argc, char **argv) { if (!strcmp(argv[1], "-l")) { test_yylex_internal(yyin); } else if (!strcmp(argv[1], "-s")) { + afficheSyntaxyque = 1; initialise_premiers(); initialise_suivants(); uniteCourante = yylex(); programme(); + } else if (!strcmp(argv[1], "-a")) { + initialise_premiers(); + initialise_suivants(); + uniteCourante = yylex(); + n_prog *p = programme(); + affiche_n_prog(p); } else { fprintf(stderr, "option Inconue"); + exit(1); } uniteCourante = yylex(); diff --git a/src/syntabs.c b/src/syntabs.c new file mode 100644 index 0000000..5c3d697 --- /dev/null +++ b/src/syntabs.c @@ -0,0 +1,236 @@ +#include +#include +#include"util.h" +#include"syntabs.h" + +n_appel *cree_n_appel(char *fonction, n_l_exp *args) +{ + n_appel *n = malloc(sizeof(n_appel)); + n->fonction = fonction; + n->args = args; + return n; +} + +n_prog *cree_n_prog(n_l_dec *variables, n_l_dec *fonctions) +{ + n_prog *n = malloc(sizeof(n_prog)); + n->variables = variables; + n->fonctions = fonctions; + return n; +} + +n_var *cree_n_var_simple(char *nom) +{ + n_var *n = malloc(sizeof(n_var)); + n->type = simple; + n->nom = nom; + return n; +} + +n_var *cree_n_var_indicee(char *nom, n_exp *indice) +{ + n_var *n = malloc(sizeof(n_var)); + n->type = indicee; + n->nom = nom; + n->u.indicee_.indice = indice; + return n; +} + +n_exp *cree_n_exp_op(operation op, n_exp *op1, n_exp *op2) +{ + n_exp *n = malloc(sizeof(n_exp)); + n->type = opExp; + n->u.opExp_.op = op; + n->u.opExp_.op1 = op1; + n->u.opExp_.op2 = op2; + return n; +} + +n_exp *cree_n_exp_appel(n_appel *app) +{ + n_exp *n = malloc(sizeof(n_exp)); + n->type = appelExp; + n->u.appel = app; + return n; +} + +n_exp *cree_n_exp_incr(n_var *var) +{ + n_exp *n = malloc(sizeof(n_exp)); + n->type = incrExp; + n->u.incr = var; + return n; + } + +n_exp *cree_n_exp_var(n_var *var) +{ + n_exp *n = malloc(sizeof(n_exp)); + n->type = varExp; + n->u.var = var; + return n; +} + +n_exp *cree_n_exp_entier(int entier) +{ + n_exp *n = malloc(sizeof(n_exp)); + n->type = intExp; + n->u.entier = entier; + return n; +} + +n_exp *cree_n_exp_lire() +{ + n_exp *n = malloc(sizeof(n_exp)); + n->type = lireExp; + return n; +} + + +n_l_exp *cree_n_l_exp(n_exp *tete, n_l_exp *queue) +{ + n_l_exp *n = malloc(sizeof(n_l_exp)); + n->tete = tete; + n->queue = queue; + return n; +} + +n_instr *cree_n_instr_incr(n_exp *incr) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = incrInst; + n->u.incr = incr; + return n; +} + +n_instr *cree_n_instr_si(n_exp *test, n_instr *alors, n_instr *sinon) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = siInst; + n->u.si_.test = test; + n->u.si_.alors = alors; + n->u.si_.sinon = sinon; + return n; +} + +n_instr *cree_n_instr_tantque(n_exp *test, n_instr *faire) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = tantqueInst; + n->u.tantque_.test = test; + n->u.tantque_.faire = faire; + return n; +} + +n_instr *cree_n_instr_faire(n_instr *faire, n_exp *test) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = faireInst; + n->u.tantque_.test = test; + n->u.tantque_.faire = faire; + return n; +} + +n_instr *cree_n_instr_pour(n_instr *init, n_exp *test, + n_instr *incr, n_instr *faire) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = pourInst; + n->u.pour_.test = test; + n->u.pour_.faire = faire; + n->u.pour_.incr = incr; + n->u.pour_.init = init; + return n; +} + +n_instr *cree_n_instr_affect(n_var *var, n_exp *exp) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = affecteInst; + n->u.affecte_.var = var; + n->u.affecte_.exp = exp; + return n; +} + +n_l_instr *cree_n_l_instr(n_instr *tete, n_l_instr *queue) +{ + n_l_instr *n = malloc(sizeof(n_l_instr)); + n->tete = tete; + n->queue = queue; + return n; +} + +n_instr *cree_n_instr_bloc(n_l_instr *liste) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = blocInst; + n->u.liste = liste; + return n; +} + +n_instr *cree_n_instr_appel(n_appel *app) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = appelInst; + n->u.appel = app; + return n; +} + +n_instr *cree_n_instr_ecrire(n_exp *expression) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = ecrireInst; + n->u.ecrire_.expression = expression; + return n; +} + +n_instr *cree_n_instr_retour(n_exp *expression) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = retourInst; + n->u.retour_.expression = expression; + return n; +} + +n_instr *cree_n_instr_vide(void) +{ + n_instr *n = malloc(sizeof(n_instr)); + n->type = videInst; + return n; +} + +n_dec *cree_n_dec_var(char *nom) +{ + n_dec *n = malloc(sizeof(n_dec)); + n->type = varDec; + n->nom = nom; + return n; +} + +n_dec *cree_n_dec_tab(char *nom, int taille) +{ + n_dec *n = malloc(sizeof(n_dec)); + n->type = tabDec; + n->nom = nom; + n->u.tabDec_.taille = taille; + return n; +} + +n_dec *cree_n_dec_fonc(char *nom, n_l_dec *param, n_l_dec *variables, n_instr *corps) +{ + n_dec *n = malloc(sizeof(n_dec)); + n->type = foncDec; + n->nom = nom; + n->u.foncDec_.param = param; + n->u.foncDec_.variables = variables; + n->u.foncDec_.corps = corps; + return n; +} + +n_l_dec *cree_n_l_dec(n_dec *tete, n_l_dec *queue) +{ + n_l_dec *n = malloc(sizeof(n_l_dec)); + n->tete = tete; + n->queue = queue; + return n; +} +