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

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

            //Look for a statement
            CParserBuilder builder = new CParserBuilder();

            m_pStatement = (CStatement)builder.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_asic);
            if (null != (m_pStatement))
            {
                int i32Ret = m_pStatement.CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                if (i32Ret == 0)
                {
                    //ADD_ERROR(C_ES_ERROR_MISSINGSTMT);
                }
                else
                {
                    return(1);
                }
            }
            return(0);
        }
示例#2
0
        public CToken(CToken token)
        {
            m_Type          = token.m_Type;
            m_SubType       = token.m_SubType;
            m_pszLexeme     = token.m_pszLexeme;
            m_pszDDItemName = null;
            //Anil August 26 2005 For handling DD variable and Expression
            if (token.m_pszDDItemName != null)
            {
                m_pszDDItemName = token.m_pszDDItemName;
            }

            m_nSymbolTableIndex    = token.m_nSymbolTableIndex;
            m_i32constant_pool_idx = token.m_i32constant_pool_idx;
            m_i32LineNo            = token.m_i32LineNo;
            m_bIsGlobal            = token.m_bIsGlobal; //Vibhor 070705: Added
            m_bIsRoutineToken      = false;             //Anil Octobet 5 2005 for handling Method Calling Method
            m_bIsReturnToken       = false;             //Anil Octobet 5 2005 for handling Method Calling Method

            m_nSymbolTableScopeIndex = 0;               //SCR26200 Felix for handling Nested Depth of Symbol

            if (token.m_pCompound != null)
            {
                m_pCompound = new COMPOUND_DATA();
                m_pCompound = token.m_pCompound;
            }
        }
示例#3
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CToken pToken = null;
            //try
            {
                //Munch a <break>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    !pToken.IsBREAKStatement())
                {
                    //throw (C_UM_ERROR_INTERNALERR);
                }
                //Munch a <;>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_SEMICOLON)
                {
                    //throw (C_UM_ERROR_INTERNALERR);
                }
                return(1);
            }

            /*
             *          catch (CRIDEError* perr)
             *          {
             *                  pvecErrors.push_back(perr);
             *                  plexAnal.SynchronizeTo(EXPRESSION, pSymbolTable);
             *          }
             *          catch (...)
             *          {
             *                  throw (C_UM_ERROR_UNKNOWNERROR);
             *          }
             *          return PARSE_FAIL;
             */
        }
示例#4
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CExpParser expParser = new CExpParser();
            CToken     pToken    = null;
            //try
            {
                m_pExpression = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_ASSIGN);
                if (m_pExpression == null)
                {
                    //ADD_ERROR(C_IF_ERROR_MISSINGEXP);
                }

                //Munch a <;>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null ||
                    pToken.IsEOS() == false)
                {
                    //throw (C_RS_ERROR_MISSINGSC);
                }


                return(0);
            }

            /*
             *          catch (CRIDEError* perr)
             *          {
             *                  pvecErrors.push_back(perr);
             *                  plexAnal.SynchronizeTo(EXPRESSION, pSymbolTable);
             *          }
             *          return 0;
             */
        }
示例#5
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CToken pToken = null;
            //try
            {
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (RUL_TOKEN_SUBTYPE.RUL_SEMICOLON != pToken.GetSubType()))
                {
                    return(0);
                }
                return(1);
            }

            /*
             *          catch (CRIDEError* perr)
             *          {
             *                  pvecErrors->push_back(perr);
             *                  plexAnal->SynchronizeTo(EXPRESSION, pSymbolTable);
             *          }
             *          catch (...)
             *          {
             *                  throw (C_UM_ERROR_UNKNOWNERROR);
             *          }
             *          return PARSE_FAIL;
             */
        }
