예제 #1
0
파일: TokenList.cs 프로젝트: anaimi/codebox
 /// <summary>
 /// Creates a new token list by cloning outerTokens with a specified range (range is exclusive, not inclusive)
 /// </summary>
 public TokenList(TokenList outerTokens, int fromToken, int toToken)
 {
     // do copy
     for (var i = fromToken; fromToken < toToken; fromToken++)
     {
         tokens.Add(outerTokens.tokens[fromToken]);
     }
 }
예제 #2
0
        public static void Expect(TokenList tl, TokenType type, string value)
        {
            Token t = tl.Next();

            if ((t.Type == type) && (t.Value == value))
            {
                tl.Consume();
            }
            else
            {
                string expectedType = TokenTypeToString(type);
                string expectedValue = value;
                string foundType = TokenTypeToString(t.Type);
                string foundValue = t.Value;
                ExceptionType exceptionType = (type == TokenType.KEYWORD)
                                                ? ExceptionType.UnknownSymbol
                                                : ExceptionType.Syntax;

                throw new EngineException(exceptionType,
                                          string.Format("Expected '{0}' with Value '{1}' found '{2}' with Value '{3}'", expectedType,
                                                        expectedValue, foundType, foundValue), t);
            }
        }
예제 #3
0
 public static string Expect(TokenList tl, TokenType type)
 {
     return Expect(tl, type, true);
 }
예제 #4
0
        public static string Expect(TokenList tl, TokenType type, bool consume)
        {
            Token t = tl.Next();

            if (t.Type == type)
            {
                if (consume)
                    tl.Consume();

                return t.Value;
            }

            string expectedType = TokenTypeToString(type);
            string foundType = TokenTypeToString(t.Type);

            throw new EngineException(ExceptionType.Syntax, string.Format("Expected '{0}' found '{1}' with Value '{2}'", expectedType, foundType, tl.Next().Value), t);
        }