fix proto again
This commit is contained in:
@@ -22,26 +22,9 @@ options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
program returns [ProgramImp p] :
|
program returns [ProgramImp p] :
|
||||||
pro=prototypes
|
|
||||||
func=functions
|
func=functions
|
||||||
EOF
|
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]
|
liste_param returns [ArrayList<VarImp> out]
|
||||||
@@ -58,9 +41,21 @@ functions returns [ArrayList<Function> out]
|
|||||||
@init{
|
@init{
|
||||||
$out = new ArrayList<Function>();
|
$out = new ArrayList<Function>();
|
||||||
}:
|
}:
|
||||||
|
(
|
||||||
(function {
|
(function {
|
||||||
$out.add($function.out);
|
$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 returns [Function out]:
|
||||||
|
|||||||
@@ -18,11 +18,6 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
|||||||
@Override
|
@Override
|
||||||
public String visitProgram(ProgramImp prog, String indent) {
|
public String visitProgram(ProgramImp prog, String indent) {
|
||||||
String str ="";
|
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++){
|
for(int i = 0; i<prog.fonctions().size(); i++){
|
||||||
str += prog.fonctions().get(i).accept(this,INDENT);
|
str += prog.fonctions().get(i).accept(this,INDENT);
|
||||||
if(i<prog.fonctions().size()-1) str += "\n";
|
if(i<prog.fonctions().size()-1) str += "\n";
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import TP2.llvm.ProgramLLVM.*;
|
|||||||
public class Program{
|
public class Program{
|
||||||
|
|
||||||
//Prog
|
//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) {
|
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
|
||||||
return v.visitProgram(this, h);
|
return v.visitProgram(this, h);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,3 +17,5 @@ FUNC INT main(x,y) {
|
|||||||
FI
|
FI
|
||||||
b:=c+1
|
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