declare works with list
This commit is contained in:
@@ -69,19 +69,22 @@ instruction [SymTable table] returns [Instruction out]:
|
|||||||
$out =new Return_instrImp($e.out);}
|
$out =new Return_instrImp($e.out);}
|
||||||
//| //ASSIGN
|
//| //ASSIGN
|
||||||
//i=ident ASSIGN e=expression [table]
|
//i=ident ASSIGN e=expression [table]
|
||||||
// {
|
//{
|
||||||
// $out = new AssignImp($i.out, $e.out);
|
// $out = new AssignImp($i.out, $e.out);
|
||||||
// }
|
//}
|
||||||
| //DECLARATION
|
| //DECLARATION
|
||||||
t=type i=ident
|
t=type i=ident
|
||||||
|
|
||||||
{
|
{
|
||||||
|
ArrayList<String> declare= new ArrayList<String>();
|
||||||
|
declare.add($i.out);
|
||||||
$table.addVar($i.out,$t.return_type);
|
$table.addVar($i.out,$t.return_type);
|
||||||
$out = new DeclarationImp($t.return_type, $i.out);
|
|
||||||
}(VIRGULE i2=ident
|
}(VIRGULE i2=ident
|
||||||
{
|
{
|
||||||
$table.addVar($i2.out,$t.return_type);
|
$table.addVar($i2.out,$t.return_type);
|
||||||
$out = new DeclarationImp($t.return_type, $i2.out);
|
declare.add($i2.out);
|
||||||
})*
|
})*
|
||||||
|
{$out = new DeclarationImp($t.return_type, declare);}
|
||||||
;
|
;
|
||||||
|
|
||||||
//Priorité lit(val, const ou paranthese) -> td_exp (*/%) -> exp (+-)
|
//Priorité lit(val, const ou paranthese) -> td_exp (*/%) -> exp (+-)
|
||||||
@@ -137,6 +140,12 @@ lit [SymTable table] returns [Expression out, Type return_Type]:
|
|||||||
$out=$e.out;
|
$out=$e.out;
|
||||||
$return_Type=$e.return_Type;
|
$return_Type=$e.return_Type;
|
||||||
}
|
}
|
||||||
|
// | t=ident{
|
||||||
|
// if($table.searchVar($t.out)){
|
||||||
|
// $out=$t.out;
|
||||||
|
// $return_Type=$table.getvar_Type($t.out);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
;
|
;
|
||||||
|
|
||||||
ident returns [String out]:
|
ident returns [String out]:
|
||||||
|
|||||||
5
src/main/java/TP2/Error/TypeChecking.java
Normal file
5
src/main/java/TP2/Error/TypeChecking.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package TP2.Error;
|
||||||
|
|
||||||
|
public class TypeChecking {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -59,6 +59,7 @@ public interface Interface{
|
|||||||
public interface ExprVisitor<H,S> {
|
public interface ExprVisitor<H,S> {
|
||||||
public S visitConst(ConstImp e,H h);
|
public S visitConst(ConstImp e,H h);
|
||||||
public S visitBinOp(BinopExpressionImp e, H h);
|
public S visitBinOp(BinopExpressionImp e, H h);
|
||||||
|
//public S visitVal(ValImp e,H h);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Type{
|
public interface Type{
|
||||||
|
|||||||
@@ -169,8 +169,7 @@ public class Program{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prettyprinter(String indent) {
|
public String prettyprinter(String indent) {
|
||||||
// TODO Auto-generated method stub
|
return t+ " :=" + e.toString();
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'prettyprinter'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -184,7 +183,7 @@ public class Program{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static record DeclarationImp(Type t, String s) implements Instruction{
|
public static record DeclarationImp(Type t, ArrayList<String> s) implements Instruction{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||||
@@ -193,7 +192,11 @@ public class Program{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prettyprinter(String indent) {
|
public String prettyprinter(String indent) {
|
||||||
return "declare "+t.toString()+s;
|
String str = indent + "declare "+t.prettyprinter() + " ";
|
||||||
|
for(int i = 0; i<s.size();i++){
|
||||||
|
str += s.get(i) + ", ";
|
||||||
|
}
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -201,9 +204,9 @@ public class Program{
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'toLLVM'");
|
throw new UnsupportedOperationException("Unimplemented method 'toLLVM'");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Type
|
||||||
public static record Type_voidImp() implements Type{
|
public static record Type_voidImp() implements Type{
|
||||||
public String prettyprinter() {
|
public String prettyprinter() {
|
||||||
return "VOID";
|
return "VOID";
|
||||||
@@ -264,9 +267,7 @@ public class Program{
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Integer visitAssign(AssignImp e, Map<String, Integer> h) {
|
public Integer visitAssign(AssignImp e, Map<String, Integer> h) {
|
||||||
//h.put(e.t(), e.e());
|
return e.accept(this, h);
|
||||||
//TODO
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Integer visitDeclaration(DeclarationImp e, Map<String, Integer> h) {
|
public Integer visitDeclaration(DeclarationImp e, Map<String, Integer> h) {
|
||||||
|
|||||||
@@ -46,6 +46,15 @@ public class SymTable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Type getvar_Type(String s){
|
||||||
|
for(int i= stackMap.size()-1; i>=0; i--){
|
||||||
|
if(stackMap.get(i).containsKey(s)){
|
||||||
|
return stackMap.get(i).get(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public String print_all(){
|
public String print_all(){
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
for(int i= stackMap.size()-1; i>=0; i--){
|
for(int i= stackMap.size()-1; i>=0; i--){
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
FUNC INT main() {
|
FUNC INT main() {
|
||||||
INT a
|
INT a,b,c
|
||||||
RETURN 4 + 6 * 5 + 3 }
|
RETURN 4 + 6 * 5 + 3 }
|
||||||
Reference in New Issue
Block a user