Skip to content
Snippets Groups Projects
Commit 5d7b9a5e authored by BAZIZI Zakaria's avatar BAZIZI Zakaria
Browse files

ça travail (TP2)

parent dfdabfd0
No related branches found
No related tags found
No related merge requests found
...@@ -16,24 +16,26 @@ pointvirgule = ';' ; ...@@ -16,24 +16,26 @@ pointvirgule = ';' ;
moins = '-'; moins = '-';
ou = '|' ; ou = '|' ;
et = '&' ; et = '&' ;
virgule = ',' ;
egale = '=' ; egale = '=' ;
inf = '<' ; inf = '<' ;
fois = '*' ; fois = '*' ;
diviser = '/' ; diviser = '/' ;
non ='!' ; non ='!' ;
dparenthese = '(' ; gparenthese = '(' ;
gparenthese = ')' ; dparenthese = ')' ;
accoladeg = '{' ; accoladeg = '{' ;
accoladed = '}' ; accoladed = '}' ;
crochetg = '[' ; crochetg = '[' ;
crochetd = ']' ; crochetd = ']' ;
type = 'bool' | 'entier' ; bool = 'bool' ;
entier = 'entier' ;
si = 'si' ; si = 'si' ;
alors = 'alors' ; alors = 'alors' ;
tantque = 'tantque' ; tantque = 'tantque' ;
faire = 'faire' ; faire = 'faire' ;
sinon = 'sinon' ; sinon = 'sinon' ;
retourner = 'retourner' ; retourner = 'retour' ;
lire ='lire'; lire ='lire';
ecrire = 'ecrire' ; ecrire = 'ecrire' ;
nombre = chiffre+; nombre = chiffre+;
...@@ -49,8 +51,12 @@ espaces, commentaire; ...@@ -49,8 +51,12 @@ espaces, commentaire;
Productions Productions
or = // faire les regles pour prog exp and equals
{or} or ou and |{and} and ;
prog = ldec ldf ;
exp =
{or} exp ou and | {and} and ;
and = and =
{et} and et equals | {equals} equals ; {et} and et equals | {equals} equals ;
...@@ -62,31 +68,39 @@ add = ...@@ -62,31 +68,39 @@ add =
{plus} add plus mult | {moins} add moins mult | {mult} mult ; {plus} add plus mult | {moins} add moins mult | {mult} mult ;
mult = mult =
{fois} mult fois non | {diviser} mult diviser non | {neg} neg ; {fois} mult fois neg | {diviser} mult diviser neg | {neg} neg ;
neg = neg =
{non} non neg | {exp} exp ; {non} non neg | {e6} e6 ;
exp = e6 =
{or} dparenthese or gparenthese {parenthese} gparenthese exp dparenthese
| {nombre} nombre | {nombre} nombre
| {vrai} vrai | {vrai} vrai
| {faux} faux | {faux} faux
| {lire} lire ; | {lire} lire gparenthese dparenthese
|{var} var
| {appelfnc} id gparenthese le dparenthese;
ins = ins =
{affectation} var egale exp pointvirgule {affectation} var egale exp pointvirgule
|{tq} tantque exp faire bloc pointvirgule |{tq} tantque exp faire bloc
|{si} si exp alors bloc pointvirgule |{si} si exp alors bloc
|{sisinon} si exp alors [alor]:bloc sinon [sino]:bloc pointvirgule |{sisinon} si exp alors [alor]:bloc sinon [sino]:bloc
|{return} retourner exp pointvirgule |{return} retourner exp pointvirgule
|{listeexp} id gparenthese exp dparenthese pointvirgule
|{write} ecrire gparenthese exp dparenthese pointvirgule |{write} ecrire gparenthese exp dparenthese pointvirgule
|{bloc} bloc pointvirgule ; |{appelfnc} id gparenthese le dparenthese pointvirgule ;
bloc = {instr} li ; bloc = {instr} accoladeg li accoladed;
li = {listeinstr} ins li | {epsilon} epsilon ; li = {listeinstr} ins li | {epsilon} epsilon ;
epsilon = ; epsilon = ;
le = {expr} exp lse | {epsilon} epsilon ;
lse = {lstexpr} virgule exp lse | {epsilon} epsilon ;
var = {id} id | {id_crochet} id crochetg exp crochetd ; var = {id} id | {id_crochet} id crochetg exp crochetd ;
decvar = {declavariable} type id |type id crochetg nombre crochetd ;
type = {type} bool | entier ;
decfonc = {declafonc} typeopt id gparenthese [firstldec]: ldec dparenthese [secondldec]: ldec bloc ;
typeopt= {typeopt} type | epsilon ;
ldec = {lstdeclacvar} decvar suitedec | epsilon ;
suitedec = {suitedeclvar} virgule decvar suitedec |epsilon ;
ldf = {lstdecfnc} decfonc ldf | epsilon ;
package lParser;
import lParser.lexer.Lexer;
import lParser.node.Start;
import lParser.parser.Parser;
import sc.Sc2Xml;
import java.io.*;
public class main {
public static void main(String[] args) throws FileNotFoundException {
File fileToTest = new File("/Users/macbook/IdeaProjects/2024-compilation-bazizi/test/input/fibo.l") ;
FileInputStream inputStream = new FileInputStream(fileToTest) ;
Sc2Xml sc = new Sc2Xml("/Users/macbook/IdeaProjects/2024-compilation-bazizi/src/l.cfg");
try{
// Création des analyseurs lexicaux et syntaxique
Parser p =new Parser(new Lexer(new PushbackReader(new InputStreamReader(inputStream), 1024)));
Start tree = p.parse();
}
catch(Exception e){ System.out.println(e.getMessage());
}
}
}
This diff is collapsed.
...@@ -71,7 +71,7 @@ public class TestColorGraph ...@@ -71,7 +71,7 @@ public class TestColorGraph
g.show(System.out); g.show(System.out);
int[] colors = new int[]{ -3,-3,-3,0,-3,2,1,-3,-3,-3}; int[] colors = new int[]{ -3,-3,-3,0,-3,2,1,-3,-3,-3};
ColorGraph cg = new ColorGraph(g, 3, colors); ColorGraph cg = new ColorGraph(g, 3, colors);
cg.color(); //cg.color();
cg.affiche(); //cg.affiche();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment