//SumOp -> + Term SumOp //SumOp -> - Term SumOp //SumOp -> EPSILON Factor SumOp(Factor t) { Factor t2; switch (lookahead.type) { case TokenType.ADD: GetNextToken(); t2 = Term(); t.Add(t2); return(SumOp(t)); case TokenType.SUB: GetNextToken(); t2 = Term(); t.Subtract(t2); return(SumOp(t)); default: return(t); } }
Factor Parse() { GetNextToken(); Factor t1 = Expression(); if (!eq.IsEquation && lookahead.type == TokenType.EOF) { return(t1); } if (!eq.IsEquation && lookahead.type != TokenType.EOF) { throw WrongSymbol("End of File", lookahead.text); } if (eq.IsEquation && lookahead.type != TokenType.EQUAL) { throw WrongSymbol("=", lookahead.text); } GetNextToken(); Factor t2 = Expression(); t1.Subtract(t2); return(t1); }
//SumOp -> + Term SumOp //SumOp -> - Term SumOp //SumOp -> EPSILON Factor SumOp(Factor t) { Factor t2; switch (lookahead.type) { case TokenType.ADD: GetNextToken (); t2 = Term (); t.Add (t2); return SumOp (t); case TokenType.SUB: GetNextToken (); t2 = Term (); t.Subtract (t2); return SumOp (t); default: return t; } }