Ejemplo n.º 1
0
        /// <summary>
        /// Парсер даты и строк.
        /// </summary>
        /// <param name="iterator"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public bool Parse(SourceIterator iterator, out IToken token)
        {
            token = null;
            string content = string.Empty;

            CodeInformation information = iterator.CodeInformation.Clone();

            if (ParseDate(iterator, out content))
            {
                token = new TokenClass()
                {
                    Content         = content,
                    CodeInformation = information,
                    Type            = TokenTypeEnum.LITERAL,
                    SubType         = TokenSubTypeEnum.L_DATE
                };
                return(true);
            }

            if (ParseString(iterator, out content))
            {
                token = new TokenClass()
                {
                    Content         = content,
                    CodeInformation = information,
                    Type            = TokenTypeEnum.LITERAL,
                    SubType         = TokenSubTypeEnum.L_STRING
                };
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public bool Parse(SourceIterator iterator, out IToken token)
        {
            token = null;
            string           content = string.Empty;
            TokenSubTypeEnum subtype;

            if (Char.IsLetter(iterator.Current) || iterator.Current == '_')
            {
                CodeInformation information = iterator.CodeInformation.Clone();
                content = iterator.GetLettersAndDigits();

                if (!_table.TryGetValue(content, out subtype))
                {
                    subtype = TokenSubTypeEnum.NA;
                }

                token = new TokenClass()
                {
                    Content         = content,
                    CodeInformation = information,
                    Type            = TokenTypeEnum.IDENTIFIER,
                    SubType         = subtype
                };

                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Получить строку заключенную в кавычки "".
        /// </summary>
        /// <returns></returns>
        public string GetString()
        {
            int    counter = 0;
            string buffer  = string.Empty;

            CodeInformation inforamtion = CodeInformation.Clone();

            do
            {
                if (_current_symbol != '|' && _current_symbol != '\t' && _current_symbol != '\r')
                {
                    buffer += _current_symbol;
                }
                if (_current_symbol == '"')
                {
                    counter++;
                    if (counter % 2 == 0 && GetForwardSymbol() != '"')
                    {
                        MoveNext();
                        break;
                    }
                }
            }while (MoveNext());

            if (buffer[buffer.Length - 1] != '"')
            {
                throw new CompilerException(CodeInformation, "Ожидается символ \"");
            }

            buffer = buffer.Remove(0, 1);
            buffer = buffer.Remove(buffer.Length - 1, 1);

            return(buffer.Replace("\"\"", "\""));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Итератор исходного кода.
        /// </summary>
        /// <param name="source"></param>
        public SourceIterator(string module_name, string source)
        {
            _source = source;

            CodeInformation = new CodeInformation()
            {
                ModuleName = module_name
            };

            Reset();
        }
Ejemplo n.º 5
0
        public bool Parse(SourceIterator iterator, out IToken token)
        {
            token = null;
            string content = string.Empty;

            if (Char.IsNumber(iterator.Current))
            {
                CodeInformation information = iterator.CodeInformation.Clone();
                content = iterator.GetDigits();
                token   = new TokenClass()
                {
                    Content         = content,
                    CodeInformation = information,
                    Type            = TokenTypeEnum.NUMBER
                };
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Перейти до указанного символа и вернуть пройденные символы.
        /// </summary>
        /// <param name="symbol">Символ до которого передвинуть курсор</param>
        private bool GoToSymbol(char symbol)
        {
            CodeInformation information = CodeInformation.Clone();

            do
            {
                if (!MoveNext())
                {
                    if (Char.IsSymbol(symbol))
                    {
                        throw new CompilerException(information, "Ожидается символ: { " + symbol + " }");
                    }
                    else
                    {
                        return(false);
                    }
                }
            }while (_current_symbol != symbol);
            return(true);
        }
Ejemplo n.º 7
0
        public bool Parse(SourceIterator iterator, out IToken token)
        {
            token = null;
            string           content = string.Empty;
            TokenSubTypeEnum subtype;

            if (_punctuation_table.TryGetValue(iterator.Current.ToString(), out subtype))
            {
                char forward_symbol;

                CodeInformation information = iterator.CodeInformation.Clone();
                forward_symbol = iterator.GetForwardSymbol();
                content       += iterator.Current;

                if ((forward_symbol == '>' || forward_symbol == '=') && (iterator.Current == '<' || iterator.Current == '>'))
                {
                    content = iterator.Current + forward_symbol.ToString();
                    _punctuation_table.TryGetValue(content, out subtype);

                    iterator.MoveNext();
                }

                iterator.MoveNext();

                token = new TokenClass()
                {
                    Content         = content,
                    CodeInformation = information,
                    Type            = TokenTypeEnum.PUNCTUATION,
                    SubType         = subtype
                };
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
 internal CompilerException(CodeInformation codeInfo, string message) : base(message)
 {
     _code_information = codeInfo;
 }
Ejemplo n.º 9
0
 internal CompilerException()
 {
     _code_information            = new CodeInformation();
     _code_information.LineNumber = -1;
 }