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

declarationconstant done?

parent 39a29a51
No related branches found
No related tags found
No related merge requests found
/*
* Represent a function declaration instruction node inside the AST.
*/
public abstract class Declaration extends Instruction{
Symbole id;
public Declaration(Symbole id, String fl, int line, int col){
super(fl,line,col);
this.id = id;
}
}
/*
* Represent a function declaration instruction node inside the AST.
*/
public class DeclarationConstant extends Declaration{
Expression exp;
Idf id;
public DeclarationConstant(Ttype type, Idf id, Expression exp, String fl, int line, int col){
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()));
}
public Idf getIdentifier(){
return this.id;
}
public Expression getConstantExpression(){
return this.exp;
}
/**
* Accepts a AST visitor
*/
Object accept(ASTVisitor visitor){
return visitor.visit(this);
}
}
import java.util.LinkedHashMap;
/*
* Represent a function declaration instruction node inside the AST.
*/
public class Entree{
private String varName;
public Entree(String str){
this.varName = str;
}
public String getNom() {
return this.varName;
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
return this.varName.equals(((Entree)obj).getNom());
}
}
/*
* Represent a function declaration instruction node inside the AST.
*/
public class Symbole{
Ttype type;
Boolean cst;
public Symbole(Ttype type, Boolean cst){
this.type = type;
this.cst = cst;
}
}
import java.util.LinkedHashMap;
/*
* Represent a function declaration instruction node inside the AST.
*/
public class TDS{
public Symbole s;
public Entree e;
private static TDS crtInstance = new TDS();
LinkedHashMap<Entree, Symbole> map;
private TDS(){
this.map = new LinkedHashMap<Entree, Symbole>();
}
public static TDS getInstance(){
return crtInstance;
}
public Symbole identifier(Entree entree){
for (Entree i : map.keySet()) {
if(i.getNom().equals(entree.getNom())){
return map.get(i);
}
}
return null;
}
public void ajouter(Symbole s, Entree e){
map.put(e,s);
}
}
public abstract class tdstype{ public abstract class Ttype{
String type; String type;
public tdstype(String type) { public Ttype(String type) {
this.type = type; this.type = type;
} }
......
public class booleen extends tdstype{ public class booleen extends Ttype{
public booleen() { public booleen() {
super("booleen"); super("booleen");
} }
......
public class entier extends tdstype{ public class entier extends Ttype{
public entier() { public entier() {
super("entier"); super("entier");
} }
......
...@@ -19,7 +19,7 @@ public interface ASTVisitor { ...@@ -19,7 +19,7 @@ public interface ASTVisitor {
Object visit(Chaine node); Object visit(Chaine node);
Object visit(Condition node); Object visit(Condition node);
// Object visit(DeclarationConstant node); Object visit(DeclarationConstant node);
Object visit(DeclarationProgramme node); Object visit(DeclarationProgramme node);
// Object visit(DeclarationVariable node); // Object visit(DeclarationVariable node);
......
...@@ -26,7 +26,7 @@ public class ByteCodeGenerator implements ASTVisitor { ...@@ -26,7 +26,7 @@ public class ByteCodeGenerator implements ASTVisitor {
public Object visit(Condition node) { return null; } public Object visit(Condition node) { return null; }
// public Object visit(DeclarationConstant node) { return null; } public Object visit(DeclarationConstant node) { return null; }
public Object visit(DeclarationProgramme node) { public Object visit(DeclarationProgramme node) {
return null; return null;
......
...@@ -28,7 +28,7 @@ public class SemanticAnalyzer implements ASTVisitor { ...@@ -28,7 +28,7 @@ public class SemanticAnalyzer implements ASTVisitor {
public Object visit(Condition node) { return null; } public Object visit(Condition node) { return null; }
// public Object visit(DeclarationConstant node) { return null; } public Object visit(DeclarationConstant node) { return null; }
public Object visit(DeclarationProgramme node) { public Object visit(DeclarationProgramme node) {
return null; return null;
......
...@@ -84,17 +84,17 @@ public class SourceCodeGenerator implements ASTVisitor { ...@@ -84,17 +84,17 @@ public class SourceCodeGenerator implements ASTVisitor {
return null; return null;
} }
// public Object visit(DeclarationConstant node){ public Object visit(DeclarationConstant node){
// Symbole sym = TDS.getInstance().identifier(new Symbole sym = TDS.getInstance().identifier(new
// Entree(node.getIdentifier().getNom())); Entree(node.getIdentifier().getNom()));
//
// code += sym + " "; code += sym + " ";
// node.getIdentifier().accept(this); node.getIdentifier().accept(this);
// code += " = "; code += " = ";
// node.getConstantExpression().accept(this); node.getConstantExpression().accept(this);
// code += ";"; code += ";";
// return null; return null;
// } }
public Object visit(DeclarationProgramme node) { public Object visit(DeclarationProgramme node) {
code += "programme "; code += "programme ";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment