Search in sources :

Example 36 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class InjectionOnSugar method injectionCatch.

private List<Expression.Catch> injectionCatch(List<ast.ExpCore.Block.On> list) {
    if (list.isEmpty()) {
        return Collections.emptyList();
    }
    List<Expression.Catch> ks = new ArrayList<>();
    for (ast.ExpCore.Block.On on : list) {
        Expression inner = lift(on.getInner());
        ks.add(new Expression.Catch1(on.getP(), on.getKind(), on.getT(), on.getX(), inner));
    }
    return ks;
}
Also used : Expression(ast.Expression) ArrayList(java.util.ArrayList) Block(ast.ExpCore.Block)

Example 37 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class Parser method parse.

public static synchronized Expression parse(String fileName, String s) {
    String old = Parser.fileName;
    Parser.fileName = fileName;
    try {
        checkForTab(s);
        checkForBalancedParenthesis(s);
        s = replaceORoundWithTab(s);
        NudeEContext ctxResult = parseCtx(s);
        Expression result = ctxResult.accept(new ToAst());
        return result;
    } finally {
        Parser.fileName = old;
    }
}
Also used : NudeEContext(antlrGenerated.L42Parser.NudeEContext) ToAst(sugarVisitors.ToAst) Expression(ast.Expression)

Example 38 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class OnLineCodeHelper method load.

private static Expression load(String name) {
    //URL res = OnLineCode.class.getResource(name+".L42");
    //Path res = L42.path.resolve(name+".L42");
    Path res = Paths.get("localhost", name + ".L42");
    assert res != null : name;
    String s = L42.pathToString(res);
    Expression e = Parser.parse(res.toString(), s);
    assert WellFormedness.checkAll(e);
    return e;
}
Also used : Path(java.nio.file.Path) Expression(ast.Expression)

Example 39 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class ErrorFormatter method errorFormat.

public static String errorFormat(Object obj, ArrayList<Ast.Position> ps) {
    if (obj instanceof ast.Ast.HasPos) {
        ps.add(((ast.Ast.HasPos) obj).getP());
    }
    if (obj instanceof String) {
        return (String) obj;
    }
    if (obj instanceof Integer) {
        return obj.toString();
    }
    if (obj instanceof Expression) {
        Ast.Position p = CollapsePositions.of((Expression) obj);
        ps.add(p);
        return ToFormattedText.ofCompact((Expression) obj);
    }
    if (obj instanceof ExpCore) {
        //thanks to Path, this have to be after Expression
        Ast.Position p = CollapsePositions.of((ExpCore) obj);
        ps.add(p);
        ExpCore exp = (ExpCore) obj;
        Expression expression = exp.accept(new InjectionOnSugar());
        return errorFormat(expression, ps);
    }
    if (obj instanceof Ast.MethodSelector) {
        return formatSelectorCompact((Ast.MethodSelector) obj);
    }
    if (obj instanceof ExpCore.ClassB.MethodWithType) {
        return ToFormattedText.of((MethodWithType) obj).trim().replace("\n", " ");
    }
    //    }
    if (obj instanceof Reporter) {
        return ((Reporter) obj).toReport(ps);
    }
    if (obj instanceof Collection<?>) {
        Collection<?> c = (Collection<?>) obj;
        if (c.size() == 0) {
            return "[]";
        }
        if (c.size() == 1) {
            return "[" + errorFormat(c.iterator().next(), ps) + "]";
        }
        String res = "[\n";
        for (Object o : c) {
            res += "  " + errorFormat(o, ps) + "\n";
        }
        return res + "  ]\n";
    }
    if (obj instanceof Ast.Type) {
        return obj.toString();
    }
    if (obj instanceof ClassB.Member) {
        return ToFormattedText.of((ClassB.Member) obj);
    }
    //if(obj instanceof Expression){return ToFormattedText.of((Expression)obj);}
    if (obj instanceof Expression.ClassB.Member) {
        return ToFormattedText.of((Expression.ClassB.Member) obj);
    }
    if (obj instanceof java.nio.file.Path) {
        return obj.toString();
    }
    if (obj instanceof Ast.Position) {
        return obj.toString();
    }
    if (obj instanceof HashMap) {
        return obj.toString();
    }
    if (obj instanceof Collection) {
        return obj.toString();
    }
    if (obj instanceof ast.Util.PathMwt) {
        return obj.toString();
    }
    if (obj instanceof ast.Ast.C) {
        return obj.toString();
    }
    if (obj instanceof Boolean) {
        return obj.toString();
    }
    if (obj instanceof ast.Ast.Path) {
        return obj.toString();
    }
    return "unknown kind " + obj.getClass().getName();
}
Also used : Position(ast.Ast.Position) HashMap(java.util.HashMap) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) Path(ast.Ast.Path) ExpCore(ast.ExpCore) Ast(ast.Ast) Position(ast.Ast.Position) MethodWithType(ast.ExpCore.ClassB.MethodWithType) InjectionOnSugar(coreVisitors.InjectionOnSugar) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Expression(ast.Expression) Collection(java.util.Collection)