示例#6
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CToken pToken = null;

            //try
            {
                //Munch a <{>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_LBRACK))
                {
                    if (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_COLON)
                    {
                        //throw (C_UM_ERROR_INTERNALERR);
                    }
                }

                //Munch List of statments...
                //try
                {
                    m_pStmtList = new CStatementList();
                    m_pStmtList.CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                }

                /*
                 * catch (CRIDEError* perr)
                 * {
                 *      pvecErrors.push_back(perr);
                 *      plexAnal.MoveTo(
                 *              RUL_SYMBOL,
                 *              RUL_RBRACK,
                 *              pSymbolTable);
                 * }
                 */
                //Munch a <}>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_RBRACK))
                {
                    //ADD_ERROR(C_CS_ERROR_MISSINGRBRACK);
                    plexAnal.UnGetToken();
                }
                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;
             */
        }
示例#7
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CParserBuilder builder = new CParserBuilder();
            CGrammarNode   pStmt   = null;

            int i = 0;

            //try
            {
                while (true)
                {
                    i++;

                    if (i == 0xb)
                    {
                        ;
                    }

                    pStmt = builder.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_asic);
                    if (pStmt == null)
                    {
                        if (plexAnal.IsEndOfSource())
                        {
                            return(1);
                        }
                        else
                        {
                            CToken pToken = null;

                            if ((CLexicalAnalyzer.LEX_FAIL != plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) && pToken != null)
                            {
                                if (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_SEMICOLON)
                                {
                                    continue;
                                }
                                else
                                {
                                    plexAnal.UnGetToken();
                                }
                            }

                            return(0);
                        }
                    }
                    pStmt.SetScopeIndex(plexAnal.GetSymbolTableScopeIndex());         //SCR26200 Felix
                    m_stmtList.Add((CStatement)pStmt);
                    pStmt.CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                }//end of while loop

                //return 1;
            }

            /*
             *          catch (...)
             *          {
             *                  return PARSE_FAIL;
             *          }
             */
        }
示例#8
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CExpParser expParser = new CExpParser();
            CToken     pToken    = null;
            //try
            {
                m_pIfExpression = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_ASSIGN, false);
                if (m_pIfExpression == null)
                {
                    //throw (C_IF_ERROR_MISSINGEXP);
                }

                //Munch a <?>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) || pToken == null ||
                    !((pToken.GetType() == RUL_TOKEN_TYPE.RUL_SYMBOL) && (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_QMARK)))
                {
                    //throw (C_RS_ERROR_MISSINGSC);
                }

                m_pTrueExpression = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_ASSIGN, false);
                if (m_pTrueExpression == null)
                {
                    //throw (C_RS_ERROR_MISSINGSC);
                }

                //Munch a <:>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) || pToken == null ||
                    !((pToken.GetType() == RUL_TOKEN_TYPE.RUL_SYMBOL) && (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_COLON)))
                {
                    //throw (C_RS_ERROR_MISSINGSC);
                }

                m_pFalseExpression = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_ASSIGN, false);                //Vibhor 110205: Changed from EXPR_FOR
                if (m_pFalseExpression == null)
                {
                    //throw (C_RS_ERROR_MISSINGSC);
                }

                //Munch a <;>

                /*		if((LEX_FAIL == plexAnal.GetNextToken(&pToken,pSymbolTable))
                || !pToken
                || !pToken.IsEOS())
                ||              {
                ||                      throw(C_RS_ERROR_MISSINGSC);
                ||              }*/

                return(0);
            }

            /*
             * catch (...)
             * {
             *      return PARSE_FAIL;
             * }
             * return 0;
             */
        }
示例#9
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CToken pToken = null;
            //try
            {
                //Munch a <return>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    !pToken.IsRETURNStatement())
                {
                    //throw (C_UM_ERROR_INTERNALERR);
                }
                //Munch a <;>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_SEMICOLON)   //Anil Octobet 5 2005 for handling Method Calling Method
                {
                    //throw(C_UM_ERROR_INTERNALERR)//Commented by anil
                    //this is the case of Void return so no need to parse the futher satement
                    m_pExpression = null;//Anil Octobet 5 2005 for handling Method Calling Method
                    return(1);
                }
                plexAnal.UnGetToken();

                //Added Anil Octobet 5 2005 for handling Method Calling Method
                //Return statement may be a Expression So Do Parse those Expression and Push it on to m_pExpression
                CExpParser 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);
                 *              }
                 */
                return(1);
            }

            /*
             *          catch (CRIDEError* perr)
             *          {
             *                  pvecErrors.push_back(perr);
             *                  plexAnal.SynchronizeTo(EXPRESSION, pSymbolTable);
             *          }
             *          catch (...)
             *          {
             *                  throw (C_UM_ERROR_UNKNOWNERROR);
             *          }
             *          return PARSE_FAIL;
             */
        }
示例#10
0
 public CAssignmentStatement()
 {
     SetNodeType(GRAMMAR_NODE_TYPE.NODE_TYPE_ASSIGN);
     m_pExpression   = new CExpression();
     m_pComplexDDExp = new CExpression();
     m_pArrayExp     = new CExpression();
     m_pOMExp        = new COMServiceExpression();
     m_pVariable     = new CToken();
 }
示例#11
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            int    i32Ret = 0;
            CToken pToken = null;
            //try
            {
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_LBRACK))
                {
                    //DELETE_PTR(pToken);//clean up memory even on errors
                    //throw (C_UM_ERROR_INTERNALERR);
                }

                m_pDeclarations = new CDeclarations();
                i32Ret          = m_pDeclarations.CreateParseSubTree(ref plexAnal, ref pSymbolTable);

                m_pStmtList = new CStatementList();
                i32Ret      = m_pStmtList.CreateParseSubTree(ref plexAnal, ref pSymbolTable);

                if (0 == i32Ret)
                {
                    if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                        pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_RBRACK))
                    {
                        //DELETE_PTR(pToken);//clean up memory, even on errors
                        //throw (C_UM_ERROR_INTERNALERR);
                        return(i32Ret);
                    }
                    else
                    {
                        return(1);
                    }
                }
                return(0);
            }

            /*
             *          catch (CRIDEError* perr)
             *          {
             *                  //if nobody has bothered to catch the error till now,
             *                  //what else can be done but to just eat it and keep quiet...
             *                  pvecErrors.push_back(perr);
             *          }
             *          catch (...)
             *          {
             *                  throw (C_UM_ERROR_UNKNOWNERROR);
             *          }
             *          return i32Ret;
             */
        }
示例#12
0
        public int GetIndex(string pszTokenName)  //Vibhor 010705: Made Public
        {
            int nSize = m_symbol_table.Count;

            for (int i = 0; i < nSize; i++)
            {
                CToken pToken = m_symbol_table[i].Token;
                if (pToken.GetLexeme() == pszTokenName)
                {
                    return(i);
                }
            }
            return(-1);
        }
示例#13
0
        public int Insert(CToken token)
        {
            int nIdx = GetIndex(token.GetLexeme());

            if (-1 == nIdx)
            {
                CVariable pNewToken = new CVariable();
                pNewToken.setCVariable(token);
                pNewToken.SetSymbolTableIndex(m_symbol_table.Count);
                m_symbol_table.Add(pNewToken);

                return(m_symbol_table.Count - 1);
            }
            return(nIdx);
        }
示例#14
0
        public int Insert(CToken token, int m_ScopeIndex)
        {
            int nIdx = -1;

            if ((nIdx = Find(token.GetLexeme(), m_ScopeIndex)) == 0)
            {
                CVariable pNewToken = new CVariable();
                pNewToken.setCVariable(token);
                pNewToken.SetSymbolTableIndex(m_symbol_table.Count);
                pNewToken.Token.SetSymbolTableScopeIndex(m_ScopeIndex);
                m_symbol_table.Add(pNewToken);

                return(m_symbol_table.Count - 1);
            }
            return(nIdx);// return what Find found
        }
