Skip to content
Snippets Groups Projects
Commit 4856cbf2 authored by christia.agodomou's avatar christia.agodomou
Browse files

declar var declars lident done

parent 32cae712
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ public class DeclarationConstant extends Declaration{
super(new Symbole(type, true), fl, line , col);
this.exp = exp;
this.id = id;
TDS.getInstance().ajouter(new Symbole(type, null), new Entree(id.getNom()));
TDS.getInstance().ajouter(new Symbole(type, true), new Entree(id.getNom()));
}
public Idf getIdentifier(){
......
import java.util.ArrayList;
/*
* Represent a function declaration instruction node inside the AST.
*/
public class DeclarationVariable extends Declaration{
ArrayList<Idf> listeId;
public DeclarationVariable(Ttype type, ArrayList<Idf> listeId, String fl, int line, int col){
super(new Symbole(type, false), fl, line , col);
this.listeId = listeId;
for(Idf i : listeId){
TDS.getInstance().ajouter(new Symbole(type, false), new Entree(i.getNom()));
}
}
public Idf getIdentifier(){
return listeId.get(0);
}
/**
* Accepts a AST visitor
*/
Object accept(ASTVisitor visitor){
return visitor.visit(this);
}
}
......@@ -22,7 +22,7 @@ public interface ASTVisitor {
Object visit(DeclarationConstant node);
Object visit(DeclarationProgramme node);
// Object visit(DeclarationVariable node);
Object visit(DeclarationVariable node);
Object visit(Diff node);
Object visit(Division node);
......
......@@ -32,7 +32,7 @@ public class ByteCodeGenerator implements ASTVisitor {
return null;
}
// public Object visit(DeclarationVariable node) { return null; }
public Object visit(DeclarationVariable node) { return null; }
public Object visit(Diff node) { return null; }
......
......@@ -34,7 +34,7 @@ public class SemanticAnalyzer implements ASTVisitor {
return null;
}
// public Object visit(DeclarationVariable node) { return null; }
public Object visit(DeclarationVariable node) { return null; }
public Object visit(Diff node) { return null; }
......
......@@ -107,16 +107,16 @@ public class SourceCodeGenerator implements ASTVisitor {
return null;
}
// public Object visit(DeclarationVariable node){
// Symbole sym = TDS.getInstance().identifier(new
// Entree(node.getIdentifier().getNom()));
//
// code += sym + " ";
// node.getIdentifier().accept(this);
// if (!isParameterDeclaration)
// code += ";";
// return null;
// }
public Object visit(DeclarationVariable node){
Symbole sym = TDS.getInstance().identifier(new
Entree(node.getIdentifier().getNom()));
code += sym + " ";
node.getIdentifier().accept(this);
if (!isParameterDeclaration)
code += ";";
return null;
}
public Object visit(Diff node) {
node.getGauche().accept(this);
......
......@@ -18,8 +18,10 @@ terminal int INTEGERCONST;
// TODO: N'oubliez pas de spécifier les types des non terminaux (f.e. le non terminal "op_bin" est de type Binaire)
non terminal DeclarationProgramme program, header;
non terminal Bloc declar_lst, body;
non terminal ArrayList<Instruction> instr_lst, declars, declar, declar_var;
non terminal declar_const;
non terminal ArrayList<Instruction> instr_lst, declars;
non terminal Declaration declar;
non terminal DeclarationVariable declar_var;
non terminal DeclarationConstant declar_const;
non terminal Expression expr, access, operand;
non terminal Pour for_instr;
non terminal Tantque while_instr;
......@@ -31,7 +33,7 @@ non terminal Affectation assign;
non terminal Unaire op_una;
non terminal Binaire op_bin;
non terminal Relation relation;
non terminal l_ident;
non terminal ArrayList<Idf> l_ident;
non terminal Ttype type;
......@@ -59,16 +61,21 @@ header ::= PRG IDENT:id {: RESULT = new DeclarationProgramme(new Idf(
declar_lst ::= declars {: :};
declars ::= {: :}
| declars declar {: :};
declars ::= {: RESULT = new ArrayList();:}
| declars:ds declar:d {: ds.add(d);
RESULT = ds;:};
declar ::= declar_var {: :}
| declar_const {: :};
declar ::= declar_var:var {: RESULT = var;:}
| declar_const:cst {: RESULT = cst;:};
declar_var ::= type l_ident SEMICOLON {: :};
declar_var ::= type:t l_ident:l SEMICOLON {: RESULT = new DeclarationVariable(t, l, "", tleft, tright);:};
l_ident ::= IDENT {: :}
| l_ident COMMA IDENT {: :};
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);
idl.add(new Idf(id,"",idleft,idright));
RESULT = idl;:};
type ::= TINTEGER {: RESULT = (new entier());:}
| TBOOLEAN {: RESULT = (new booleen());:};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment