public void PascalInput_Should_CreateOutput(string input, string output) { var tokens = lexer.Tokenize(input.Trim()); var node = ast.Evaluate(tokens); table.CheckSyntax(node); var result = cSharp.VisitNode(node).Trim(); //result.Should().Be(output.Trim()); CompileCSharp.CompileExecutable2(output, "test").Should().BeTrue(); }
public string Convert(string pascalInput) { var tokens = lexer.Tokenize(pascalInput); var tree = ast.Evaluate(tokens); table.CheckSyntax(tree); return(VisitNode(tree)); }
public override bool Execute() { try { var text = File.ReadAllText(FileName); var lexer = new PascalLexer(); var tokens = lexer.Tokenize(text); var ast = new PascalAst(); var node = ast.Evaluate(tokens); var syntaxChecker = new PascalSemanticAnalyzer(); syntaxChecker.CheckSyntax(node); return(true); } catch (Exception e) { return(false); } //System.Diagnostics.Debugger.Launch(); }
public void CaseStatementWithoutElse() { var input = @" program checkCase; var grade: char; begin grade := 'A'; case (grade) of 'A' : writeln('Excellent!' ); 'B', 'C': writeln('Well done' ); 'D' : writeln('You passed' ); 'F' : writeln('Better try again' ); end; writeln('Your grade is ', grade ); end. "; var tokens = lexer.Tokenize(input); var node = ast.Evaluate(tokens).Should().BeOfType <PascalProgramNode>().Subject; var statements = node.Block.CompoundStatement.Nodes; statements[0].Should().BeOfType <AssignmentNode>(); var t = statements[1].Should().BeOfType <CaseStatementNode>().Subject; t.CompareExpression.Should().BeOfType <VariableOrFunctionCall>(); var items = t.CaseItemNodes; items.Should().HaveCount(4); items[1].Cases.Should().HaveCount(2); items[1].Statement.Should().BeOfType <ProcedureCallNode>(); statements[2].Should().BeOfType <ProcedureCallNode>(); }
private object Evaluate(string input) { var tokens = lexer.Tokenize(input); var node = ast.Evaluate(tokens); analyzer.CheckSyntax(node); var n = interpreter.Interpret(node); return(n); }
private Node CheckSyntaxAndReturnNode(string input) { var tokens = this.lexer.Tokenize(input); var node = ast.Evaluate(tokens); analyzer.CheckSyntax(node); return(node); }