Skip to content
Snippets Groups Projects
Commit 5af6f4fd authored by lucien.noel's avatar lucien.noel
Browse files

push du travail de chris + début analyse semantique

parent 0fb4d072
No related branches found
No related tags found
No related merge requests found
......@@ -15,8 +15,8 @@ public class DeclarationVariable extends Declaration{
}
}
public Idf getIdentifier(){
return listeId.get(0);
public Idf getIdentifier(int i){
return listeId.get(i);
}
......
......@@ -12,6 +12,7 @@ public class Entree{
public String getNom() {
return this.varName;
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
......
This diff is collapsed.
programme Program
entier z;
entier x;
booleen p;
entier x, y;
booleen z;
debutprg
c = 1;
si c alors c = 2;sinon c = 0;
finsi
ecrire "::: loop0";
pour x allantde 0 a 10 faire
ecrire x;
finpour
x = 24;
z = vrai;
y = x + z;
finprg
......@@ -11,14 +11,28 @@
public class SemanticAnalyzer implements ASTVisitor {
public Object visit(Addition node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
if (!(node.getGauche() instanceof Nombre)) {
throw new RuntimeException("Impossible d'effectuer l'addition car la valeur de gauche n'est pas un nombre !");
}
if (!(node.getDroite() instanceof Nombre)) {
throw new RuntimeException("Impossible d'effectuer l'addition car la valeur de droite n'est pas un nombre !");
}
return null;
}
public Object visit(Affectation node) {
node.getDestination().accept(this);
node.getSource().accept(this);
return null;
}
public Object visit(Bloc node) {
for (Instruction inst : node.getInstructions()) {
inst.accept(this);
}
return null;
}
......@@ -26,75 +40,161 @@ public class SemanticAnalyzer implements ASTVisitor {
return null;
}
public Object visit(Condition node) { return null; }
public Object visit(Condition node) {
node.getCondition().accept(this);
node.getThenInstruction().accept(this);
if (node.hasElse()) {
node.getElseInstruction().accept(this);
}
return null;
}
public Object visit(DeclarationConstant node) { return null; }
public Object visit(DeclarationConstant node) {
node.getIdentifier().accept(this);
node.getConstantExpression().accept(this);
return null;
}
public Object visit(DeclarationProgramme node) {
node.getIdentifier().accept(this);
node.getDeclaration().accept(this);
node.getInstructions().accept(this);
return null;
}
public Object visit(DeclarationVariable node) {
for (int i = 0; i < node.listeId.size(); i++) {
node.getIdentifier(i).accept(this);
}
return null;
}
public Object visit(DeclarationVariable node) { return null; }
public Object visit(Diff node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
public Object visit(Diff node) { return null; }
return null;
}
public Object visit(Division node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(Ecrire node) { return null; }
public Object visit(Ecrire node) {
node.getSource().accept(this);
return null;
}
public Object visit(Egal node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(Et node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(Faux node) { return null; }
public Object visit(Faux node) {
return null;
}
public Object visit(Idf node) {
return null;
return node.getNom();
}
public Object visit(InfEgal node) { return null; }
public Object visit(InfEgal node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(Inferieur node) { return null; }
public Object visit(Inferieur node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(Lire node) { return null; }
public Object visit(Lire node) {
node.getDestination().accept(this);
return null;
}
public Object visit(Moins node) { return null; }
public Object visit(Moins node) {
node.getOperand().accept(this);
return null;
}
public Object visit(Nombre node) {
return node.getValeur();
}
public Object visit(Non node) {
node.getOperand().accept(this);
return null;
}
public Object visit(Non node) { return null; }
public Object visit(Ou node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(Ou node) { return null; }
public Object visit(Parentheses node) {
node.getExpression().accept(this);
return null;
}
public Object visit(Parentheses node) { return null; }
public Object visit(Pour node) {
node.getIteratorName().accept(this);
node.getFrom().accept(this);
node.getTo().accept(this);
node.getInstruction().accept(this);
public Object visit(Pour node) { return null; }
return null;
}
public Object visit(Produit node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(Relation node) { return null; }
public Object visit(Relation node) {
return null;
}
public Object visit(Soustraction node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(SupEgal node) { return null; }
public Object visit(SupEgal node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(Superieur node) { return null; }
public Object visit(Superieur node) {
node.getGauche().accept(this);
node.getDroite().accept(this);
return null;
}
public Object visit(Tantque node) { return null; }
public Object visit(Tantque node) {
return null;
}
public Object visit(Unaire node) { return null; }
public Object visit(Unaire node) {
return null;
}
public Object visit(Vrai node) { return null; }
public Object visit(Vrai node) {
return null;
}
}
......@@ -107,12 +107,22 @@ public class SourceCodeGenerator implements ASTVisitor {
}
public Object visit(DeclarationVariable node) {
Symbole sym = TDS.getInstance().identifier(new Entree(node.getIdentifier().getNom()));
for (int i = 0; i < node.listeId.size(); i++) {
Symbole sym = TDS.getInstance().identifier(new Entree(node.listeId.get(i).getNom()));
code += sym + " ";
node.getIdentifier().accept(this);
//code += node.listeId.get(i).getNom();
node.getIdentifier(i).accept(this);
if (!isParameterDeclaration)
code += ";";
if (!(i == node.listeId.size() - 1)) {
code += "\n";
addTabulation();
}
}
return null;
}
......
hepial.cup 100755 → 100644
......@@ -73,8 +73,9 @@ declar_var ::= type:t l_ident:l SEMICOLON {: RESULT = new DeclarationVari
l_ident ::= IDENT:id {: ArrayList<Idf> liste = new ArrayList<Idf>();
liste.add(new Idf(id,"",idleft,idright));
RESULT = liste;:}
| l_ident:idList COMMA IDENT:id {: ArrayList<Idf> idl = new ArrayList<Idf>((Collection<? extends Idf>) idList);
| l_ident:idList COMMA IDENT:id {: ArrayList<Idf> idl = new ArrayList<Idf>((idList));
idl.add(new Idf(id,"",idleft,idright));
RESULT = idl;:};
type ::= TINTEGER {: RESULT = (new entier());:}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment