예제 #1
0
 private void match(TokenType token)
 {
     if (lookahead.Type == token)
     {
         lookahead = enumerator.MoveNext() ? enumerator.Current : new Token(TokenType.Empty);
     }
     else throw new InvalidOperationException(String.Format("Failed to match on {0}", token));
 }
예제 #2
0
        public string Parse(IEnumerable<Token> tokens)
        {
            enumerator = tokens.GetEnumerator();
            result = new StringBuilder();

            if (enumerator.MoveNext())
            {
                lookahead = enumerator.Current;
                expr();
            }
            return result.ToString();
        }
예제 #3
0
 private void output(Token token)
 {
     result.Append(token.Value.ToString());
 }
예제 #4
0
 private static bool isDigit(Token lookahead)
 {
     return lookahead.Type == TokenType.Digit;
 }