public int Interpret() { IAST tree = this._parser.Parse(); IAST result = this._visitor.ReduceTree(tree); return(result.Token.Value); }
public IfElse(IAST exp, IAST b1, IAST b2) { expression = exp; block1 = b1; block2 = b2; output = null; }
public ForStatement(string iter, string counter, IAST iterable, Block body) { this.iter = iter; this.counter = counter; this.iterable = iterable; this.body = body; }
public BinOp(IAST l, Token t, IAST r) { left = l; op = t.getValue(); right = r; output = null; }
public MiniPLInterpreter(string sampleProgram, ISymbolTable symbolTable, IInputOutput io) { this.sampleProgram = sampleProgram; this.io = io; this.ast = null; this.symbolTable = symbolTable; }
private Right right() { lexer.consume(); IAST exp = expression(); return(new Right(exp)); }
private Left left() { lexer.consume(); IAST exp = expression(); return(new Left(exp)); }
private Forward forward() { lexer.consume(); IAST exp = expression(); return(new Forward(exp)); }
public void checkASTexists() { this.parser.processAndBuildAST(); IAST ast = this.parser.getAST(); Assert.True(ast != null); }
private BackWard backWard() { lexer.consume(); IAST exp = expression(); return(new BackWard(exp)); }
public void sampleProgramShouldBeAnalyzedCorrectly() { Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.True(this.analyzer.analyze(ast, this.symbolTable)); }
public AssignOp(Var l, Type t, IAST r) { left = l; type = t; right = r; output = null; }
public void assigningValuesForControlVariablesShouldBeIllegalInsideForLoops(string source) { this.parser = TestHelpers.getParser(source); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.Throws <SemanticException>(() => this.analyzer.analyze(ast, this.symbolTable)); }
public void twoSameVariablesCantBeDeclared() { this.parser = TestHelpers.getParser("var x : int; var x : string;"); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.Throws <SemanticException>(() => this.analyzer.analyze(ast, this.symbolTable)); }
private SetPos setPos() { lexer.consume(); IAST exp1 = expression(); IAST exp2 = expression(); return(new SetPos(exp1, exp2)); }
public void semanticsShouldBeOkInAssertStatementForBoolVariables(string source) { this.parser = TestHelpers.getParser(source); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.True(this.analyzer.analyze(ast, this.symbolTable)); }
public void forLoopShouldThrowAnExceptionWithWrongTypesOrMissingDeclarations(string source) { this.parser = TestHelpers.getParser(source); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.Throws <SemanticException>(() => this.analyzer.analyze(ast, this.symbolTable)); }
public void checkCorrectTypeInForLoopsRangeOperator(string source) { this.parser = TestHelpers.getParser(source); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.True(this.analyzer.analyze(ast, this.symbolTable)); }
public void variableAssignmentShouldBeOkWithCorrectTypes(string source) { this.parser = TestHelpers.getParser(source); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.True(this.analyzer.analyze(ast, this.symbolTable)); }
public void analyzeShouldThrowSemanticExceptionWithUsageOfWrongTypes(string source) { this.parser = TestHelpers.getParser(source); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.Throws <SemanticException>(() => this.analyzer.analyze(ast, this.symbolTable)); }
public void analyzeShouldFinishWithDifferentLegalTypes(string source) { this.parser = TestHelpers.getParser(source); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.True(this.analyzer.analyze(ast, this.symbolTable)); }
public void assertingUndeclaredVariableShouldThrowException(string source) { this.parser = TestHelpers.getParser(source); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); Assert.Throws <SemanticException>(() => this.analyzer.analyze(ast, this.symbolTable)); }
static public void AddChild(this AST_Tree self, IAST c) { if (c == null) { return; } self.children.Add(c); }
public void checkVariableIsNotDeclared() { this.parser = TestHelpers.getParser("var x : int; var y : int;"); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); this.analyzer.analyze(ast, this.symbolTable); Assert.False(this.analyzer.variableExists("z")); }
public void checkStringIsDeclaredWithDefaultValue() { this.parser = TestHelpers.getParser("var x : string;"); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); this.analyzer.analyze(ast, this.symbolTable); Assert.Equal("", this.analyzer.getString("x")); }
public void checkBoolIsDeclaredWithDefaultValue() { this.parser = TestHelpers.getParser("var trueValue : bool;"); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); this.analyzer.analyze(ast, this.symbolTable); Assert.True(this.analyzer.variableExists("trueValue")); Assert.False(this.analyzer.getBool("trueValue")); }
static public void AddChildren(this AST_Tree self, IAST b) { if (b is AST_Tree c) { for (int i = 0; i < c.children.Count; ++i) { self.AddChild(c.children[i]); } } }
static public void AddChild(this IAST self, IAST c) { if (c == null) { return; } var ast = self as AST_Tree; ast.children.Add(c); }
public void shouldHaveThreeDifferentTypesDeclared() { this.parser = TestHelpers.getParser("var x : bool; var y : int; var z : string;"); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); this.analyzer.analyze(ast, this.symbolTable); Assert.False(this.analyzer.getBool("x")); Assert.Equal(0, this.analyzer.getInt("y")); Assert.Equal("", this.analyzer.getString("z")); }
public void checkThreeIntegersAreDeclaredWithDefaultValue() { this.parser = TestHelpers.getParser("var x : int; var y : int; var z : int;"); Assert.True(this.parser.processAndBuildAST()); IAST ast = this.parser.getAST(); this.analyzer.analyze(ast, this.symbolTable); Assert.Equal(0, this.analyzer.getInt("x")); Assert.Equal(0, this.analyzer.getInt("y")); Assert.Equal(0, this.analyzer.getInt("z")); }