示例#15
0
 public int InsertConstant(CToken token)
 {
     /*
      * CONSTANT_POOL_UTF8 pconst_entry = new CONSTANT_POOL_UTF8();
      * m_constant_pool_table.Add(pconst_entry);
      * pconst_entry.tag = CONSTANT_Utf8;
      *
      * short i16Count = (short)token.GetLexeme().Length;
      * pconst_entry.length = _MSB_INT16(i16Count);
      * pconst_entry.length <<= 8;
      * pconst_entry.length |= _LSB_INT16(i16Count);
      * pconst_entry.pBytes = new byte[pconst_entry.length + 1];
      * //memset(pconst_entry.pBytes, 0, pconst_entry.length + 1);
      * memcpy(pconst_entry.pBytes, token.GetLexeme(), pconst_entry.length);
      *
      * return m_constant_pool_table.Count - 1;
      */
     return(0);
 }
示例#16
0
        public int GetIndex(string pszTokenName, int m_nSymbolTableScopeIndex) //SCR26200 Felix
        {
            int nSize = m_symbol_table.Count;

            for (int i = 0; i < nSize; i++)
            {
                CToken pToken = m_symbol_table[i].Token;
                if (pToken.GetLexeme() == pszTokenName && (pToken.GetSymbolTableScopeIndex() == m_nSymbolTableScopeIndex))
                {
                    return(i);
                }
            }

            for (int i = 0; i < nSize; i++)
            {
                CToken pToken = m_symbol_table[i].Token;
                if (pToken.GetLexeme() == pszTokenName)
                {
                    return(i);
                }
            }
            return(-1);
        }
示例#17
0
        //	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;
             */
        }
示例#18
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CToken pToken = null;
            {
                //Munch a <IF>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || !pToken.IsIFStatement())
                {
                    //throw(C_UM_ERROR_INTERNALERR);
                }

                //Munch a <(>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_LPAREN))
                {
                    //ADD_ERROR(C_IF_ERROR_MISSINGLP);
                    plexAnal.UnGetToken();
                }

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

                //Munch a <)>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_RPAREN))
                {
                    //ADD_ERROR(C_IF_ERROR_MISSINGRP);
                    plexAnal.UnGetToken();
                }

                //Eat a Statement...
                CParserBuilder builder = new CParserBuilder();
                m_pStatement = (CStatement)builder.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_asic);
                if (null != m_pStatement)
                {
                    int i32Ret = m_pStatement.CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                    if (i32Ret == 0)
                    {
                        //ADD_ERROR(C_IF_ERROR_MISSINGSTMT);
                    }
                }
                else
                {
                    //ADD_ERROR(C_IF_ERROR_MISSINGSTMT);
                }

                //See if you can snatch a "else"
                try
                {
                    m_pElse = (CELSEStatement)builder.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_SELECTION);
                    if (null != m_pElse)
                    {
                        m_pElse.CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                    }
                }
                catch (Exception ex)
                {
                    string exinfo = ex.Message;
                    //return 0;
                }

                return(1);
            }
        }
示例#19
0
        public void setCVariable(CToken pToken)
        {
            Token   = pToken;
            m_Value = new INTER_VARIANT();
            RUL_TOKEN_TYPE    Type    = pToken.GetType();
            RUL_TOKEN_SUBTYPE SubType = pToken.GetSubType();

            if (Type == RUL_TOKEN_TYPE.RUL_SIMPLE_VARIABLE)
            {
                byte[] data;
                switch (SubType)
                {
                case RUL_TOKEN_SUBTYPE.RUL_CHAR_DECL:
                    data = BitConverter.GetBytes(' ');
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_CHAR);    // = (char)' ';
                    break;

                case RUL_TOKEN_SUBTYPE.RUL_LONG_LONG_DECL:
                    //m_Value = (Int64)0;
                    data = BitConverter.GetBytes((Int64)0);
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_LONGLONG);    // = (char)' ';
                    break;

                // Walt EPM 08sep08 - added
                case RUL_TOKEN_SUBTYPE.RUL_UNSIGNED_SHORT_INTEGER_DECL:
                    //m_Value = (ushort)0;
                    data = BitConverter.GetBytes((ushort)0);
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_USHORT);    // = (char)' ';
                    break;

                case RUL_TOKEN_SUBTYPE.RUL_SHORT_INTEGER_DECL:
                    //m_Value = (short)0;
                    data = BitConverter.GetBytes((short)0);
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_SHORT);    // = (char)' ';
                    break;

                case RUL_TOKEN_SUBTYPE.RUL_UNSIGNED_INTEGER_DECL:
                    //m_Value = (uint)0;
                    data = BitConverter.GetBytes((uint)0);
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_UINT);    // = (char)' ';
                    break;

                // Walt EPM 08sep08 - end added
                case RUL_TOKEN_SUBTYPE.RUL_INTEGER_DECL:
                case RUL_TOKEN_SUBTYPE.RUL_LONG_DECL:
                    //m_Value = (long)0;
                    data = BitConverter.GetBytes((int)0);
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_INT);    // = (char)' ';
                    break;

                case RUL_TOKEN_SUBTYPE.RUL_BOOLEAN_DECL:
                    //m_Value = (bool)false;
                    data = BitConverter.GetBytes(false);
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_BOOL);    // = (char)' ';
                    break;

                case RUL_TOKEN_SUBTYPE.RUL_REAL_DECL:
                    //m_Value = (float)0.0;
                    data = BitConverter.GetBytes((float)0.0);
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_FLOAT);    // = (char)' ';
                    break;

                case RUL_TOKEN_SUBTYPE.RUL_DOUBLE_DECL:
                    //m_Value = (double)0.0;//WS:EPM 10aug07
                    data = BitConverter.GetBytes((double)0);
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_DOUBLE);    // = (char)' ';
                    break;

                case RUL_TOKEN_SUBTYPE.RUL_STRING_DECL:
                case RUL_TOKEN_SUBTYPE.RUL_DD_STRING_DECL:     //Added By Anil July 07 2005
                    //m_Value = (string)"";
                    data = System.Text.Encoding.Default.GetBytes("");
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_DD_STRING);    // = (char)' ';
                    break;

                case RUL_TOKEN_SUBTYPE.RUL_UNSIGNED_CHAR_DECL:
                    //m_Value = (byte)' ';//WHS EP June17-2008 have changed this to make sure that it works for all data types
                    data = BitConverter.GetBytes(' ');
                    m_Value.SetValue(data, 0, VARIANT_TYPE.RUL_UNSIGNED_CHAR);    // = (char)' ';
                    break;
                }
            }
        }
示例#20
0
 EXPR_VECTOR m_vecExpressions;   //each dim in actual array corresponds
 public CArrayExpression()
 {
     m_pToken         = new CToken();
     m_vecExpressions = new EXPR_VECTOR();
 }
示例#21
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CToken pToken = null;
            //try
            {
                //Munch a <SWITCH>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_SWITCH))
                {
                    //throw (C_UM_ERROR_INTERNALERR);
                }

                //Munch a <(>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_LPAREN))
                {
                    //ADD_ERROR(C_IF_ERROR_MISSINGLP);
                    plexAnal.UnGetToken();
                }

                //Munch & Parse the expression.
                //we got to give the expression string to the expression parser.
                //
                CParserBuilder builder2  = new CParserBuilder();
                CExpParser     expParser = new CExpParser();
                CGrammarNode   pNode     = null;

                pNode = builder2.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_asic);

                m_pExpression          = null;
                m_pExpressionStatement = null;
                if (null != pNode)
                {
                    expressionNodeType = pNode.GetNodeType();
                    if (expressionNodeType == GRAMMAR_NODE_TYPE.NODE_TYPE_ASSIGN)
                    {
                        expressionNodeType     = GRAMMAR_NODE_TYPE.NODE_TYPE_ASSIGN;
                        m_pExpressionStatement = (CAssignmentStatement)pNode;

                        m_pExpressionStatement.CreateParseSubTree(ref plexAnal, ref pSymbolTable, STATEMENT_TYPE.STMT_ASSIGNMENT_FOR);
                    }
                    else if (expressionNodeType == GRAMMAR_NODE_TYPE.NODE_TYPE_EXPRESSION)
                    {
                        expressionNodeType = GRAMMAR_NODE_TYPE.NODE_TYPE_EXPRESSION;
                        m_pExpression      = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_FOR);

                        if (m_pExpression == null)
                        {
                            //ADD_ERROR(C_WHILE_ERROR_MISSINGEXP);
                        }
                    }
                }
                else
                {
                    //ADD_ERROR(C_WHILE_ERROR_MISSINGSTMT);
                }

                //Munch a <)>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_RPAREN))
                {
                    //ADD_ERROR(C_IF_ERROR_MISSINGRP);
                    plexAnal.UnGetToken();
                }

                //Munch a <{>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_LBRACK))
                {
                    //ADD_ERROR(C_IF_ERROR_MISSINGRP);
                    plexAnal.UnGetToken();
                }

                //See if you can snatch a "case"
                CParserBuilder builder = new CParserBuilder();
                int            iNumberOfCaseStatements = 0;
                m_pCase[iNumberOfCaseStatements] = (CCASEStatement)builder.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_SELECTION);
                while (null != (m_pCase[iNumberOfCaseStatements]))
                {
                    m_pCase[iNumberOfCaseStatements].CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                    if (m_pCase[iNumberOfCaseStatements].IsDefaultStatement())
                    {
                        m_bIsDefaultPresent = true;
                        m_pDefaultCase      = m_pCase[iNumberOfCaseStatements];
                    }
                    else
                    {
                        iNumberOfCaseStatements++;
                    }
                    m_pCase[iNumberOfCaseStatements] = (CCASEStatement)builder.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_SELECTION);
                }
                m_iNumberOfCasesPresent = iNumberOfCaseStatements;

                //Munch a <}>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_RBRACK))
                {
                    //ADD_ERROR(C_IF_ERROR_MISSINGRP);
                    plexAnal.UnGetToken();
                }

                /* VMKP Commented on 140404,  For INOR device
                 *      Sensor selection method is crashing with this Fix */
                /*	if (pNode)	//TSRPRASAD 09MAR2004 Fix the memory leaks
                 *      {
                 *              delete pNode;
                 *              pNode = null;
                 *      }*/
                /* VMKP Commented on 140404 */

                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;
             */
        }
示例#22
0
 public CComplexDDExpression(CToken pToken)
 {
     m_pToken         = pToken;
     m_vecExpressions = new EXPR_VECTOR();
 }
示例#23
0
 public CArrayExpression(CToken pToken)
 {
     m_pToken         = pToken;
     m_vecExpressions = new EXPR_VECTOR();
 }
示例#24
0
        EXPR_VECTOR m_vecExpressions;   //each dim in actual array corresponds

        public CComplexDDExpression()
        {
            m_pToken         = new CToken();
            m_vecExpressions = new EXPR_VECTOR();
        }
