diff --git a/src/l.cfg b/src/l.cfg index 5159f484cf0ea7172ce62b4aad5a0aaf3ab18347..d255ffd8509e8e4f2d4a54a21bdd8b50ab4ae95f 100644 --- a/src/l.cfg +++ b/src/l.cfg @@ -1,4 +1,4 @@ -Package lParser; +Package sc; Helpers @@ -11,22 +11,145 @@ Tokens espaces = (' ' | 13 | 10)+; commentaire= '#' [[0 .. 0xffff] - [10 + 13]]* (10 | 13 | 10 13); -plus = '+'; +virgule = ','; nombre = chiffre+; +ecrire = 'ecrire'; +retour = 'retour'; +ptvirgule = ';' ; +parenthouvrante = '('; +parenthfermante = ')'; +crochetouvrant = '['; +crochetfermant = ']'; +accolateouvrant = '{'; +accolatefermant = '}'; + + +egal = '='; +plus = '+'; +moins = '-'; +mult = '*'; +div= '/'; +modulo = '%'; +ou = '|'; +et = '&'; +negation = '!'; +inferieur = '<'; +superieur = '>'; + + + + +vrai = 'vrai'; +faux = 'faux'; + +si = 'si'; +sinon = 'sinon'; +alors = 'alors'; +tantque = 'tantque'; +faire = 'faire'; +lire = 'lire'; +entier = 'entier'; +bool = 'bool'; + +concat = ' '; + +identif = alpha alphanum*; Ignored Tokens espaces, commentaire; Productions -// l'axiome +programme = listedecvar listedecfonc; + +listedecvar = + {liste_des_variables} decvar listedecvarp | {vide}; + +listedecvarp = + {liste_des_variables_prime} virgule decvar listedecvarp | {vide}; + +decvar = + {type1} type identif | {type2} type identif crochetouvrant nombre crochetfermant ; + +listedecfonc = + {liste_des_fonctions} decfonc listedecfonc | {vide}; + +decfonc = + typeop identif parenthouvrante [parametre]:listedecvar parenthfermante [varloc]:listedecvar blocinst ; + +type = + {entier} entier | {boolean} bool ; + +typeop = + {type} type | {vide}; + +blocinst = + accolateouvrant listeinst accolatefermant ; + +listeinst = + {liste_instruction} inst listeinst | {vide} ; + +inst = + {variable} var egal expr ptvirgule | + {condition_si} si expr alors blocinst | + {condition_sinon} si expr alors [blocinstsi] : blocinst sinon [blocinstsinon] : blocinst | + {condition_tantque} tantque expr faire blocinst | + {condition_appelle_de_fonction} identif parenthouvrante listeexpr parenthfermante ptvirgule | + {ecrire} ecrire parenthouvrante expr parenthfermante ptvirgule | + {condition_return} retour expr ptvirgule ; + +listeexpr = + {liste_expression} expr listeexprp | {vide} ; + +listeexprp = + {liste_expression_prime} virgule expr listeexprp | {vide} ; + +expr = + {condition_ou} expr ou expr1 | + {expr1} expr1 ; + +expr1 = + {condition_et} expr1 et expr2 | + {expr2} expr2 ; + +expr2 = + {condition_egal} expr2 egal expr3 | + {condition_inf} expr2 inferieur expr3 | + {expr3} expr3 ; + +expr3 = + {condtion_plus} expr3 plus expr4 | + {condition_moins} expr3 moins expr4 | + {expr4} expr4 ; + +expr4 = + {condition_mult} expr4 mult expr5 | + {condition_div} expr4 div expr5 | + {expr5} expr5 ; + +expr5 = + {condition_negation} negation expr5 | + {expr6} expr6 ; + +expr6 = + {expr} parenthouvrante expr parenthfermante | + {nombre} nombre | + {vrai} vrai | + {faux} faux | + {identifiant} identif parenthouvrante listeexpr parenthfermante | + {lire} lire parenthouvrante parenthfermante | + {variable} var ; + +expr7 = {condition_concat} expr7 concat expr8 | {expr} expr8; +expr8 = {identif} identif | parenthouvrante expr7 parenthfermante ; + + -programme = exp ; +var = + {id1} identif | + {id2}identif crochetouvrant expr crochetfermant ; -exp = - {plus} exp plus nombre | - {nb} nombre ; diff --git a/src/sa.cfg b/src/sa.cfg index 60ff9b85148f3e6fe9b397212b275494b2853a94..d8628151c95df95738b712398c5e699a17ec4bd6 100644 --- a/src/sa.cfg +++ b/src/sa.cfg @@ -1,4 +1,4 @@ -Package saParser; +Package sc; Helpers @@ -9,54 +9,37 @@ alphanum = [lettre + chiffre]; Tokens -espaces = (' ' | 13 | 10 | 9)+; +espaces = (' ' | 13 | 10)+; commentaire= '#' [[0 .. 0xffff] - [10 + 13]]* (10 | 13 | 10 13); - - -po = '('; -pf = ')'; -saappel = 'SaAppel'; -sadecfonc = 'SaDecFonc'; -sadectab = 'SaDecTab'; -sadecvar = 'SaDecVar'; -sadecvarsimple = 'SaDecVarSimple'; -saexpadd = 'SaExpAdd'; -saexpand = 'SaExpAnd'; -saexpappel = 'SaExpAppel'; -saexpdiv = 'SaExpDiv'; -saexpequal = 'SaExpEqual'; -saexpfaux = 'SaExpFaux'; -saexpinf = 'SaExpInf'; -saexpint = 'SaExpInt'; -saexplire = 'SaExpLire'; -saexpmult = 'SaExpMult'; -saexpnot = 'SaExpNot'; -saexpor = 'SaExpOr'; -saexpsub = 'SaExpSub'; -saexpvar = 'SaExpVar'; -saexpvrai = 'SaExpVrai'; -sainstaffect = 'SaInstAffect'; -sainstbloc = 'SaInstBloc'; -sainstecriture = 'SaInstEcriture'; -sainstretour = 'SaInstRetour'; -sainstsi = 'SaInstSi'; -sainsttantque = 'SaInstTantQue'; -saldecfonc = 'SaLDecFonc'; -saldecvar = 'SaLDecVar'; -salexp = 'SaLExp'; -salinst = 'SaLInst'; -saprog = 'SaProg'; -savarindicee = 'SaVarIndicee'; -savarsimple = 'SaVarSimple'; -faux = 'faux'; -vrai = 'vrai'; -lire = 'lire'; -null = 'null'; +virgule = ','; +divise = '/'; +point_virgule = ';'; +fois = '*'; +moins = '-'; +parenthese_ouvrante = '('; +parenthese_fermante = ')'; +crochet_ouvrant = '['; +crochet_fermant = ']'; +accolade_ouvrante = '{'; +accolade_fermante = '}'; +egal = '='; +inferieur = '<'; +et = '&'; +ou = '|'; +non = '!'; +plus = '+'; +nonnull = '?'; +si = 'si'; +alors = 'alors'; +sinon = 'sinon'; +tantque = 'tantque'; +faire = 'faire'; entier = 'entier'; -bool = 'bool'; -nul = 'nul'; -integer = chiffre+; -id = alpha alphanum*; +retour = 'retour'; +lire = 'lire'; +ecrire = 'ecrire'; +nombre = chiffre+; +identif = alpha alphanum*; Ignored Tokens @@ -64,64 +47,147 @@ espaces, commentaire; Productions -prog = po saprog ldecvar ldecfonc pf; - - -exp = {add} po saexpadd [op1]:exp [op2]:exp pf - | {and} po saexpand [op1]:exp [op2]:exp pf - | {div} po saexpdiv [op1]:exp [op2]:exp pf - | {equal} po saexpequal [op1]:exp [op2]:exp pf - | {inf} po saexpinf [op1]:exp [op2]:exp pf - | {mult} po saexpmult [op1]:exp [op2]:exp pf - | {or} po saexpor [op1]:exp [op2]:exp pf - | {sub} po saexpsub [op1]:exp [op2]:exp pf - | {not} po saexpnot exp pf - | {appel} po saexpappel appel pf - | {var} po saexpvar var pf - | {faux} faux - | {vrai} vrai - | {int} integer - | {lire} lire - ; - -inst = {affect} po sainstaffect var exp pf - | {bloc} po sainstbloc linst pf - | {ecriture} po sainstecriture exp pf - | {retour} po sainstretour exp pf - | {si} po sainstsi exp [alors]:inst [sinon]:inst pf - | {si2} po sainstsi exp [alors]:inst null pf - | {tantque} po sainsttantque exp inst pf - | {appel} appel - ; - -ldecfonc = {rec} po saldecfonc decfonc ldecfonc pf - | {fin} null - ; - -ldecvar = {rec} po saldecvar decvar ldecvar pf - | {fin} null - ; - -lexp = {rec} po salexp exp lexp pf - | {fin} null - ; - -linst = {rec} po salinst inst linst pf - | {fin} null - ; - -decfonc = po sadecfonc id type [param]:ldecvar [variables]:ldecvar inst pf; - -decvar = {tab} po sadectab id type integer pf - | {simple} po sadecvarsimple id type pf - ; - -var = {indicee} po savarindicee id exp pf - | {simple} po savarsimple id pf; - -appel = po saappel id lexp pf; - -type = {entier} entier - | {bool} bool - | {null} nul - ; \ No newline at end of file +programme = +{decvarldecfonc} optdecvar listedecfonc | +{ldecfonc} listedecfonc; + +optdecvar = listedecvar point_virgule; + +listedecvar = +{decvarldecvar} decvar listedecvarbis | +{decvar} decvar; + + +listedecvarbis = +{decvarldecvar} virgule decvar listedecvarbis| +{decvar} virgule decvar ; + +decvar = +{decvarentier} entier identif | +{decvartableau} entier identif crochet_ouvrant nombre crochet_fermant ; + +listedecfonc = +{ldecfoncrec} decfonc listedecfonc | +{ldecfoncfinal} ; + +decfonc = +{decvarinstr} identif listeparam optdecvar instrbloc | +{instr} identif listeparam instrbloc ; + +listeparam = +{sansparam} parenthese_ouvrante parenthese_fermante | +{avecparam} parenthese_ouvrante listedecvar parenthese_fermante ; + +instr = +{instraffect} instraffect | +{instrbloc } instrbloc | +{instrsi } instrsi | +{instrtantque } instrtantque | +{instrappel } instrappel | +{instrretour } instrretour | +{instrecriture } instrecriture | +{instrvide} instrvide | +{instnonnull} instnonnull; + +instraffect = var egal exp point_virgule ; + +instrbloc = accolade_ouvrante listeinst accolade_fermante ; + +//listeinst = instr*; + +listeinst = +{linstrec} instr listeinst | +{linstfinal} ; + + + +instrsi = +{avecsinon} si exp alors instrbloc instrsinon | +{sanssinon} si exp alors instrbloc ; + +instopetern = +{sanssinon} si exp nonnull alors instrbloc instopetern | +{avecsinon} si exp2 alors instrbloc instnonnull; + + +instnonnull = nonnull instrbloc ; + +instrsinon = sinon instrbloc ; + +instrtantque = tantque exp faire instrbloc ; + +instrappel = appelfct point_virgule ; + +instrretour = retour exp point_virgule ; + +instrecriture = ecrire parenthese_ouvrante exp parenthese_fermante point_virgule ; + +instrvide = point_virgule ; + +//################################################################################ +// exp (booléennes, arithmétiques) avec implémentation des priorités. +// ordre croissant de priorités comme suit (le | a la plus petite priorité)= +// 7. | (ou) +// 6. & (et) +// 5. < = +// 4. + - +// 3. * / +// 2. ! (non) +// 1. (exp) appelfct var[exp] +//###############################################################################*/ + +exp = +{ou} exp ou exp1 | +{exp1} exp1; + +exp1 = +{et} exp1 et exp2 | +{exp2} exp2; + +exp2 = +{inf} exp2 inferieur exp3 | +{egal} exp2 egal exp3 | +{exp3} exp3; + +exp3 = +{plus} exp3 plus exp4 | +{moins} exp3 moins exp4 | +{exp4} exp4 ; + +exp4 = +{fois} exp4 fois exp5 | +{divise} exp4 divise exp5 | +{exp5} exp5 ; + +exp5 = +{non} non exp5 | +{exp6} exp6 ; + +exp6 = + {nonnull} nonnull exp6 | + {exp7} exp7 ; + +exp7 = + {nombre} nombre | + {appelfct} appelfct | + {var} var | + {parentheses} parenthese_ouvrante exp parenthese_fermante | + {lire} lire parenthese_ouvrante parenthese_fermante ; + + + +// accès à une variable, case d'un tableau ou appel à fonction + +var = +{vartab} identif crochet_ouvrant exp crochet_fermant | +{varsimple} identif ; + +listeexp = +{recursif} exp listeexpbis| +{final} ; + +listeexpbis = +{recursif} virgule exp listeexpbis | +{final} ; + +appelfct = identif parenthese_ouvrante listeexp parenthese_fermante ; \ No newline at end of file