Commit 5d754ed2 authored by Sarah Grebing's avatar Sarah Grebing

variable assignment

parent c2c8707a
......@@ -4,10 +4,14 @@ import edu.kit.formal.proofscriptparser.ScriptLanguageParser;
import edu.kit.formal.proofscriptparser.ScriptLanguageVisitor;
import edu.kit.formatl.proofscriptparser.ast.*;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.*;
import sun.net.idn.Punycode;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.RuleNode;
import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Alexander Weigl
......@@ -39,8 +43,20 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
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) {
throw new IllegalStateException("not implemented");
VariableDeclaration varDecl = new VariableDeclaration();
varDecl.setIdentifier(new Variable(ctx.name));
varDecl.setType(findType(ctx.type.getText()));
return varDecl;
}
@Override public Statements visitStmtList(ScriptLanguageParser.StmtListContext ctx) {
......
......@@ -44,4 +44,6 @@ public interface Visitor<T> {
T visit(Parameters parameters);
T visit(UnaryExpression unaryExpression);
T visit(VariableDeclaration variableDeclaration);
}
package edu.kit.formatl.proofscriptparser.ast;
/**
* Created by sarah on 4/30/17.
*/
public enum Type {
INT("int"), BOOL("bool");
private final String symbol;
Type(String symbol) {
this.symbol = symbol;
}
public String symbol() {
return symbol;
}
}
package edu.kit.formatl.proofscriptparser.ast;
import edu.kit.formal.proofscriptparser.ScriptLanguageParser;
import edu.kit.formatl.proofscriptparser.Visitor;
/**
* Created by sarah on 4/30/17.
*/
public class VariableDeclaration extends ASTNode<ScriptLanguageParser.VarDeclContext> {
private Variable identifier;
private Type type;
public VariableDeclaration setType(Type type){
this.type = type;
return this;
}
public VariableDeclaration setIdentifier(Variable id){
this.identifier = id;
return this;
}
@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this);
}
@Override
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