Merge branch 'main' of https://gitlab2.istic.univ-rennes1.fr/tuvu/tp2-vsl-pds
This commit is contained in:
@@ -108,7 +108,7 @@ public class VSLParser extends Parser {
|
||||
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
public static class ProgramContext extends ParserRuleContext {
|
||||
public Program p;
|
||||
public ProgramImp p;
|
||||
public FunctionContext func;
|
||||
public TerminalNode EOF() { return getToken(VSLParser.EOF, 0); }
|
||||
public FunctionContext function() {
|
||||
@@ -130,7 +130,7 @@ public class VSLParser extends Parser {
|
||||
((ProgramContext)_localctx).func = function();
|
||||
setState(21);
|
||||
match(EOF);
|
||||
((ProgramContext)_localctx).p = new Program(((ProgramContext)_localctx).func.out);
|
||||
((ProgramContext)_localctx).p = new ProgramImp(((ProgramContext)_localctx).func.out);
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
@@ -146,7 +146,7 @@ public class VSLParser extends Parser {
|
||||
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
public static class FunctionContext extends ParserRuleContext {
|
||||
public List<Function> out;
|
||||
public ArrayList<Function> out;
|
||||
public TypeContext t;
|
||||
public IdentContext i;
|
||||
public List_instrContext instrs;
|
||||
|
||||
@@ -21,14 +21,14 @@ options {
|
||||
}
|
||||
}
|
||||
|
||||
program returns [Program p] :
|
||||
program returns [ProgramImp p] :
|
||||
func=function
|
||||
EOF
|
||||
{$p = new Program($func.out);}
|
||||
{$p = new ProgramImp($func.out);}
|
||||
;
|
||||
|
||||
|
||||
function returns [List<Function> out]
|
||||
function returns [ArrayList<Function> out]
|
||||
@init{
|
||||
SymTable sym_table = new SymTable();
|
||||
}:
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.antlr.runtime.CharStream;
|
||||
import org.antlr.runtime.CommonTokenStream;
|
||||
import org.antlr.runtime.RecognitionException;
|
||||
|
||||
import TP2.asd.*;
|
||||
import TP2.asd.Program.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
@@ -32,7 +32,7 @@ public class Main {
|
||||
VSLParser parser = new VSLParser(tokens);
|
||||
|
||||
// Parse
|
||||
ProgramImpl ast = parser.program();
|
||||
ProgramImp ast = parser.program();
|
||||
|
||||
// Pretty-print the program (to debug parsing)
|
||||
System.err.println("todo " + ast);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package TP2.asd;
|
||||
|
||||
import java.util.Map;
|
||||
import TP2.asd.Program.*;
|
||||
|
||||
public interface Interface{
|
||||
public interface Expression {
|
||||
@@ -12,17 +13,17 @@ public interface Interface{
|
||||
}
|
||||
|
||||
public interface ProgramVisitor<H,S> {
|
||||
public S visitProgram(Program p, H h);
|
||||
public S visitFunction(Program.Function f, H h);
|
||||
public S visitProgram(ProgramImp p, H h);
|
||||
public S visitFunction(Function f, H h);
|
||||
}
|
||||
|
||||
public interface InstrVisitor<H,S>{
|
||||
public S visitReturn(Program.Return_instr e, H h);
|
||||
public S visitReturn(Return_instr e, H h);
|
||||
}
|
||||
|
||||
public interface ExprVisitor<H,S> {
|
||||
public S visitConst(Program.Const e,H h);
|
||||
public S visitBinOp(Program.BinopExpression e, H h);
|
||||
public S visitConst(Const e,H h);
|
||||
public S visitBinOp(BinopExpression e, H h);
|
||||
}
|
||||
|
||||
public interface Type{
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
package TP2.asd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import TP2.asd.Interface.*;
|
||||
|
||||
public class Program{
|
||||
public static record ProgramImp(ArrayList<Instruction> instructions){
|
||||
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
|
||||
return v.visitProgram(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
public static record Function(Type type, String nom, ArrayList<Instruction> instructions){
|
||||
public Function(Type type, String name, Instruction instruction) {
|
||||
this(type, name, new ArrayList<>() {{ add(instruction); }});
|
||||
|
||||
Reference in New Issue
Block a user