Exemple #1
0
        public CGrammarNode CreateParser(ref CLexicalAnalyzer plexAnal, STATEMENT_TYPE stmt_type)
        {
            CGrammarNode pNode  = null;
            CToken       pToken = null;

            if ((CLexicalAnalyzer.LEX_FAIL != (plexAnal.LookAheadToken(ref pToken))) && pToken != null)
            {
                if (((stmt_type == STATEMENT_TYPE.STMT_DECL) || (stmt_type == STATEMENT_TYPE.STMT_asic)) &&
                    ((pToken.GetType() == RUL_TOKEN_TYPE.RUL_SYMBOL) && (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_SEMICOLON)))
                {
                    pNode = new CEmptyStatement();
                }
                else if (
                    ((stmt_type == STATEMENT_TYPE.STMT_DECL) || (stmt_type == STATEMENT_TYPE.STMT_asic)) &&
                    ((pToken.GetType() == RUL_TOKEN_TYPE.RUL_SYMBOL) && (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_LPAREN))
                    )
                {
                    pNode = new CExpression();
                }
                else if (((stmt_type == STATEMENT_TYPE.STMT_DECL) || (stmt_type == STATEMENT_TYPE.STMT_asic)) && pToken.IsDeclaration())          //Declaration Statement
                {
                    pNode = new CDeclaration();
                }
                else if (((stmt_type == STATEMENT_TYPE.STMT_asic)) &&
                         (RUL_TOKEN_TYPE.RUL_KEYWORD == pToken.GetType()) &&
                         !pToken.IsIteration() &&
                         !pToken.IsFunctionToken())
                {
                    if (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_IF)// IF Selection Statement
                    {
                        pNode = new CSelectionStatement();
                    }
                    else if (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_SWITCH)//SWITCH Statement
                    {
                        pNode = new CSwitchStatement();
                    }
                    else if (RUL_TOKEN_TYPE.RUL_KEYWORD == pToken.GetType() &&
                             RUL_TOKEN_SUBTYPE.RUL_RULE_ENGINE == pToken.GetSubType())   //Rule Statement
                    {
                        pNode = new CRuleServiceStatement();
                    }
                    else if (RUL_TOKEN_TYPE.RUL_KEYWORD == pToken.GetType() &&
                             RUL_TOKEN_SUBTYPE.RUL_BREAK == pToken.GetSubType())     //break Statement
                    {
                        pNode = new CBreakStatement();
                    }
                    else if (RUL_TOKEN_TYPE.RUL_KEYWORD == pToken.GetType() &&
                             RUL_TOKEN_SUBTYPE.RUL_CONTINUE == pToken.GetSubType())      //continue Statement
                    {
                        pNode = new CContinueStatement();
                    }
                    else if (RUL_TOKEN_TYPE.RUL_KEYWORD == pToken.GetType() &&
                             RUL_TOKEN_SUBTYPE.RUL_RETURN == pToken.GetSubType())    //continue Statement
                    {
                        pNode = new CReturnStatement();
                    }
                }
                else if (((stmt_type == STATEMENT_TYPE.STMT_ITERATION) || (stmt_type == STATEMENT_TYPE.STMT_asic)) && pToken.IsIteration())                               //Iteration Statement
                {
                    if (pToken.IsWHILEStatement())
                    {
                        pNode = new CIterationStatement();
                    }
                    else if (pToken.IsDOStatement())
                    {
                        pNode = new CIterationDoWhileStatement();
                    }
                    else if (pToken.IsFORStatement())
                    {
                        pNode = new CIterationForStatement();
                    }
                }
                else if (((stmt_type == STATEMENT_TYPE.STMT_ASSIGNMENT) || (stmt_type == STATEMENT_TYPE.STMT_asic)) && (pToken.IsFunctionToken()))
                //Assignment Statement
                {
                    pNode = new CExpression();
                }
                else if (((stmt_type == STATEMENT_TYPE.STMT_ASSIGNMENT) || (stmt_type == STATEMENT_TYPE.STMT_asic)) &&
                         (pToken.IsVariable() || pToken.IsArrayVar() || pToken.IsDDItem() ||//Added By Anil August 4 2005
                          pToken.IsOMToken() || pToken.IsNumeric() ||
                          pToken.IsConstant() || pToken.IsFunctionToken() || pToken.IsOperator() ||
                          ((pToken.GetType() == RUL_TOKEN_TYPE.RUL_SYMBOL) && (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_LPAREN))
                         ))
                //Assignment Statement
                {
                    CToken pNewToken = null;  //TSRPRASAD 09MAR2004 Fix the memory leaks	*/

                    bool bLineIsAssignment = false;
                    if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ARITHMETIC_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_PLUS_ASSIGN, ref pNewToken))   //TSRPRASAD 09MAR2004 Fix the memory leaks	*/
                    {
                        bLineIsAssignment = true;
                    }
                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_MINUS_ASSIGN, ref pNewToken))   //TSRPRASAD 09MAR2004 Fix the memory leaks	*/
                    {
                        bLineIsAssignment = true;
                    }
                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_DIV_ASSIGN, ref pNewToken))     //TSRPRASAD 09MAR2004 Fix the memory leaks	*/
                    {
                        bLineIsAssignment = true;
                    }
                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_MOD_ASSIGN, ref pNewToken))   //TSRPRASAD 09MAR2004 Fix the memory leaks	*/
                    {
                        bLineIsAssignment = true;
                    }

                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_MUL_ASSIGN, ref pNewToken))    //TSRPRASAD 09MAR2004 Fix the memory leaks	*/
                    {
                        bLineIsAssignment = true;
                    }
                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_BIT_AND_ASSIGN, ref pNewToken)) //TSRPRASAD 09MAR2004 Fix the memory leaks	*/
                    {
                        bLineIsAssignment = true;
                    }
                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_BIT_OR_ASSIGN, ref pNewToken))  //TSRPRASAD 09MAR2004 Fix the memory leaks	*/
                    {
                        bLineIsAssignment = true;
                    }
                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_BIT_XOR_ASSIGN, ref pNewToken)) //TSRPRASAD 09MAR2004 Fix the memory leaks	*/
                    {
                        bLineIsAssignment = true;
                    }
                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_BIT_RSHIFT_ASSIGN, ref pNewToken))  //TSRPRASAD 09MAR2004 Fix the memory leaks	*/
                    {
                        bLineIsAssignment = true;
                    }
                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_BIT_LSHIFT_ASSIGN, ref pNewToken)) //TSRPRASAD 09MAR2004 Fix the memory leaks	*/

                    {
                        bLineIsAssignment = true;
                    }
                    else if (plexAnal.ScanLineForToken(RUL_TOKEN_TYPE.RUL_ASSIGNMENT_OPERATOR, RUL_TOKEN_SUBTYPE.RUL_ASSIGN, ref pNewToken)) //TSRPRASAD 09MAR2004 Fix the memory leaks	*/

                    {
                        bLineIsAssignment = true;
                    }

                    if (bLineIsAssignment)
                    {
                        pNode = new CAssignmentStatement();
                    }
                    else
                    {
                        pNode = new CExpression();
                    }
                }
                else if (((stmt_type == STATEMENT_TYPE.STMT_ASSIGNMENT) || (stmt_type == STATEMENT_TYPE.STMT_asic)) && pToken.IsFunctionToken())                           //Assignment Statement
                {
                    pNode = new CAssignmentStatement();
                }
                else if (((stmt_type == STATEMENT_TYPE.STMT_COMPOUND) || (stmt_type == STATEMENT_TYPE.STMT_asic)) && pToken.IsCompound())                                //Compound Statement
                {
                    pNode = new CCompoundStatement();
                }
                else if (((stmt_type == STATEMENT_TYPE.STMT_SERVICE) || (stmt_type == STATEMENT_TYPE.STMT_asic) || (stmt_type == STATEMENT_TYPE.STMT_ASSIGNMENT_FOR)) &&
                         pToken.IsService())                               //Service Statement
                {
                    pNode = new CServiceStatement();
                }
                else if (((stmt_type == STATEMENT_TYPE.STMT_SELECTION)) && (RUL_TOKEN_TYPE.RUL_KEYWORD == pToken.GetType()))
                {
                    if ((pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_CASE) || (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_DEFAULT))//CASE or DEFAULT Statement
                    {
                        pNode = new CCASEStatement();
                    }
                    else if (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_ELSE)//ELSE Statement
                    {
                        pNode = new CELSEStatement();
                    }
                }
                else
                {
                    //error
                    //the natural control flow is allowed to take care of this
                    //erroneous condition.
                }
            }
            return(pNode);
        }
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CToken pToken = null;
            //try
            {
                CExpParser expParser;
                //Munch a <Var>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) || pToken == null)
                {
                    //throw (C_UM_ERROR_INTERNALERR);
                }
                if (pToken.IsArrayVar())
                {
                    plexAnal.UnGetToken();
                    expParser        = new CExpParser();
                    m_pArrayExp      = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_LVALUE);
                    m_bLvalueIsArray = true;
                    m_pVariable      = null;
                    m_pOMExp         = null;
                    m_pComplexDDExp  = null;//Added By Anil August 23 2005
                }
                //Added By Anil August 4 2005 --starts here
                //For Handlin the DD variable and Expressions
                else if (pToken.IsDDItem())
                {
                    plexAnal.UnGetToken();
                    expParser            = new CExpParser();
                    m_pComplexDDExp      = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_LVALUE);
                    m_bLvalueIsComplexDD = true;
                    m_pArrayExp          = null;
                    m_pVariable          = null;
                    m_pOMExp             = null;
                }
                //Added By Anil August 4 2005 --Ends here
                else if (pToken.IsVariable())
                {
                    m_pVariable     = pToken;
                    m_pArrayExp     = null;
                    m_pOMExp        = null;
                    m_pComplexDDExp = null;//Anil August 23 2005

                    //DELETE_PTR(pToken);
                    //todo walter
                }
                else if (pToken.IsOMToken())
                {
                    //do something...
                    plexAnal.UnGetToken();
                    m_pOMExp = new COMServiceExpression();
                    m_pOMExp.CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                    m_pVariable     = null;
                    m_pArrayExp     = null;
                    m_pComplexDDExp = null;//Anil August 23 2005
                }
                else
                {
                    //throw (C_AP_ERROR_LVALUE);
                }

                //DELETE_PTR(pToken);  //todo walter
                pToken = null;
                //Munch a <=> or <*=>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null ||
                    !pToken.IsAssignOp())
                {
                    //throw (C_AP_ERROR_MISSINGEQ);
                }
                m_AssignType = pToken.GetSubType();

                //Munch & Parse the expression.
                //we got to give the expression string to the expression parser.
                expParser = new CExpParser();
                //try
                {
                    m_pExpression = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_ASSIGN);

                    if (m_pExpression == null)
                    {
                        //throw (C_AP_ERROR_MISSINGEXP);
                    }
                }

                /*
                 *              catch (CRIDEError* perr)
                 *              {
                 *                      pvecErrors.push_back(perr);
                 *                      plexAnal.SynchronizeTo(EXPRESSION, pSymbolTable);
                 *              }
                 */
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (RUL_TOKEN_SUBTYPE.RUL_SEMICOLON != pToken.GetSubType()))
                {
                    //throw (C_AP_ERROR_MISSINGSC);
                }
                return(1);
            }

            /*
             *          catch (CRIDEError* perr)
             *          {
             *                  pvecErrors.push_back(perr);
             *                  plexAnal.SynchronizeTo(EXPRESSION, pSymbolTable);
             *          }
             *          catch (...)
             *          {
             *                  throw (C_UM_ERROR_UNKNOWNERROR);
             *          }
             *          return PARSE_FAIL;
             */
        }
Exemple #3
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;
             */
        }