public override void Parse(Lexer lexer, List <ASTNode> astNodes) { Token token = lexer.Read(); if (this.Test(token)) { ASTNode astNode = ASTNodeFactory.Make(this.Type, new[] { token }); astNodes.Add(astNode); } else { throw new ParseException(token); } }
private ASTNode Shift(Lexer lexer, ASTNode left, int precedenceValue) { List <ASTNode> astNodes = new List <ASTNode>(); astNodes.Add(left); astNodes.Add(new ASTLeaf(lexer.Read())); ASTNode right = this.Factor.Parse(lexer); Precedence nextPrecedence = this.NextOperator(lexer); while (nextPrecedence != null && IsRightExpression(precedenceValue, nextPrecedence)) { right = this.Shift(lexer, right, nextPrecedence.Value); nextPrecedence = this.NextOperator(lexer); } astNodes.Add(right); return(ASTNodeFactory.Make(this.Type, new[] { astNodes })); }
public ASTNode Parse(Lexer lexer) { List <ASTNode> astNodes = new List <ASTNode>(); foreach (Element element in this.Elements) { element.Parse(lexer, astNodes); } if (this.Type == null) { if (astNodes.Count == 1) { return(astNodes[0]); } else { return(new ASTBranchNode(astNodes)); } } else if (this.Type == typeof(PrimaryExpression)) { if (astNodes.Count == 1) { return(astNodes[0]); } else { return(new PrimaryExpression(astNodes)); } } else { return(ASTNodeFactory.Make(this.Type, new[] { astNodes })); } }