Commit 78c231fe authored by Alexander Weigl's avatar Alexander Weigl

fix the merge errors

parent 16848e62
......@@ -24,7 +24,8 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return scripts;
}
@Override public ProofScript visitStart(ScriptLanguageParser.StartContext ctx) {
@Override
public ProofScript visitStart(ScriptLanguageParser.StartContext ctx) {
ProofScript s = new ProofScript();
s.setName(ctx.name.getText());
s.setRuleContext(ctx);
......@@ -35,32 +36,32 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return s;
}
@Override public Signature visitArgList(ScriptLanguageParser.ArgListContext ctx) {
@Override
public Signature visitArgList(ScriptLanguageParser.ArgListContext ctx) {
Signature signature = new Signature();
for (ScriptLanguageParser.VarDeclContext decl : ctx.varDecl()) {
signature.put(new Variable(decl.name), Type.valueOf(decl.type.getText()));
signature.put(new Variable(decl.name), Type.findType(decl.type.getText()));
}
return signature;
}
private Type findType(String n) {
for (Type t : Type.values()) {
if (t.symbol().equals(n))
return t;
}
throw new IllegalStateException("Type " + n + " not defined");
}
//TODO check
@Override public Object visitVarDecl(ScriptLanguageParser.VarDeclContext ctx) {
VariableDeclaration varDecl = new VariableDeclaration();
/**
* @param ctx the parse tree
* @return
* @deprecated not needed, handled in {@link #visitArgList(ScriptLanguageParser.ArgListContext)}
*/
@Override
public Object visitVarDecl(ScriptLanguageParser.VarDeclContext ctx) {
/* VariableDeclaration varDecl = new VariableDeclaration();
varDecl.setIdentifier(new Variable(ctx.name));
varDecl.setType(findType(ctx.type.getText()));
return varDecl;
varDecl.setType(Type.findType(ctx.type.getText()));
return varDecl;*/
return null;
}
@Override public Statements visitStmtList(ScriptLanguageParser.StmtListContext ctx) {
@Override
public Statements visitStmtList(ScriptLanguageParser.StmtListContext ctx) {
Statements statements = new Statements();
for (ScriptLanguageParser.StatementContext stmt : ctx.statement()) {
statements.add((Statement) stmt.accept(this));
......@@ -68,11 +69,13 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return statements;
}
@Override public Object visitStatement(ScriptLanguageParser.StatementContext ctx) {
@Override
public Object visitStatement(ScriptLanguageParser.StatementContext ctx) {
return ctx.getChild(0).accept(this);
}
@Override public Object visitAssignment(ScriptLanguageParser.AssignmentContext ctx) {
@Override
public Object visitAssignment(ScriptLanguageParser.AssignmentContext ctx) {
AssignmentStatement assign = new AssignmentStatement();
assign.setRuleContext(ctx);
assign.setRhs(new Variable(ctx.variable));
......@@ -80,12 +83,13 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return assign;
}
@Override public BinaryExpression visitExprMultiplication(ScriptLanguageParser.ExprMultiplicationContext ctx) {
@Override
public BinaryExpression visitExprMultiplication(ScriptLanguageParser.ExprMultiplicationContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), Operator.MULTIPLY);
}
private BinaryExpression createBinaryExpression(ParserRuleContext ctx,
List<ScriptLanguageParser.ExpressionContext> expression, Operator op) {
List<ScriptLanguageParser.ExpressionContext> expression, Operator op) {
BinaryExpression be = new BinaryExpression();
be.setLeft((Expression) expression.get(0).accept(this));
be.setRight((Expression) expression.get(1).accept(this));
......@@ -93,29 +97,26 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return be;
}
private UnaryExpression createUnaryExpression(ParserRuleContext ctx, ScriptLanguageParser.ExpressionContext expression, Operator op){
private UnaryExpression createUnaryExpression(ParserRuleContext ctx, ScriptLanguageParser.ExpressionContext expression, Operator op) {
UnaryExpression ue = new UnaryExpression();
ue.setRuleContext(ctx);
ue.setExpression((Expression) expression.accept(this));
ue.setOperator(op);
return ue;
}
@Override public Object visitExprMinus(ScriptLanguageParser.ExprMinusContext ctx) {
UnaryExpression ue = new UnaryExpression();
ue.setRuleContext(...);
ue.setOperator(Operator.MINUS);
ue.setExpression((Expression) ctx.expression().accept(this));
return ue;
@Override
public Object visitExprMinus(ScriptLanguageParser.ExprMinusContext ctx) {
return createUnaryExpression(ctx, ctx.expression(), Operator.NEGATE);
}
@Override public Object visitExprNegate(ScriptLanguageParser.ExprNegateContext ctx) {
UnaryExpression ue = new UnaryExpression();
ue.setOperator(Operator.NOT);
ue.setExpression((Expression) ctx.expression().accept(this));
return ue;
@Override
public Object visitExprNegate(ScriptLanguageParser.ExprNegateContext ctx) {
return createUnaryExpression(ctx, ctx.expression(), Operator.NOT);
}
@Override public Object visitExprComparison(ScriptLanguageParser.ExprComparisonContext ctx) {
@Override
public Object visitExprComparison(ScriptLanguageParser.ExprComparisonContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), findOperator(ctx.op.getText()));
}
......@@ -127,109 +128,128 @@ ue.setRuleContext(...);
throw new IllegalStateException("Operator " + n + " not defined");
}
@Override public Object visitExprEquality(ScriptLanguageParser.ExprEqualityContext ctx) {
@Override
public Object visitExprEquality(ScriptLanguageParser.ExprEqualityContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), findOperator(ctx.op.getText()));
}
@Override public Object visitExprMatch(ScriptLanguageParser.ExprMatchContext ctx) {
@Override
public Object visitExprMatch(ScriptLanguageParser.ExprMatchContext ctx) {
return ctx.matchPattern().accept(this);
}
@Override public Object visitExprIMP(ScriptLanguageParser.ExprIMPContext ctx) {
@Override
public Object visitExprIMP(ScriptLanguageParser.ExprIMPContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), Operator.IMPLICATION);
}
@Override public Object visitExprParen(ScriptLanguageParser.ExprParenContext ctx) {
@Override
public Object visitExprParen(ScriptLanguageParser.ExprParenContext ctx) {
return ctx.expression().accept(this);
}
@Override public Object visitExprOr(ScriptLanguageParser.ExprOrContext ctx) {
@Override
public Object visitExprOr(ScriptLanguageParser.ExprOrContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), Operator.OR);
}
@Override public Object visitExprLineOperators(ScriptLanguageParser.ExprLineOperatorsContext ctx) {
@Override
public Object visitExprLineOperators(ScriptLanguageParser.ExprLineOperatorsContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), findOperator(ctx.op.getText()));
}
@Override public Object visitExprAnd(ScriptLanguageParser.ExprAndContext ctx) {
@Override
public Object visitExprAnd(ScriptLanguageParser.ExprAndContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), Operator.AND);
}
@Override public Object visitExprLiterals(ScriptLanguageParser.ExprLiteralsContext ctx) {
@Override
public Object visitExprLiterals(ScriptLanguageParser.ExprLiteralsContext ctx) {
return ctx.literals().accept(this);
}
@Override public Object visitExprDivision(ScriptLanguageParser.ExprDivisionContext ctx) {
@Override
public Object visitExprDivision(ScriptLanguageParser.ExprDivisionContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), Operator.DIVISION);
}
@Override public Object visitLiteralID(ScriptLanguageParser.LiteralIDContext ctx) {
@Override
public Object visitLiteralID(ScriptLanguageParser.LiteralIDContext ctx) {
return new Variable(ctx.ID().getSymbol());
}
@Override public Object visitLiteralDigits(ScriptLanguageParser.LiteralDigitsContext ctx) {
@Override
public Object visitLiteralDigits(ScriptLanguageParser.LiteralDigitsContext ctx) {
return new IntegerLiteral(ctx.DIGITS().getSymbol());
}
@Override public Object visitLiteralTerm(ScriptLanguageParser.LiteralTermContext ctx) {
@Override
public Object visitLiteralTerm(ScriptLanguageParser.LiteralTermContext ctx) {
return new TermLiteral(ctx.getText());
}
@Override public Object visitLiteralString(ScriptLanguageParser.LiteralStringContext ctx) {
@Override
public Object visitLiteralString(ScriptLanguageParser.LiteralStringContext ctx) {
return new StringLiteral(ctx.getText());
}
@Override public Object visitLiteralTrue(ScriptLanguageParser.LiteralTrueContext ctx) {
@Override
public Object visitLiteralTrue(ScriptLanguageParser.LiteralTrueContext ctx) {
return new BooleanLiteral(false, ctx.TRUE().getSymbol());
}
@Override public Object visitLiteralFalse(ScriptLanguageParser.LiteralFalseContext ctx) {
@Override
public Object visitLiteralFalse(ScriptLanguageParser.LiteralFalseContext ctx) {
return new BooleanLiteral(false, ctx.FALSE().getSymbol());
}
@Override public Object visitMatchPattern(ScriptLanguageParser.MatchPatternContext ctx) {
@Override
public Object visitMatchPattern(ScriptLanguageParser.MatchPatternContext ctx) {
MatchExpression match = new MatchExpression();
match.setRuleContext(ctx);
match.setSignature((Signature) ctx.argList().accept(this));
if (ctx.TERM_LITERAL() != null) {
match.setTerm(new TermLiteral(ctx.TERM_LITERAL().getText()));
}
else {
} else {
match.setVariable(new Variable(ctx.ID().getSymbol()));
}
return match;
}
@Override public Object visitScriptVar(ScriptLanguageParser.ScriptVarContext ctx) {
@Override
public Object visitScriptVar(ScriptLanguageParser.ScriptVarContext ctx) {
throw new IllegalStateException("not implemented");
}
@Override public Object visitRepeatStmt(ScriptLanguageParser.RepeatStmtContext ctx) {
@Override
public Object visitRepeatStmt(ScriptLanguageParser.RepeatStmtContext ctx) {
RepeatStatement rs = new RepeatStatement();
rs.setRuleContext(ctx);
rs.setBody((Statements) ctx.stmtList().accept(this));
return rs;
}
@Override public Object visitCasesStmt(ScriptLanguageParser.CasesStmtContext ctx) {
@Override
public Object visitCasesStmt(ScriptLanguageParser.CasesStmtContext ctx) {
CasesStatement cases = new CasesStatement();
ctx.casesList().forEach(c -> cases.getCases().add((CaseStatement) c.accept(this)));
if (ctx.DEFAULT() != null) {
cases.setDefaultCase((Statements)
ctx.defList.accept(this)
ctx.defList.accept(this)
);
}
return cases;
}
@Override public Object visitCasesList(ScriptLanguageParser.CasesListContext ctx) {
@Override
public Object visitCasesList(ScriptLanguageParser.CasesListContext ctx) {
CaseStatement caseStatement = new CaseStatement();
caseStatement.setRuleContext(ctx);
caseStatement.setGuard((Expression) ctx.expression().accept(this));
......@@ -237,21 +257,24 @@ ue.setRuleContext(...);
return caseStatement;
}
@Override public Object visitForEachStmt(ScriptLanguageParser.ForEachStmtContext ctx) {
@Override
public Object visitForEachStmt(ScriptLanguageParser.ForEachStmtContext ctx) {
ForeachStatement f = new ForeachStatement();
f.setRuleContext(ctx);
f.setBody((Statements) ctx.stmtList().accept(this));
return f;
}
@Override public Object visitTheOnlyStmt(ScriptLanguageParser.TheOnlyStmtContext ctx) {
@Override
public Object visitTheOnlyStmt(ScriptLanguageParser.TheOnlyStmtContext ctx) {
TheOnlyStatement f = new TheOnlyStatement();
f.setRuleContext(ctx);
f.setBody((Statements) ctx.stmtList().accept(this));
return f;
}
@Override public Object visitScriptCommand(ScriptLanguageParser.ScriptCommandContext ctx) {
@Override
public Object visitScriptCommand(ScriptLanguageParser.ScriptCommandContext ctx) {
CallStatement scs = new CallStatement();
scs.setRuleContext(ctx);
scs.setCommand(ctx.cmd.getText());
......@@ -261,7 +284,8 @@ ue.setRuleContext(...);
return scs;
}
@Override public Object visitParameters(ScriptLanguageParser.ParametersContext ctx) {
@Override
public Object visitParameters(ScriptLanguageParser.ParametersContext ctx) {
Parameters params = new Parameters();
int i = 1;
for (ScriptLanguageParser.ParameterContext pc : ctx.parameter()) {
......@@ -272,23 +296,28 @@ ue.setRuleContext(...);
return params;
}
@Override public Object visitParameter(ScriptLanguageParser.ParameterContext ctx) {
@Override
public Object visitParameter(ScriptLanguageParser.ParameterContext ctx) {
return null;
}
@Override public Object visit(ParseTree parseTree) {
@Override
public Object visit(ParseTree parseTree) {
throw new IllegalStateException("not implemented");
}
@Override public Object visitChildren(RuleNode ruleNode) {
@Override
public Object visitChildren(RuleNode ruleNode) {
throw new IllegalStateException("not implemented");
}
@Override public Object visitTerminal(TerminalNode terminalNode) {
@Override
public Object visitTerminal(TerminalNode terminalNode) {
throw new IllegalStateException("not implemented");
}
@Override public Object visitErrorNode(ErrorNode errorNode) {
@Override
public Object visitErrorNode(ErrorNode errorNode) {
throw new IllegalStateException("not implemented");
}
}
......@@ -45,6 +45,6 @@ public class BooleanLiteral extends Literal {
@Override
public Type getType(Signature signature) throws NotWelldefinedException {
return Type.bool;
return Type.BOOL;
}
}
......@@ -40,7 +40,7 @@ public class IntegerLiteral extends Literal {
@Override
public Type getType(Signature signature) throws NotWelldefinedException {
return Type.integer;
return Type.INT;
}
......
......@@ -34,7 +34,7 @@ public class MatchExpression extends Expression<ScriptLanguageParser.MatchPatter
public Type getType(Signature signature) throws NotWelldefinedException {
if(term==null && variable==null)
throw new NotWelldefinedException("Missing parameter", this);
return Type.bool;
return Type.BOOL;
}
@Override public int getPrecedence() {
......
......@@ -12,43 +12,43 @@ public enum Operator {
/**
* special entry for marking match as an atomic expression.
*/
MATCH("match", 1000, bool),
MATCH("match", 1000, BOOL),
/**
*
*/
NOT("not", "¬", 10, bool, bool),
NOT("not", "¬", 10, BOOL, BOOL),
/** */
NEGATE("-", "-", 10, integer, integer),
NEGATE("-", "-", 10, INT, INT),
/** */
MULTIPLY("*", "×", 20, integer, integer, integer),
MULTIPLY("*", "×", 20, INT, INT, INT),
/** */
DIVISION("/", "÷", 20, integer, integer, integer),
DIVISION("/", "÷", 20, INT, INT, INT),
/** */
PLUS("+", 30, integer, integer, integer),
PLUS("+", 30, INT, INT, INT),
/** */
MINUS("-", 30, integer, integer, integer),
MINUS("-", 30, INT, INT, INT),
/** */
LE("<", 40, integer, integer, bool),
LE("<", 40, INT, INT, BOOL),
/** */
GE(">", 40, integer, integer, bool),
GE(">", 40, INT, INT, BOOL),
/** */
LEQ("<=", "≤", 40, integer, integer, bool),
LEQ("<=", "≤", 40, INT, INT, BOOL),
/** */
GEQ(">=", "≥", 40, integer, integer, bool),
GEQ(">=", "≥", 40, INT, INT, BOOL),
/** */
EQ("=", "≡", 50, integer, integer, bool),
EQ("=", "≡", 50, INT, INT, BOOL),
/** */
NEQ("<>", "≢", 50, integer, integer, bool),
NEQ("<>", "≢", 50, INT, INT, BOOL),
/** */
AND("&", "∧", 60, bool, bool, bool),
AND("&", "∧", 60, BOOL, BOOL, BOOL),
/** */
OR("|", "∨", 70, bool, bool, bool),
OR("|", "∨", 70, BOOL, BOOL, BOOL),
/** */
IMPLICATION("==>", "⇒", 80, bool, bool, bool),
IMPLICATION("==>", "⇒", 80, BOOL, BOOL, BOOL),
/**
*
* */
EQUIVALENCE("<=>", "⇔", 90, bool, bool, bool);
EQUIVALENCE("<=>", "⇔", 90, BOOL, BOOL, BOOL);
private final String symbol;
private final String unicode;
......
......@@ -26,6 +26,6 @@ public class StringLiteral extends Literal {
@Override
public Type getType(Signature signature) throws NotWelldefinedException {
return Type.string;
return Type.STRING;
}
}
......@@ -30,6 +30,6 @@ public class TermLiteral extends Literal {
@Override
public Type getType(Signature signature) throws NotWelldefinedException {
return Type.term;
return Type.TERM;
}
}
package edu.kit.formatl.proofscriptparser.ast;
import java.util.Arrays;
/**
* Created by sarah on 4/30/17.
*/
public enum Type {
bool, string, term, integer, any
STRING("string"), TERM("term"), ANY("any"),
INT("int"), BOOL("bool");
private final String symbol;
......@@ -12,7 +15,16 @@ public enum Type {
this.symbol = symbol;
}
public String symbol() {
public String symbol() {
return symbol;
}
public static Type findType(String n) {
for (Type t : Type.values()) {
if (t.symbol().equals(n))
return t;
}
throw new IllegalStateException("Type " + n + " is not defined. Valid types are: " + Arrays.toString(values()));
}
}
......@@ -6,8 +6,8 @@ import edu.kit.formatl.proofscriptparser.Visitor;
/**
* Created by sarah on 4/30/17.
*/
public class VariableDeclaration extends ASTNode<ScriptLanguageParser.VarDeclContext> {
private Variable identifier;
public class VariableDeclaration {//extends ASTNode<ScriptLanguageParser.VarDeclContext> {
/* private Variable identifier;
private Type type;
public VariableDeclaration setType(Type type){
......@@ -29,4 +29,4 @@ public class VariableDeclaration extends ASTNode<ScriptLanguageParser.VarDeclCon
public ASTNode<ScriptLanguageParser.VarDeclContext> clone() {
return null;
}
}
*/}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment