Exemplo n.º 1
0
 private bool ConsumeToken(Token.Symbol symbol, bool force)
 {
     if (tokens.Count == 0)
     {
         if (force)
         {
             throw new ParseError(String.Format(
                                      "end of input while expecting token \"{0}\"",
                                      symbol));
         }
         else
         {
             return(false);
         }
     }
     if (tokens.Peek().Name == symbol)
     {
         tokens.Dequeue();
         return(true);
     }
     else if (force)
     {
         throw new ParseError(String.Format(
                                  "expected \"{0}\" found \"{1}\"",
                                  symbol,
                                  tokens.Peek().ToString()));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
 private bool CanConsumeToken(Token.Symbol symbol)
 {
     if (tokens.Count == 0)
     {
         return(false);
     }
     if (tokens.Peek().Name == symbol)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
 private bool ConsumeToken(Token.Symbol symbol)
 {
     return(ConsumeToken(symbol, false));
 }