block
This commit is contained in:
@@ -39,11 +39,11 @@ functions returns [ArrayList<Function> out]
|
||||
|
||||
function returns [Function out]:
|
||||
FUNCTION t=type i=ident ParO ParF
|
||||
(
|
||||
BacO instrs=list_instr BacF
|
||||
BacO
|
||||
(instrs=list_instr
|
||||
{
|
||||
$out=new FunctionImp($t.return_type, $i.out, $instrs.out);
|
||||
}
|
||||
} BacF
|
||||
| instr= instruction
|
||||
{
|
||||
$out=new FunctionImp($t.return_type, $i.out, $instr.out);
|
||||
@@ -51,6 +51,18 @@ function returns [Function out]:
|
||||
)
|
||||
;
|
||||
|
||||
declaration returns [Declaration out]:
|
||||
(t=type i=ident
|
||||
{
|
||||
ArrayList<String> declare= new ArrayList<String>();
|
||||
declare.add($i.out);
|
||||
}(VIRGULE i2=ident
|
||||
{
|
||||
declare.add($i2.out);
|
||||
})*
|
||||
{$out = new DeclarationImp($t.return_type, declare);})+
|
||||
;
|
||||
|
||||
list_instr returns [ArrayList<Instruction> out]
|
||||
@init{
|
||||
$out = new ArrayList<>();
|
||||
@@ -65,21 +77,21 @@ instruction returns [Instruction out]:
|
||||
RETURN e=expression
|
||||
{
|
||||
$out =new Return_instrImp($e.out);}
|
||||
| //BLOC
|
||||
BacO
|
||||
(dec=declaration instr4=list_instr
|
||||
{
|
||||
$out=new BlocDec($dec.out,$insts4.out);
|
||||
}
|
||||
| instr3=list_instr
|
||||
{ $out= new Bloc($instr3.out);
|
||||
}
|
||||
) BacF
|
||||
| //ASSIGN
|
||||
i=ident ASSIGN e=expression
|
||||
{
|
||||
$out = new AssignImp($i.out, $e.out);
|
||||
}
|
||||
| //DECLARATION
|
||||
t=type i=ident
|
||||
{
|
||||
ArrayList<String> declare= new ArrayList<String>();
|
||||
declare.add($i.out);
|
||||
}(VIRGULE i2=ident
|
||||
{
|
||||
declare.add($i2.out);
|
||||
})*
|
||||
{$out = new DeclarationImp($t.return_type, declare);}
|
||||
| // PRINT
|
||||
PRINT
|
||||
{ArrayList<Object> printer= new ArrayList<Object>();}
|
||||
|
||||
@@ -32,6 +32,8 @@ public interface Interface{
|
||||
|
||||
public interface InstrVisitor<H,S>{
|
||||
public S visitReturn(Return_instrImp instr, H h);
|
||||
public S visitBloc(BlocImp instr, H h);
|
||||
public S visitBlocDec (BlocDecImp instr, H h);
|
||||
public S visitAssign(AssignImp instr, H h);
|
||||
public S visitDeclaration(DeclarationImp instr,H h);
|
||||
public S visitPrint(PrintImp instr, H h);
|
||||
|
||||
@@ -43,6 +43,18 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
return indent+"RETURN " + instr.e().accept(this,"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitBloc(BlocImp instr, String h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitBloc'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitBlocDec(BlocDecImp instr, String h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitBlocDec'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitAssign(AssignImp instr, String indent) {
|
||||
return indent + instr.t()+ " := " + instr.e().accept(this,"");
|
||||
|
||||
@@ -61,6 +61,18 @@ public class Program{
|
||||
}
|
||||
}
|
||||
|
||||
public static record BlocDecImp(Declaration e, ArrayList<Instruction> l) implements Instruction{
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitBlocDec(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
public static record BlocImp(ArrayList<Instruction> l) implements Instruction{
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitBloc(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
public static record AssignImp(String t, Expression e) implements Instruction{
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitAssign(this, h);
|
||||
|
||||
@@ -68,6 +68,18 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitBloc(BlocImp instr, SymTable h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitBloc'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitBlocDec(BlocDecImp instr, SymTable h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitBlocDec'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitAssign(AssignImp instr, SymTable h) {
|
||||
InstrAndVal res = instr.e().accept(this,h);
|
||||
|
||||
Reference in New Issue
Block a user