示例#25
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            //Eat a Statement...
            CToken pToken = null;
            //try
            {
                //Munch a <CASE>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_CASE)
                    )
                {
                    if (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_DEFAULT)
                    {
                        //throw (C_UM_ERROR_INTERNALERR);
                    }
                    else
                    {
                        m_bIsDefaultCase = true;
                    }
                }

                //Munch & Parse the expression.
                //we got to give the expression string to the expression parser.
                //
                if (m_bIsDefaultCase != true)
                {
                    CExpParser expParser = new CExpParser();
                    //try
                    {
                        m_pExpression = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_CASE);
                        if (m_pExpression == null)
                        {
                            //ADD_ERROR(C_IF_ERROR_MISSINGEXP);
                        }
                    }

                    /*
                     * catch (CRIDEError* perr)
                     * {
                     *      pvecErrors.push_back(perr);
                     *      plexAnal.SynchronizeTo(EXPRESSION, ref pSymbolTable);
                     * }
                     */
                }

                //Munch a <:>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || (pToken.GetSubType() != RUL_TOKEN_SUBTYPE.RUL_COLON))
                {
                    //throw (C_UM_ERROR_INTERNALERR);
                }

                if ((CLexicalAnalyzer.LEX_FAIL != plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) &&
                    pToken != null && (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_CASE))
                {
                    plexAnal.UnGetToken();
                    m_pStatementList = null;
                    return(1);
                }
                plexAnal.UnGetToken();

                //Look for a statement
                m_pStatementList = new CStatementList();

                /*		if((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken,pSymbolTable))
                || !pToken
                || (pToken.GetSubType() != RUL_LBRACK)
                ||                      )
                ||              {
                ||                      plexAnal.UnGetToken();
                ||              }
                ||              else
                ||              {
                ||                      bCompoundStatement = true;
                ||              }
                ||              DELETE_PTR(pToken);*/

                bool bCompoundStatement = false;
                int  iBrackCount        = 0;
                while (true)
                {
                    if (CLexicalAnalyzer.LEX_FAIL != plexAnal.GetNextToken(ref pToken, ref pSymbolTable))
                    {
                        if ((pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_LBRACK) && (bCompoundStatement))
                        {
                            bCompoundStatement = true;
                            iBrackCount++;
                        }
                        if ((pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_RBRACK) && (bCompoundStatement))
                        {
                            if (bCompoundStatement == true)
                            {
                                iBrackCount--;
                                if (iBrackCount == 0)
                                {
                                    bCompoundStatement = false;
                                }
                            }
                        }

                        if ((pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_CASE) || (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_DEFAULT))
                        {
                            plexAnal.UnGetToken();
                            break;
                        }

                        plexAnal.UnGetToken();
                    }

                    CGrammarNode   pStmt   = null;
                    CParserBuilder builder = new CParserBuilder();

                    pStmt = builder.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_asic);
                    if (pStmt == null)
                    {
                        if (plexAnal.IsEndOfSource())
                        {
                            return(1);
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    m_pStatementList.AddStatement((CStatement)pStmt);
                    int i32Ret = pStmt.CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                    if (i32Ret == 0)
                    {
                        //ADD_ERROR(C_ES_ERROR_MISSINGSTMT);
                    }
                }
                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;
             */
        }
示例#26
0
 public CVariable()
 {
     m_Value = new INTER_VARIANT();
     Token   = new CToken();
 }
示例#27
0
 public CPrimaryExpression(CToken pToken)
 {
     m_pToken = pToken;
 }
示例#28
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);
        }
示例#29
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;
             */
        }
