Esempio n. 1
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CToken pToken    = new CToken();
            CToken pSymToken = null;

            //try
            {
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) || pToken == null)
                {
                    //throw (C_UM_ERROR_INTERNALERR);
                }

                RUL_TOKEN_SUBTYPE SubType = pToken.GetSubType();

                bool   lboxState  = false;
                bool   rboxState  = false;
                bool   numState   = false;
                bool   idState    = true;
                bool   commaState = false;
                CToken pArrToken  = null;
                int    dimCnt     = 0; // stevev 25apr13 - we have to reuse bracket scoped arrays

                while ((CLexicalAnalyzer.LEX_FAIL != plexAnal.GetNextVarToken(ref pToken, ref pSymbolTable, SubType)) &&
                       pToken != null && (!pToken.IsEOS()))
                {
                    int       idex = 0;
                    CVariable cv   = pSymbolTable.Find(pToken.GetLexeme(), ref idex);
                    if (cv != null)
                    {
                        pSymToken = cv.Token;
                    }
                    if ((!pToken.IsSymbol() && pSymToken != null) ||
                        (RUL_TOKEN_SUBTYPE.RUL_LBOX == pToken.GetSubType()) ||
                        (RUL_TOKEN_SUBTYPE.RUL_RBOX == pToken.GetSubType()) ||
                        (pToken.IsNumeric()))
                    {
                        if (pToken.IsArrayVar())
                        {
                            lboxState  = true;
                            rboxState  = false;
                            numState   = false;
                            idState    = false;
                            commaState = false;

                            pSymToken.SetSubType(SubType);
                            //Make a copy of the array Token
                            pArrToken = new CToken(pToken);
                        }
                        else if (lboxState)
                        {
                            if (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_LBOX)
                            {
                                //ADD_ERROR(C_DECL_ERROR_LBOX);
                                plexAnal.SynchronizeTo(PRODUCTION.DECLARATION, pSymbolTable);
                            }
                            lboxState  = false;
                            rboxState  = true;
                            numState   = false;
                            idState    = false;
                            commaState = false;
                        }
                        else if (rboxState)
                        {
                            if ((null == pArrToken) || !pToken.IsNumeric())
                            {
                                //ADD_ERROR(C_DECL_ERROR_NUM);
                                plexAnal.SynchronizeTo(PRODUCTION.DECLARATION, pSymbolTable);
                            }

                            lboxState  = false;
                            rboxState  = false;
                            numState   = true;
                            idState    = false;
                            commaState = false;
                            //This is a number and with pArrToken get the symbol table token

                            int       i32Idx = pArrToken.GetSymbolTableIndex();
                            CVariable pVar   = pSymbolTable.GetAt(i32Idx);
                            //INTER_VARIANT varArray = pVar.GetValue();
                            VARIANT_TYPE vtSafeArray = new VARIANT_TYPE();

                            //increment the dimension and set the limit of that dimension
                            if (pVar.GetValue().GetVarType() != VARIANT_TYPE.RUL_SAFEARRAY || dimCnt == 0)// stevev 25apr13
                            {
                                // WS:EMP-17jul07:varArray.Clear();
                                // WS:EMP-17jul07:varArray.varType = RUL_SAFEARRAY;
                                // WS:EMP-17jul07:__VAL& val = (__VAL&)varArray.GetValue();
                                // stevev-14feb08:make it more flexible...INTER_SAFEARRAYBOUND rgbound[1] = {atoi(pToken.GetLexeme())};
                                INTER_SAFEARRAYBOUND rgbound = new INTER_SAFEARRAYBOUND();
                                rgbound.cElements = Convert.ToUInt32(pToken.GetLexeme());
                                //INTER_SAFEARRAYBOUND rgbound[1] = { strtoul(pToken->GetLexeme(), NULL, 0) };
                                INTER_SAFEARRAY sa    = new INTER_SAFEARRAY(); // WS:EMP-17jul07 was::>val.prgsa = new INTER_SAFEARRAY();
                                ushort          cDims = 0;                     // WS:EMP-17jul07 was::>_USHORT cDims = (val.prgsa).GetDims();

                                TokenType_to_VariantType(pToken.GetType(), SubType, ref vtSafeArray);

                                // WS:EMP-17jul07 was::>(val.prgsa).SetAllocationParameters(vtSafeArray, ++cDims, rgbound);
                                sa.SetAllocationParameters(vtSafeArray, ++cDims, rgbound);
                                sa.Allocate(); // stevev 11jun09 - get rid of error message, destructor will deallocate
                                //varArray = sa; // added WS:EMP-17jul07
                                pVar.GetValue().SetValue(sa);
                                pSymbolTable.SetAt(i32Idx, pVar);
                                dimCnt = 1;
                            }
                            else// isa RUL_SAFEARRAY && dimCnt > 0
                            {
                                __VAL val = pVar.GetValue().GetValue();
                                //INTER_SAFEARRAYBOUND rgbound[1] = { strtoul(pToken.GetLexeme(), NULL, 0) };
                                INTER_SAFEARRAYBOUND rgbound = new INTER_SAFEARRAYBOUND();
                                rgbound.cElements = 3;
                                (val.prgsa).AddDim(rgbound);
                                dimCnt++;
                            }
                        }
                        else if (numState)
                        {
                            if (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_RBOX)
                            {
                                //ADD_ERROR(C_DECL_ERROR_RBOX);
                                plexAnal.SynchronizeTo(PRODUCTION.DECLARATION, pSymbolTable);
                            }

                            //accept a Right box.
                            lboxState  = true;
                            rboxState  = false;
                            numState   = false;
                            commaState = true;
                            idState    = false;
                        }
                        else
                        {
                            if (idState)
                            {
                                if (pToken.GetType() != RUL_TOKEN_TYPE.RUL_SIMPLE_VARIABLE)
                                {
                                    //ADD_ERROR(C_DECL_ERROR_IDMISSING);
                                    plexAnal.SynchronizeTo(PRODUCTION.DECLARATION, pSymbolTable);
                                }
                                pSymToken.SetSubType(SubType);
                            }
                            else
                            {
                                //ADD_ERROR(C_DECL_ERROR_COMMAMISSING);
                                plexAnal.SynchronizeTo(PRODUCTION.DECLARATION, pSymbolTable);
                            }
                            lboxState  = false;
                            rboxState  = false;
                            numState   = false;
                            idState    = false;
                            commaState = true;
                        }
                    }
                    else if (commaState)
                    {
                        if (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_COMMA)
                        {
                            //ADD_ERROR(C_DECL_ERROR_COMMAMISSING);
                            plexAnal.SynchronizeTo(PRODUCTION.DECLARATION, pSymbolTable);
                        }

                        idState    = true;
                        commaState = false;
                        lboxState  = false;
                        rboxState  = false;
                        numState   = false;
                    }
                    else
                    {
                        //Of course, this is a problem case.
                        //Unfortunately, expressions in the declarations are not handled
                        //ADD_ERROR(C_DECL_ERROR_EXPRESSION);
                        plexAnal.SynchronizeTo(PRODUCTION.DECLARATION, pSymbolTable);

                        //accept a Right box. //VMKP added on 030404

                        /*  Synchronizing was not proper when an expression
                         *                       present in the variable declaration, With that the
                         *                       below lines one declaration next to the expression
                         *                       declaration is skipping */
                        lboxState  = true;
                        rboxState  = false;
                        numState   = false;
                        commaState = true;
                        idState    = false;
                    }
                }//end of while loop

                //Validate the exit criteria...
                if (!(rboxState == numState == idState == false) || !(commaState == true))
                {
                    //ADD_ERROR(C_DECL_ERROR_UNKNOWN);
                    plexAnal.SynchronizeTo(PRODUCTION.DECLARATION, pSymbolTable);
                }

                return(1);
            }

            /*
             *          catch (CRIDEError* perr)
             *          {
             *                  pvecErrors.push_back(perr);
             *                  plexAnal.MovePast(
             *                          RUL_SYMBOL,
             *                          RUL_SEMICOLON,
             *                          pSymbolTable);
             *          }
             *          catch (...)
             *          {
             *                  throw (C_UM_ERROR_UNKNOWNERROR);
             *          }
             *
             *          return PARSE_FAIL;
             */
        }
