예제 #1
0
        public override void cm_Parse()
        {
            cLexem.cf_LexemDic.Clear();

            int         i  = 1;
            Stack <int> _s = new Stack <int>();

            _s.Push(0);
            bool   _la    = true;
            cToken _token = cf_scanner.cm_GetNextToken();

            cf_lisTokens.Add(_token);
            while (_token != null && i != 0)
            {
                DataRow _row = cf_dataTable.Rows[i - 1];
                if (_token.IsInTerminals(_row["terminals"] as string[]))
                {
                    _la = (bool)_row["accept"];

                    // действие
                    if (!string.IsNullOrEmpty(_row["action"] as string))
                    {
                        cm_doAction(_row["action"] as string);
                    }

                    if ((bool)_row["return"])
                    {
                        i = _s.Pop();
                    }
                    else
                    {
                        if ((bool)_row["stack"])
                        {
                            _s.Push(i + 1);
                        }
                        i = (int)_row["jump"];
                    }
                }
                else
                {
                    if ((bool)_row["error"])
                    {
                        throw new cParserException(cf_lisTokens, _row["terminals"] as string[]);
                    }
                    else
                    {
                        i   = i + 1;
                        _la = false;
                    }
                }
                if (_la)
                {
                    if (_token.cf_Type == eTokenType.Null)
                    {
                        throw new cParserException(cf_lisTokens, _row["terminals"] as string[]);
                    }
                    _token = cf_scanner.cm_GetNextToken();
                    cf_lisTokens.Add(_token);
                }
            }

            if (i != 0)
            {
                throw new cParserException(cf_lisTokens, new string[] { });
            }
            if (_token.cf_Type != eTokenType.Null)
            {
                throw new cParserException(cf_lisTokens, new string[] { });
            }
        }
예제 #2
0
        public override void cm_Parse()
        {
            cLexem.cf_LexemDic.Clear();

            Stack <object> _s = new Stack <object>();

            _s.Push(0);

            cToken _token = cf_scanner.cm_GetNextToken();

            cf_lisTokens.Add(_token);
            string _lexem = _token.cf_Type.ToString();

            bool _finished = false, _error = false;

            //while (!_finished & !_error & (_token != null))
            while (!_finished & !_error)
            {
                int _num = 0;
                try
                {
                    _num = (int)_s.Peek();
                }
                catch
                {
                    throw new cParserException(cf_lisTokens, new string[] { });
                }
                DataRow _row   = cf_dataTable.Rows[_num];
                object  _value = _row[_lexem];
                if (!(_value is System.DBNull))
                {
                    string   _val      = _value as String;
                    string[] _splitVal = _val.Split(new char[] { cLRTableGenerator.cc_Separator }, StringSplitOptions.RemoveEmptyEntries);
                    if (_splitVal.Length > 0)
                    {
                        string _do = _splitVal[0];
                        char   _c  = _do[0];
                        switch (_c)
                        {
                        case 'S':
                            _s.Push(_lexem);
                            int _sNum = 0;
                            if (!Int32.TryParse(_do.TrimStart(new char[] { 'S' }), out _sNum))
                            {
                                throw new cParserException(cf_lisTokens, new string[] { });
                            }
                            _s.Push(_sNum);
                            _token = cf_scanner.cm_GetNextToken() ?? cToken.cc_NullToken;
                            cf_lisTokens.Add(_token);
                            _lexem = _token.cm_TypeToStr();
                            break;

                        case 'R':
                            uint _rNum = 0;
                            if (!UInt32.TryParse(_do.TrimStart(new char[] { 'R' }), out _rNum))
                            {
                                throw new cParserException(cf_lisTokens, new string[] { });
                            }
                            //_lexem=cm_doR(_rNum, _s);
                            cm_stackPop(_s, _rNum * 2);
                            _lexem = _splitVal[1];
                            cm_doAction(_splitVal);
                            break;

                        case 'A':
                            _finished = true;
                            break;

                        default:
                            _s.Push(_lexem);
                            int _numN = 0;
                            if (!Int32.TryParse(_do, out _numN))
                            {
                                throw new cParserException(cf_lisTokens, new string[] { });
                            }
                            _s.Push(_numN);
                            //_token = cf_scanner.cm_GetNextToken();
                            //cf_lisTokens.Add(_token);
                            _lexem = _token.cm_TypeToStr();
                            break;
                        }
                    }
                    else
                    {
                        throw new cParserException(cf_lisTokens, new string[] { });
                    }
                }
                else
                {
                    throw new cParserException(cf_lisTokens, new string[] { });
                }
            }
        }