示例#30
0
        //	Create as much of the parse tree as possible.
        public override int CreateParseSubTree(ref CLexicalAnalyzer plexAnal, ref CSymbolTable pSymbolTable)
        {
            CToken pToken = null;
            //try
            {
                //Munch a <FOR>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || !pToken.IsFORStatement())
                {
                    //throw (C_UM_ERROR_INTERNALERR);
                }

                //Munch a <(>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || !(pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_LPAREN))
                {
                    //ADD_ERROR(C_WHILE_ERROR_MISSINGLP);
                    plexAnal.UnGetToken();
                }

                //Munch a Initialization Statement...
                CParserBuilder builder = new CParserBuilder();
                m_pInitializationStatement = (CAssignmentStatement)builder.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_asic);
                if (null != (m_pInitializationStatement))
                {
                    m_pInitializationStatement.CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                }
                else
                {
                    //Munch a <;>
                    if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                        pToken == null || !(pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_SEMICOLON))
                    {
                        //ADD_ERROR(C_WHILE_ERROR_MISSINGLP);
                        plexAnal.UnGetToken();
                    }
                }

                //Munch & Parse the expression.
                //we got to give the expression string to the expression parser.
                //
                CParserBuilder builder2  = new CParserBuilder();
                CExpParser     expParser = new CExpParser();
                CGrammarNode   pNode;

                pNode = builder2.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_asic);

                m_pExpression          = null;
                m_pExpressionStatement = null;
                if (null != pNode)
                {
                    expressionNodeType = pNode.GetNodeType();
                    if (expressionNodeType == GRAMMAR_NODE_TYPE.NODE_TYPE_ASSIGN)
                    {
                        expressionNodeType     = GRAMMAR_NODE_TYPE.NODE_TYPE_ASSIGN;
                        m_pExpressionStatement = (CAssignmentStatement)pNode;

                        m_pExpressionStatement.CreateParseSubTree(ref plexAnal, ref pSymbolTable, STATEMENT_TYPE.STMT_asic);
                    }
                    else if (expressionNodeType == GRAMMAR_NODE_TYPE.NODE_TYPE_EXPRESSION)
                    {
                        expressionNodeType = GRAMMAR_NODE_TYPE.NODE_TYPE_EXPRESSION;
                        m_pExpression
                            = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_FOR);

                        if (m_pExpression == null)
                        {
                            //ADD_ERROR(C_WHILE_ERROR_MISSINGEXP);
                        }
                    }
                    else if (expressionNodeType == GRAMMAR_NODE_TYPE.NODE_TYPE_INVALID)
                    {
                        pToken = null;

                        //try
                        {
                            if ((CLexicalAnalyzer.LEX_FAIL != (plexAnal.LookAheadToken(ref pToken))) && pToken != null)
                            {
                                if ((pToken.GetType() == RUL_TOKEN_TYPE.RUL_SYMBOL) && (pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_SEMICOLON))
                                {
                                    // This code is to handle for(;;) for Yokagawa EJX
                                    expressionNodeType = GRAMMAR_NODE_TYPE.NODE_TYPE_EXPRESSION;
                                    CToken pToken2 = new CToken("1");
                                    pToken2.SetType(RUL_TOKEN_TYPE.RUL_NUMERIC_CONSTANT);
                                    m_pExpression = new CPrimaryExpression(pToken2);
                                }
                            }
                        }

                        /*
                         *                      catch (...)
                         *                      {
                         *                      }
                         */
                    }
                }
                else
                {
                    //ADD_ERROR(C_WHILE_ERROR_MISSINGSTMT);
                }

                //Munch a <;>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || !(pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_SEMICOLON))
                {
                    //ADD_ERROR(C_WHILE_ERROR_MISSINGLP);
                    plexAnal.UnGetToken();
                }

                //Munch a Increment Statement...
                pNode = builder2.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_asic);

                m_pIncrementExpression = null;
                m_pIncrementStatement  = null;
                if (null != pNode)
                {
                    incrementNodeType = pNode.GetNodeType();
                    if (incrementNodeType == GRAMMAR_NODE_TYPE.NODE_TYPE_ASSIGN)
                    {
                        incrementNodeType     = GRAMMAR_NODE_TYPE.NODE_TYPE_ASSIGN;
                        m_pIncrementStatement = (CAssignmentStatement)pNode;

                        m_pIncrementStatement.CreateParseSubTree(ref plexAnal, ref pSymbolTable, STATEMENT_TYPE.STMT_ASSIGNMENT_FOR);
                    }
                    else if (incrementNodeType == GRAMMAR_NODE_TYPE.NODE_TYPE_EXPRESSION)
                    {
                        incrementNodeType = GRAMMAR_NODE_TYPE.NODE_TYPE_EXPRESSION;
                        m_pIncrementExpression
                            = expParser.ParseExpression(ref plexAnal, ref pSymbolTable, STMT_EXPR_TYPE.EXPR_FOR);

                        if (m_pIncrementExpression == null)
                        {
                            //ADD_ERROR(C_WHILE_ERROR_MISSINGEXP);
                        }
                    }
                }
                else
                {
                    //ADD_ERROR(C_WHILE_ERROR_MISSINGSTMT);
                }

                //Munch a <)>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || !(pToken.GetSubType() == RUL_TOKEN_SUBTYPE.RUL_RPAREN))
                {
                    //ADD_ERROR(C_WHILE_ERROR_MISSINGLP);
                    plexAnal.UnGetToken();
                }

                //Munch the statement
                CParserBuilder builder3 = new CParserBuilder();
                m_pStatement = (CStatement)builder.CreateParser(ref plexAnal, STATEMENT_TYPE.STMT_asic);
                if (null != (m_pStatement))
                {
                    m_pStatement.CreateParseSubTree(ref plexAnal, ref pSymbolTable);
                }
                else
                {
                    //ADD_ERROR(C_WHILE_ERROR_MISSINGSTMT);
                }

                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;
             */
        }