public void ParserShould_GetPrecedence_OfBracketedExpressionCorrect() { // arrange var input = @"(x + y) * z"; // act var parser = new Parser(ArithmeticGrammarParserTableFactory.Create(), new ArithmeticGrammarAstFactory()) { EnableStackTrace = true }; var ast = parser.Parse(new Tokenizer(input), new ErrorRecord(input)); // assert Assert.That(ast, Is.AstEqual(new TimesOperator ( position: 0, left: new PlusOperator ( position: 0, left: new Identifier(0, "x"), right: new Identifier(0, "y") ), right: new Identifier(0, "z") ))); }
public void ParserShould_GenerateAst_WithLeftAssociativeAddition() { // arrange var input = @"x + y + z"; // act var parser = new Parser(ArithmeticGrammarParserTableFactory.Create(), new ArithmeticGrammarAstFactory()) { EnableStackTrace = true }; var ast = parser.Parse(new Tokenizer(input), new ErrorRecord(input)); // assert Assert.That(ast, Is.AstEqual(new PlusOperator ( position: 0, left: new PlusOperator ( position: 0, left: new Identifier(0, "x"), right: new Identifier(0, "y") ), right: new Identifier(0, "z") ))); }
public void ParserShould_ParseExpression_WithBrackets() { // arrange var input = @"(x)"; // act var parser = new Parser(ArithmeticGrammarParserTableFactory.Create(), new ArithmeticGrammarAstFactory()) { EnableStackTrace = true }; var ast = parser.Parse(new Tokenizer(input), new ErrorRecord(input)); // assert Assert.That(ast, Is.AstEqual(new Identifier(0, "x"))); }