Пример #1
0
 /// <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);
        }