Commit 105b4780 authored by Lulu Luong's avatar Lulu Luong

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	rt/src/main/java/edu/kit/iti/formal/psdbg/interpreter/Evaluator.java
#	ui/src/main/java/edu/kit/iti/formal/psdbg/gui/controls/ScriptArea.java
parents de3bd0cf 72f657b2
...@@ -27,6 +27,13 @@ subprojects { ...@@ -27,6 +27,13 @@ subprojects {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
} }
task printClasspath {
doLast {// sourceSets.test.runtimeClasspath.
sourceSets.test.runtimeClasspath.each {println it}
}
}
dependencies { dependencies {
compile group: 'commons-cli', name: 'commons-cli', version: '1.4' compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
......
Subproject commit fb865a833c618c3a24dddfe08b2e05d76b7a450e
...@@ -33,9 +33,18 @@ statement ...@@ -33,9 +33,18 @@ statement
| scriptCommand | scriptCommand
| unconditionalBlock | unconditionalBlock
| conditionalBlock | conditionalBlock
| letStmt
// | callStmt // | callStmt
; ;
letStmt
:
'bind' expression
( SEMICOLON
| 'in' ( statement | INDENT stmtList DEDENT)
)
;
/*scriptDecl /*scriptDecl
: :
SCRIPT name=ID '(' signature=argList? ')' INDENT body=stmtList DEDENT SCRIPT name=ID '(' signature=argList? ')' INDENT body=stmtList DEDENT
...@@ -57,7 +66,6 @@ expression ...@@ -57,7 +66,6 @@ expression
| expression AND expression #exprAnd | expression AND expression #exprAnd
| expression OR expression #exprOr | expression OR expression #exprOr
| expression IMP expression #exprIMP | expression IMP expression #exprIMP
| expression USING LBRACKET argList RBRACKET #namespaceset
//| expression EQUIV expression already covered by EQ/NEQ //| expression EQUIV expression already covered by EQ/NEQ
| expression LBRACKET substExpressionList RBRACKET #exprSubst | expression LBRACKET substExpressionList RBRACKET #exprSubst
| ID LPAREN (expression (',' expression)*)? RPAREN #function | ID LPAREN (expression (',' expression)*)? RPAREN #function
......
...@@ -59,10 +59,6 @@ public class ASTChanger extends DefaultASTVisitor<ASTNode> { ...@@ -59,10 +59,6 @@ public class ASTChanger extends DefaultASTVisitor<ASTNode> {
@Override @Override
public MatchExpression visit(MatchExpression match) { public MatchExpression visit(MatchExpression match) {
if (match.getSignature() != null)
match.setSignature((Signature)
match.getSignature().accept(this));
match.setPattern((Expression) match.getPattern().accept(this)); match.setPattern((Expression) match.getPattern().accept(this));
return match; return match;
} }
......
...@@ -95,7 +95,6 @@ public interface ASTTraversal<T> extends Visitor<T> { ...@@ -95,7 +95,6 @@ public interface ASTTraversal<T> extends Visitor<T> {
@Override @Override
default T visit(MatchExpression match) { default T visit(MatchExpression match) {
match.getPattern().accept(this); match.getPattern().accept(this);
match.getSignature().accept(this);
return null; return null;
} }
...@@ -265,9 +264,9 @@ public interface ASTTraversal<T> extends Visitor<T> { ...@@ -265,9 +264,9 @@ public interface ASTTraversal<T> extends Visitor<T> {
} }
@Override @Override
default T visit(NamespaceSetExpression nss) { default T visit(LetStatement let) {
nss.getExpression().accept(this); let.getExpression().accept(this);
nss.getSignature().accept(this); let.getBody().accept(this);
return null; return null;
} }
} }
...@@ -178,8 +178,8 @@ public class DefaultASTVisitor<T> implements Visitor<T> { ...@@ -178,8 +178,8 @@ public class DefaultASTVisitor<T> implements Visitor<T> {
} }
@Override @Override
public T visit(NamespaceSetExpression nss) { public T visit(LetStatement let) {
return defaultVisit(nss); return defaultVisit(let);
} }
} }
...@@ -123,7 +123,7 @@ public class PrettyPrinter extends DefaultASTVisitor<Void> { ...@@ -123,7 +123,7 @@ public class PrettyPrinter extends DefaultASTVisitor<Void> {
s.append("match "); s.append("match ");
String prefix = getWhitespacePrefix(); String prefix = getWhitespacePrefix();
match.getPattern().accept(this); match.getPattern().accept(this);
if (!match.getSignature().isEmpty()) { /*if (!match.getSignature().isEmpty()) {
if (getCurrentLineLength() > maxWidth) { if (getCurrentLineLength() > maxWidth) {
s.append("\n").append(prefix); s.append("\n").append(prefix);
...@@ -134,7 +134,7 @@ public class PrettyPrinter extends DefaultASTVisitor<Void> { ...@@ -134,7 +134,7 @@ public class PrettyPrinter extends DefaultASTVisitor<Void> {
s.append("using ["); s.append("using [");
match.getSignature().accept(this); match.getSignature().accept(this);
s.append("]"); s.append("]");
} }*/
return null; return null;
} }
......
package edu.kit.iti.formal.psdbg.parser; package edu.kit.iti.formal.psdbg.parser;
import edu.kit.iti.formal.psdbg.parser.ast.*; import edu.kit.iti.formal.psdbg.parser.ast.CallStatement;
import javafx.util.Pair; import edu.kit.iti.formal.psdbg.parser.ast.Parameters;
......
package edu.kit.iti.formal.psdbg.parser; package edu.kit.iti.formal.psdbg.parser;
/*- /*-
* #%L * #%L
* ProofScriptParser * ProofScriptParser
* %% * %%
* Copyright (C) 2017 Application-oriented Formal Verification * Copyright (C) 2017 Application-oriented Formal Verification
* %% * %%
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as * it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public * You should have received a copy of the GNU General Public
* License along with this program. If not, see * License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>. * <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L% * #L%
*/ */
import edu.kit.iti.formal.psdbg.parser.ast.*; import edu.kit.iti.formal.psdbg.parser.ast.*;
...@@ -29,6 +29,7 @@ import edu.kit.iti.formal.psdbg.parser.function.ScriptFunction; ...@@ -29,6 +29,7 @@ import edu.kit.iti.formal.psdbg.parser.function.ScriptFunction;
import edu.kit.iti.formal.psdbg.parser.types.TypeFacade; import edu.kit.iti.formal.psdbg.parser.types.TypeFacade;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.val;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode; import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTree;
...@@ -163,6 +164,26 @@ public class TransformAst implements ScriptLanguageVisitor<Object> { ...@@ -163,6 +164,26 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return ctx.getChild(0).accept(this); return ctx.getChild(0).accept(this);
} }
@Override
public Object visitLetStmt(ScriptLanguageParser.LetStmtContext ctx) {
LetStatement lst = new LetStatement();
lst.setRuleContext(ctx);
lst.setExpression((Expression) ctx.expression().accept(this));
lst.getExpression().setParent(lst);
if (ctx.statement() != null) {
val stmt = (Statement) ctx.statement().accept(this);
Statements stmts = new Statements();
stmts.add(stmt);
lst.setBody(stmts);
stmts.setParent(lst);
}
if (ctx.stmtList() != null) {
lst.setBody((Statements) ctx.stmtList().accept(this));
lst.getBody().setParent(lst);
}
return lst;
}
@Override @Override
public Object visitAssignment(ScriptLanguageParser.AssignmentContext ctx) { public Object visitAssignment(ScriptLanguageParser.AssignmentContext ctx) {
AssignmentStatement assign = new AssignmentStatement(); AssignmentStatement assign = new AssignmentStatement();
...@@ -245,14 +266,6 @@ public class TransformAst implements ScriptLanguageVisitor<Object> { ...@@ -245,14 +266,6 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return ctx.matchPattern().accept(this); return ctx.matchPattern().accept(this);
} }
@Override
public Object visitNamespaceset(ScriptLanguageParser.NamespacesetContext ctx) {
NamespaceSetExpression nse = new NamespaceSetExpression();
nse.setExpression((Expression) ctx.expression().accept(this));
nse.setSignature((Signature) ctx.argList().accept(this));
return nse;
}
@Override @Override
public Object visitExprIMP(ScriptLanguageParser.ExprIMPContext ctx) { public Object visitExprIMP(ScriptLanguageParser.ExprIMPContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), Operator.IMPLICATION); return createBinaryExpression(ctx, ctx.expression(), Operator.IMPLICATION);
...@@ -363,11 +376,6 @@ public class TransformAst implements ScriptLanguageVisitor<Object> { ...@@ -363,11 +376,6 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
e.setParent(match); e.setParent(match);
match.setDerivableTerm(e); match.setDerivableTerm(e);
} else { } else {
if (ctx.argList() != null) {
Signature signature = (Signature) ctx.argList().accept(this);
match.setSignature(signature);
signature.setParent(match);
}
Expression<ParserRuleContext> e = (Expression<ParserRuleContext>) ctx.pattern.accept(this); Expression<ParserRuleContext> e = (Expression<ParserRuleContext>) ctx.pattern.accept(this);
match.setPattern(e); match.setPattern(e);
e.setParent(match); e.setParent(match);
......
...@@ -90,5 +90,5 @@ public interface Visitor<T> { ...@@ -90,5 +90,5 @@ public interface Visitor<T> {
T visit(RelaxBlock relaxBlock); T visit(RelaxBlock relaxBlock);
T visit(NamespaceSetExpression nss); T visit(LetStatement let);
} }
...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast;
* it under the terms of the GNU General Public License as * it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public * You should have received a copy of the GNU General Public
* License along with this program. If not, see * License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>. * <http://www.gnu.org/licenses/gpl-3.0.html>.
...@@ -25,12 +25,13 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -25,12 +25,13 @@ package edu.kit.iti.formal.psdbg.parser.ast;
import edu.kit.iti.formal.psdbg.parser.Visitable; import edu.kit.iti.formal.psdbg.parser.Visitable;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.val;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -47,7 +48,9 @@ public abstract class ASTNode<T extends ParserRuleContext> ...@@ -47,7 +48,9 @@ public abstract class ASTNode<T extends ParserRuleContext>
/** /**
* *
*/ */
@Getter @Setter @Nullable @Getter
@Setter
@Nullable
protected ASTNode parent; protected ASTNode parent;
/** /**
...@@ -116,7 +119,7 @@ public abstract class ASTNode<T extends ParserRuleContext> ...@@ -116,7 +119,7 @@ public abstract class ASTNode<T extends ParserRuleContext>
@Override @Override
public abstract ASTNode<T> copy(); public abstract ASTNode<T> copy();
public boolean isAncestor(ASTNode node){ public boolean isAncestor(ASTNode node) {
ASTNode n = this; ASTNode n = this;
do { do {
if (n.equals(node)) if (n.equals(node))
...@@ -140,6 +143,17 @@ public abstract class ASTNode<T extends ParserRuleContext> ...@@ -140,6 +143,17 @@ public abstract class ASTNode<T extends ParserRuleContext>
return depth; return depth;
} }
public ASTNode[] getChildren() {
return new ASTNode[0];
}
public final ASTNode[] asList() {
val ary = getChildren();
val nry = Arrays.copyOf(ary, ary.length + 1);
nry[nry.length - 1] = this;
return nry;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
...@@ -152,4 +166,12 @@ public abstract class ASTNode<T extends ParserRuleContext> ...@@ -152,4 +166,12 @@ public abstract class ASTNode<T extends ParserRuleContext>
public int hashCode() { public int hashCode() {
return Objects.hash(getRuleContext()); return Objects.hash(getRuleContext());
} }
public int getSyntaxWidth() {
if (ruleContext != null) {
return ruleContext.stop.getStopIndex()
- ruleContext.start.getStartIndex();
}
return -1;
}
} }
...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast;
* it under the terms of the GNU General Public License as * it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public * You should have received a copy of the GNU General Public
* License along with this program. If not, see * License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>. * <http://www.gnu.org/licenses/gpl-3.0.html>.
...@@ -23,7 +23,6 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -23,7 +23,6 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/ */
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser; import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import edu.kit.iti.formal.psdbg.parser.types.Type; import edu.kit.iti.formal.psdbg.parser.types.Type;
...@@ -74,6 +73,10 @@ public class AssignmentStatement ...@@ -74,6 +73,10 @@ public class AssignmentStatement
return type != null; return type != null;
} }
@Override
public ASTNode[] getChildren() {
return new ASTNode[]{getLhs(), getRhs()};
}
@Override @Override
public boolean eq(ASTNode o) { public boolean eq(ASTNode o) {
......
...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast;
* it under the terms of the GNU General Public License as * it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public * You should have received a copy of the GNU General Public
* License along with this program. If not, see * License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>. * <http://www.gnu.org/licenses/gpl-3.0.html>.
...@@ -47,6 +47,11 @@ public class BinaryExpression extends Expression<ParserRuleContext> { ...@@ -47,6 +47,11 @@ public class BinaryExpression extends Expression<ParserRuleContext> {
this.right = right; this.right = right;
} }
@Override
public ASTNode[] getChildren() {
return new ASTNode[]{getLeft(), getRight()};
}
@Override @Override
public <T> T accept(Visitor<T> visitor) { public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this); return visitor.visit(this);
......
...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast;
* it under the terms of the GNU General Public License as * it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public * You should have received a copy of the GNU General Public
* License along with this program. If not, see * License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>. * <http://www.gnu.org/licenses/gpl-3.0.html>.
...@@ -23,7 +23,6 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -23,7 +23,6 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/ */
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser; import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor; import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.*; import lombok.*;
...@@ -58,6 +57,11 @@ public class CallStatement extends Statement<ScriptLanguageParser.ScriptCommandC ...@@ -58,6 +57,11 @@ public class CallStatement extends Statement<ScriptLanguageParser.ScriptCommandC
return visitor.visit(this); return visitor.visit(this);
} }
@Override
public ASTNode[] getChildren() {
return new ASTNode[]{getParameters()};
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast;
* it under the terms of the GNU General Public License as * it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public * You should have received a copy of the GNU General Public
* License along with this program. If not, see * License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>. * <http://www.gnu.org/licenses/gpl-3.0.html>.
...@@ -44,14 +44,21 @@ public abstract class CaseStatement extends Statement<ScriptLanguageParser.Cases ...@@ -44,14 +44,21 @@ public abstract class CaseStatement extends Statement<ScriptLanguageParser.Cases
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override public <T> T accept(Visitor<T> visitor) { @Override
public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this); return visitor.visit(this);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override public abstract CaseStatement copy(); @Override
public abstract CaseStatement copy();
@Override
public ASTNode[] getChildren() {
return new ASTNode[]{getBody()};
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
...@@ -63,5 +70,4 @@ public abstract class CaseStatement extends Statement<ScriptLanguageParser.Cases ...@@ -63,5 +70,4 @@ public abstract class CaseStatement extends Statement<ScriptLanguageParser.Cases
return getBody().eq(that.getBody()); return getBody().eq(that.getBody());
} }
} }
...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast; ...@@ -10,12 +10,12 @@ package edu.kit.iti.formal.psdbg.parser.ast;
* it under the terms of the GNU General Public License as * it under the terms of the GNU General Public License as