예제 #1
0
        private LexerState SelectState()
        {
            char cs = _iterator.CurrentSymbol;

            if (Char.IsLetter(cs) || cs == SpecialChars.Underscore)
            {
                _state = _wordState;
            }
            else if (Char.IsDigit(cs))
            {
                _state = _numberState;
            }
            else if (cs == SpecialChars.DateQuote)
            {
                _state = _dateState;
            }
            else if (cs == SpecialChars.StringQuote)
            {
                _state = _stringState;
            }
            else if (SpecialChars.IsOperatorChar(cs))
            {
                _state = CommentOrOperatorState(cs);
            }
            else if (cs == SpecialChars.EndOperator)
            {
                SetFixedState(LexemType.EndOperator, Token.Semicolon);
            }
            else if (cs == SpecialChars.QuestionMark)
            {
                SetFixedState(LexemType.Operator, Token.Question);
            }
            else if (cs == SpecialChars.Preprocessor)
            {
                _state = _directiveState;
            }
            else if (cs == SpecialChars.Annotation)
            {
                _iterator.GetContents();
                _iterator.MoveNext();
                _state = _annotationState;
            }
            else
            {
                var cp  = _iterator.GetPositionInfo();
                var exc = new SyntaxErrorException(cp, string.Format("Неизвестный символ {0}", cs));
                if (!HandleError(exc))
                {
                    throw exc;
                }
            }

            return(_state);
        }
예제 #2
0
 public void Special_Characters()
 {
     Assert.True(SpecialChars.IsOperatorChar('+'));
     Assert.True(SpecialChars.IsOperatorChar('-'));
     Assert.True(SpecialChars.IsOperatorChar('*'));
     Assert.True(SpecialChars.IsOperatorChar('/'));
     Assert.True(SpecialChars.IsOperatorChar('<'));
     Assert.True(SpecialChars.IsOperatorChar('>'));
     Assert.True(SpecialChars.IsOperatorChar('='));
     Assert.True(SpecialChars.IsOperatorChar('%'));
     Assert.True(SpecialChars.IsOperatorChar('('));
     Assert.True(SpecialChars.IsOperatorChar(')'));
     Assert.True(SpecialChars.IsOperatorChar('.'));
     Assert.True(SpecialChars.IsOperatorChar(','));
     Assert.True(SpecialChars.IsOperatorChar('['));
     Assert.True(SpecialChars.IsOperatorChar(']'));
 }