Beispiel #1
0
        public const char InverseOne = (char)255;  // -1

        public static string KindToString(ExprTokenKind kind)
        {
            string result;

            KindToStringValues.TryGetValue(kind, out result);
            return(result ?? String.Empty);
        }
Beispiel #2
0
 public void Expected(ExprTokenKind wanted)
 {
     Kind = ExprTokenKind.ERROR;
     if (wanted == ExprTokenKind.ERROR || wanted == ExprTokenKind.UNKNOWN)
     {
         throw new ParseError(String.Format(ParseError.ParseError_InvalidToken, this));
     }
     else
     {
         throw new ParseError(String.Format(ParseError.ParseError_InvalidTokenWanted, this, wanted));
     }
 }
Beispiel #3
0
        public void Unexpected(char wanted)
        {
            ExprTokenKind prevKind = Kind;

            Kind = ExprTokenKind.ERROR;

            if (wanted == default(char))
            {
                switch (prevKind)
                {
                case ExprTokenKind.TOK_EOF:
                    throw new ParseError(ParseError.ParseError_UnexpectedEndOfExpression);

                case ExprTokenKind.IDENT:
                    throw new ParseError(String.Format(ParseError.ParseError_UnexpectedSymbol, Value));

                case ExprTokenKind.VALUE:
                    throw new ParseError(String.Format(ParseError.ParseError_UnexpectedValue, Value));

                default:
                    throw new ParseError(String.Format(ParseError.ParseError_UnexpectedExpressionToken, Symbol));
                }
            }
            else
            {
                switch (prevKind)
                {
                case ExprTokenKind.TOK_EOF:
                    throw new ParseError(String.Format(ParseError.ParseError_UnexpectedEndOfExpressionWanted, wanted));

                case ExprTokenKind.IDENT:
                    throw new ParseError(String.Format(ParseError.ParseError_UnexpectedSymbolWanted, Value, wanted));

                case ExprTokenKind.VALUE:
                    throw new ParseError(String.Format(ParseError.ParseError_UnexpectedValueWanted, Value, wanted));

                default:
                    throw new ParseError(String.Format(ParseError.ParseError_UnexpectedExpressionTokenWanted, Symbol, wanted));
                }
            }
        }
Beispiel #4
0
 public ExprToken(ExprTokenKind kind, Value value)
     : this()
 {
     Kind  = kind;
     Value = value;
 }
Beispiel #5
0
        private void ReadAndCheckTokenProps(Func <int> act, ref ExprToken token, InputTextStream inStream, int expectedResult, ExprTokenKind expectedKind, int expectedLength, Value expectedValue, string expectedSymbol)
        {
            inStream.PeekNextNonWS();
            token.Clear();
            int result = act();

            Assert.Equal(expectedResult, result);
            Assert.Equal(expectedKind, token.Kind);
            Assert.Equal(expectedLength, token.Length);
            Assert.True(expectedValue.IsEqualTo(token.Value));
            Assert.Equal(expectedSymbol, token.Symbol);
        }