Пример #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
        //	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);
            }
        }
Пример #3
0
 public virtual int visitStatement(CStatement 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);
 }
Пример #4
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;
             */
        }
Пример #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
            {
                //Munch a <WHILE>
                if ((CLexicalAnalyzer.LEX_FAIL == plexAnal.GetNextToken(ref pToken, ref pSymbolTable)) ||
                    pToken == null || !pToken.IsWHILEStatement())
                {
                    //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 & 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_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_WHILE);//Vibhor 150305: Changed from 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_WHILE_ERROR_MISSINGRP);
                    plexAnal.UnGetToken();
                }

                //Munch a Statement...
                CParserBuilder builder = 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;
             */
        }