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);
        }
Exemple #2
0
 public virtual int visitReturnStatement(CReturnStatement pStatement, CSymbolTable pSymbolTable,
                                         ref INTER_VARIANT pvar, RUL_TOKEN_SUBTYPE AssignType = RUL_TOKEN_SUBTYPE.RUL_ASSIGN) //Anil August 26 2005 to Fix a[exp1] += exp2
 {
     return(0);
 }