Esempio n. 2
0
        public override int visitArrayExpression(CArrayExpression pArrExp, CSymbolTable pSymbolTable,
                                                 ref INTER_VARIANT pvar, RUL_TOKEN_SUBTYPE AssignType)
        {
            //try
            {
                int             i32Idx    = pArrExp.GetToken().GetSymbolTableIndex();
                CVariable       pVariable = pSymbolTable.GetAt(i32Idx);
                INTER_SAFEARRAY prgsa     = pVariable.GetValue().GetValue().prgsa;

                //evaluate the expressions...
                EXPR_VECTOR pvecExpressions = pArrExp.GetExpressions();
                List <int>  vecDims         = new List <int>();
                prgsa.GetDims(ref vecDims);

                if (vecDims.Count != pvecExpressions.Count)
                {
                    //throw (C_TC_ERROR_DIM_MISMATCH, pArrExp);
                }
                byte[] by;
                switch (prgsa.Type())
                {
                case VARIANT_TYPE.RUL_CHAR:
                    by = new byte[1];
                    //by[0] = ' ';
                    by[0] = 0;
                    pvar.SetValue(by, 0, prgsa.Type());
                    break;

                case VARIANT_TYPE.RUL_INT:
                    by = new byte[4];
                    by = BitConverter.GetBytes((int)0);
                    pvar.SetValue(by, 0, prgsa.Type());
                    break;

                case VARIANT_TYPE.RUL_BOOL:
                    by    = new byte[1];
                    by[0] = 0;
                    pvar.SetValue(by, 0, prgsa.Type());
                    break;

                case VARIANT_TYPE.RUL_FLOAT:
                    by = new byte[4];
                    by = BitConverter.GetBytes((float)0.0);
                    pvar.SetValue(by, 0, prgsa.Type());
                    break;

                case VARIANT_TYPE.RUL_DOUBLE:
                    by = new byte[4];
                    by = BitConverter.GetBytes((double)0.0);
                    pvar.SetValue(by, 0, prgsa.Type());
                    break;

                case VARIANT_TYPE.RUL_CHARPTR:
                case VARIANT_TYPE.RUL_SAFEARRAY:
                case VARIANT_TYPE.RUL_DD_STRING:
                case VARIANT_TYPE.RUL_UNSIGNED_CHAR:
                    by    = new byte[1];
                    by[0] = 0;
                    pvar.SetValue(by, 0, prgsa.Type());
                    break;
                }
                return(TYPE_SUCCESS);
            }

            /*
             * catch (CRIDEError* perr)
             * {
             *      pvecErrors.push_back(perr);
             * }
             * catch (...)
             * {
             *      throw (C_UM_ERROR_UNKNOWNERROR, pArrExp);
             * }
             * return TYPE_FAILURE;
             */
        }