// Atom : Value | LParen Expression RParen internal static INode Produce(TokenBuffer tokens) { var value = Value.Produce(tokens); if (value != null) return value; // HACK if (tokens.Current is LeftParenthesis) tokens.SavePosition(); var lParen = tokens.GetTerminal<LeftParenthesis>(); if (lParen == null) return null; var expression = Expression.Produce(tokens); if (expression == null) { tokens.RestorePosition(); return null; } var rParen = tokens.GetTerminal<RightParenthesis>(); if (rParen == null) { throw new ParseException("Missing closing parenthesis"); } return expression; }
// AddSubOp : AddOp | SubOp internal static AddSubOp Produce(TokenBuffer tokens) { var addOp = tokens.GetTerminal<AdditionOperator>(); if (addOp != null) return new AddSubOp(addOp); var subOp = tokens.GetTerminal<SubtractionOperator>(); if (subOp != null) return new AddSubOp(subOp); return null; }
// ExpRootOp : ExpOp | RootOp internal static ExpRootOp Produce(TokenBuffer tokens) { var expOp = tokens.GetTerminal<ExponentiationOperator>(); if (expOp != null) return new ExpRootOp(expOp); var rootOp = tokens.GetTerminal<RootExtractionOperator>(); if (rootOp != null) return new ExpRootOp(rootOp); return null; }
// MulDivOp : MulOp | DivOp internal static MulDivOp Produce(TokenBuffer tokens) { var mulOp = tokens.GetTerminal<MultiplicationOperator>(); if (mulOp != null) return new MulDivOp(mulOp); var divOp = tokens.GetTerminal<DivisionOperator>(); if (divOp != null) return new MulDivOp(divOp); return null; }
// Digits : Digit+ internal static Digits Produce(TokenBuffer tokens) { var digitList = new List<Digit>(); var digit = tokens.GetTerminal<Digit>(); if (digit != null) { while (digit != null) { digitList.Add(digit); digit = tokens.GetTerminal<Digit>(); } return new Digits(digitList); } return null; }
// Identifier : Character+ internal static Identifier Produce(TokenBuffer tokens) { var characters = new List<Character>(); var character = tokens.GetTerminal<Character>(); if (character != null) { while (character != null) { characters.Add(character); character = tokens.GetTerminal<Character>(); } return new Identifier(characters); } return null; }
internal static Assignment Produce(TokenBuffer tokens) { var assignee = Identifier.Produce(tokens); if (assignee == null) //throw new ParseException("Assignment must start with a identifier for the assignee."); return null; var assignOp = tokens.GetTerminal<AssignmentOperator>(); if (assignOp == null) //throw new ParseException("Expected assignment operator."); return null; var assigner = Expression.Produce(tokens); if (assigner == null) throw new ParseException("Expected expression for the right side of the assignment."); return new Assignment(assignee, assigner); }