fix proto again
This commit is contained in:
@@ -22,28 +22,11 @@ options {
|
||||
}
|
||||
|
||||
program returns [ProgramImp p] :
|
||||
pro=prototypes
|
||||
func=functions
|
||||
EOF
|
||||
{$p = new ProgramImp($func.out,$pro.out);}
|
||||
{$p = new ProgramImp($func.out);}
|
||||
;
|
||||
|
||||
prototypes returns [ArrayList<Function> out]
|
||||
@init{
|
||||
$out = new ArrayList<Function>();
|
||||
}:
|
||||
(proto {
|
||||
$out.add($proto.out);
|
||||
})*
|
||||
;
|
||||
|
||||
proto returns [Function out]:
|
||||
PROTOTYPE t=type i=ident ParO v=liste_param ParF
|
||||
{
|
||||
$out=new PrototypeImp($t.return_type,$i.out, $v.out);
|
||||
}
|
||||
;
|
||||
|
||||
liste_param returns [ArrayList<VarImp> out]
|
||||
@init{
|
||||
$out = new ArrayList<VarImp>();
|
||||
@@ -58,11 +41,23 @@ functions returns [ArrayList<Function> out]
|
||||
@init{
|
||||
$out = new ArrayList<Function>();
|
||||
}:
|
||||
(
|
||||
(function {
|
||||
$out.add($function.out);
|
||||
})+
|
||||
})
|
||||
|(proto {
|
||||
$out.add($proto.out);
|
||||
})
|
||||
)+
|
||||
;
|
||||
|
||||
proto returns [Function out]:
|
||||
PROTOTYPE t=type i=ident ParO v=liste_param ParF
|
||||
{
|
||||
$out=new PrototypeImp($t.return_type,$i.out, $v.out);
|
||||
}
|
||||
;
|
||||
|
||||
function returns [Function out]:
|
||||
FUNCTION t=type i=ident ParO v=liste_param ParF instr= instruction
|
||||
{
|
||||
|
||||
@@ -18,11 +18,6 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
@Override
|
||||
public String visitProgram(ProgramImp prog, String indent) {
|
||||
String str ="";
|
||||
for(int i= 0; i<prog.protos().size();i++){
|
||||
str+=prog.protos().get(i).accept(this, INDENT);
|
||||
if(i<prog.protos().size()-1) str += "\n";
|
||||
}
|
||||
str+="\n";
|
||||
for(int i = 0; i<prog.fonctions().size(); i++){
|
||||
str += prog.fonctions().get(i).accept(this,INDENT);
|
||||
if(i<prog.fonctions().size()-1) str += "\n";
|
||||
|
||||
@@ -7,7 +7,7 @@ import TP2.llvm.ProgramLLVM.*;
|
||||
public class Program{
|
||||
|
||||
//Prog
|
||||
public static record ProgramImp(ArrayList<Function> fonctions,ArrayList<Function> protos) implements ProgramI{
|
||||
public static record ProgramImp(ArrayList<Function> fonctions) implements ProgramI{
|
||||
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
|
||||
return v.visitProgram(this, h);
|
||||
}
|
||||
|
||||
@@ -16,4 +16,6 @@ FUNC INT main(x,y) {
|
||||
THEN READ a ELSE READ b
|
||||
FI
|
||||
b:=c+1
|
||||
RETURN 4 + 6 * 5 + 2 }
|
||||
RETURN 4 + 6 * 5 + 2 }
|
||||
|
||||
PROTO INT type(x,y)
|
||||
Reference in New Issue
Block a user