Example 40 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class L42 method runSlow.

public static ErrorMessage.FinalResult runSlow(String fileName, String code) {
    try {
        L42.setExecutionStage(ExecutionStage.Parsing);
        Expression code1 = Parser.parse(fileName, code);
        assert code1 instanceof Expression.ClassB || code1 instanceof Expression.ClassReuse;
        L42.setExecutionStage(ExecutionStage.CheckingWellFormedness);
        auxiliaryGrammar.WellFormedness.checkAll(code1);
        L42.setExecutionStage(ExecutionStage.Desugaring);
        Expression code2 = Desugar.of(code1);
        assert auxiliaryGrammar.WellFormedness.checkAll(code2);
        ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
        assert coreVisitors.CheckNoVarDeclaredTwice.of(code3);
        // L42.usedNames.addAll(CollectDeclaredVarsAndCheckNoDeclaredTwice.of(code2));
        //L42.usedNames.addAll(CollectDeclaredClassNamesAndMethodNames.of(code2));
        L42.setExecutionStage(ExecutionStage.MetaExecution);
        //ClassB result= (ClassB)Executor.stepStar(exe,code3);
        //Refresh of position identities, it is used to generate correct Java code.
        code3 = (ClassB) code3.accept(new CloneVisitor() {

            @Override
            public ExpCore visit(ClassB cb) {
                Position p = cb.getP();
                cb = cb.withP(new Position(p.getFile(), p.getLine1(), p.getPos1(), p.getLine2(), p.getPos2(), p.get_next()));
                return super.visit(cb);
            }
        });
        //ClassB result= Configuration.reduction.of(code3);
        ClassB result = ProgramReduction.allSteps(code3);
        //System.out.println("--------------------------");
        return checkFinalError(result);
    } finally {
        L42.setExecutionStage(ExecutionStage.None);
    }
}
Also used : ExpCore(ast.ExpCore) Expression(ast.Expression) Position(ast.Ast.Position) CloneVisitor(coreVisitors.CloneVisitor) ClassB(ast.ExpCore.ClassB) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Aggregations

Expression (ast.Expression)66 ArrayList (java.util.ArrayList)24 VarDec (ast.Ast.VarDec)14 X (ast.Expression.X)13 Type (ast.Ast.Type)11 VarDecXE (ast.Ast.VarDecXE)11 ExpCore (ast.ExpCore)11 Catch (ast.Expression.Catch)11 RoundBlock (ast.Expression.RoundBlock)11 VarDecE (ast.Ast.VarDecE)10 Doc (ast.Ast.Doc)8 Position (ast.Ast.Position)8 MethodSelectorX (ast.Ast.MethodSelectorX)7 Parameters (ast.Ast.Parameters)7 MethodWithType (ast.Expression.ClassB.MethodWithType)7 MethodType (ast.Ast.MethodType)6 ClassB (ast.ExpCore.ClassB)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 Path (ast.Ast.Path)4