Example #1
0
        private void _GetNext()
        {
            Lexeme buffer = null;

            while (_input.Peek() != -1)
            {
                _readFlag = true;
                switch (_input.Peek())
                {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    buffer    = new NumberLexeme(GetDecimal());
                    _readFlag = false;
                    break;

                case '+':
                    buffer = new Lexeme(LexemeType.add);
                    break;

                case '-':
                    buffer = new Lexeme(LexemeType.sub);
                    break;

                case '*':
                    buffer = new Lexeme(LexemeType.mul);
                    break;

                case '/':
                    buffer = new Lexeme(LexemeType.div);
                    break;

                case ' ':
                    break;

                case '(':
                    buffer = new Lexeme(LexemeType.bracketOpen);
                    break;

                case ')':
                    buffer = new Lexeme(LexemeType.bracketClose);
                    break;

                default:
                    throw new Exception("Недопустимый символ!!!");
                }

                if (_readFlag == true)
                {
                    _input.Read();
                }

                if (buffer == null)
                {
                    continue;
                }

                _buffer = buffer;
                return;
            }
            _buffer = null;
            return;
        }
Example #2
0
File: Class1.cs Project: dfyz/stuff
        private void _GetNext()
        {
            Lexeme buffer = null;
            while (_input.Peek() != -1)
            {
                _readFlag = true;
                switch(_input.Peek())
                {
                    case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
                        buffer = new NumberLexeme(GetDecimal());
                        _readFlag = false;
                        break;
                    case '+':
                        buffer = new Lexeme(LexemeType.add);
                        break;
                    case '-':
                        buffer =  new Lexeme(LexemeType.sub);
                        break;
                    case '*':
                        buffer =  new Lexeme(LexemeType.mul);
                        break;
                    case '/':
                        buffer =  new Lexeme(LexemeType.div);
                        break;
                    case ' ':
                        break;
                    case '(':
                        buffer =  new Lexeme(LexemeType.bracketOpen);
                        break;
                    case ')':
                        buffer =  new Lexeme(LexemeType.bracketClose);
                        break;
                    default:
                        throw new Exception("Недопустимый символ!!!");
                }

                if ( _readFlag == true )
                    _input.Read();

                if ( buffer == null )
                    continue;

                _buffer = buffer;
                return;
            }
            _buffer = null;
            return;
        }