Ejemplo n.º 1
0
        public override int VisitExpr_PLUSMINUS(MINICParser.Expr_PLUSMINUSContext context)
        {
            ASTComposite m_parent = m_parents.Peek();

            if (context.op.Type == MINICParser.MINUS)
            {
                CASTExpressionSubtraction newnode = new CASTExpressionSubtraction(context.GetText(), m_parents.Peek(), 2);
                m_parent.AddChild(newnode, m_parentContext.Peek());
                m_parents.Push(newnode);

                this.VisitElementInContext(context.expression(0), m_parentContext, contextType.CT_EXPRESSION_SUBTRACTION_LEFT);
                this.VisitElementInContext(context.expression(1), m_parentContext, contextType.CT_EXPRESSION_SUBTRACTION_RIGHT);
            }
            else if (context.op.Type == MINICParser.PLUS)
            {
                CASTExpressionAddition newnode = new CASTExpressionAddition(context.GetText(), m_parents.Peek(), 2);
                m_parent.AddChild(newnode, m_parentContext.Peek());
                m_parents.Push(newnode);

                this.VisitElementInContext(context.expression(0), m_parentContext, contextType.CT_EXPRESSION_ADDITION_LEFT);
                this.VisitElementInContext(context.expression(1), m_parentContext, contextType.CT_EXPRESSION_ADDITION_RIGHT);
            }



            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 2
0
 public Result VisitContext(ASTComposite node, contextType ct, VParam param = default(VParam))
 {
     foreach (ASTElement item in node.MChildren[node.GetContextIndex(ct)])
     {
         item.Accept(this, param);
     }
     return(default(Result));
 }
Ejemplo n.º 3
0
        public override int VisitStatement_BreakStatement(MINICParser.Statement_BreakStatementContext context)
        {
            ASTComposite       m_parent = m_parents.Peek();
            CASTBreakStatement newnode  = new CASTBreakStatement(context.GetText(), m_parents.Peek(), 0);

            m_parent.AddChild(newnode, m_parentContext.Peek());
            return(0);
        }
Ejemplo n.º 4
0
 public Result VisitChildren(ASTComposite node, VParam param = default(VParam))
 {
     for (int i = 0; i < node.MChildren.Length; i++)
     {
         foreach (ASTElement item in node.MChildren[i])
         {
             item.Accept(this, param);
         }
     }
     return(default(Result));
 }
Ejemplo n.º 5
0
        public override int VisitCompileUnit(MINICParser.CompileUnitContext context)
        {
            CASTCompileUnit newnode = new CASTCompileUnit(context.GetText(), null, 2);

            m_root = newnode;
            m_parents.Push(newnode);
            this.VisitElementsInContext(context.statement(), m_parentContext, contextType.CT_COMPILEUNIT_MAINBODY);
            this.VisitElementsInContext(context.functionDefinition(), m_parentContext, contextType.CT_COMPILEUNIT_FUNCTIONDEFINITIONS);
            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 6
0
        public override int VisitExpr_PLUS(MINICParser.Expr_PLUSContext context)
        {
            ASTComposite       m_parent = m_parents.Peek();
            CASTExpressionPlus newnode  = new CASTExpressionPlus(context.GetText(), m_parents.Peek(), 1);

            m_parent.AddChild(newnode, m_parentContext.Peek());
            m_parents.Push(newnode);
            this.VisitElementInContext(context.expression(), m_parentContext, contextType.CT_EXPRESSION_PLUS);

            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 7
0
        public override int VisitStatement_ReturnStatement(MINICParser.Statement_ReturnStatementContext context)
        {
            ASTComposite        m_parent = m_parents.Peek();
            CASTReturnStatement newnode  = new CASTReturnStatement(context.GetText(), m_parents.Peek(), 1);

            m_parent.AddChild(newnode, m_parentContext.Peek());
            m_parents.Push(newnode);

            this.VisitElementInContext(context.expression(), m_parentContext, contextType.CT_STATEMENT_RETURN);

            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 8
0
        public override int VisitWhilestatement(MINICParser.WhilestatementContext context)
        {
            ASTComposite       m_parent = m_parents.Peek();
            CASTWhileStatement newnode  = new CASTWhileStatement(context.GetText(), m_parents.Peek(), 2);

            m_parent.AddChild(newnode, m_parentContext.Peek());
            m_parents.Push(newnode);
            this.VisitElementInContext(context.expression(), m_parentContext, contextType.CT_WHILESTATEMENT_CONDITION);
            this.VisitElementInContext(context.statement(), m_parentContext, contextType.CT_WHILESTATEMENT_BODY);

            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 9
0
        public override int VisitCompoundStatement(MINICParser.CompoundStatementContext context)
        {
            ASTComposite          m_parent = m_parents.Peek();
            CASTCompoundStatement newnode  = new CASTCompoundStatement(context.GetText(), m_parents.Peek(), 1);

            m_parent.AddChild(newnode, m_parentContext.Peek());
            m_parents.Push(newnode);

            this.VisitElementInContext(context.statementList(), m_parentContext, contextType.CT_COMPOUNDSTATEMENT);

            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 10
0
        public override int VisitExpr_ASSIGN(MINICParser.Expr_ASSIGNContext context)
        {
            ASTComposite         m_parent = m_parents.Peek();
            CASTExpressionAssign newnode  = new CASTExpressionAssign(context.GetText(), m_parents.Peek(), 2);

            m_parent.AddChild(newnode, m_parentContext.Peek());
            m_parents.Push(newnode);

            this.VisitTerminalInContext(context, context.IDENTIFIER().Symbol, m_parentContext, contextType.CT_EXPRESSION_ASSIGN_LVALUE);
            this.VisitElementInContext(context.expression(), m_parentContext, contextType.CT_EXPRESSION_ASSIGN_EXPRESSION);
            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 11
0
        public override int VisitExpr_NEQUAL(MINICParser.Expr_NEQUALContext context)
        {
            ASTComposite         m_parent = m_parents.Peek();
            CASTExpressionNequal newnode  = new CASTExpressionNequal(context.GetText(), m_parents.Peek(), 2);

            m_parent.AddChild(newnode, m_parentContext.Peek());
            m_parents.Push(newnode);

            this.VisitElementInContext(context.expression(0), m_parentContext, contextType.CT_EXPRESSION_NEQUAL_LEFT);
            this.VisitElementInContext(context.expression(1), m_parentContext, contextType.CT_EXPRESSION_NEQUAL_RIGHT);

            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 12
0
        public override int VisitFunctionDefinition(MINICParser.FunctionDefinitionContext context)
        {
            ASTComposite           m_parent = m_parents.Peek();
            CASTFunctionDefinition newnode  = new CASTFunctionDefinition(context.GetText(), m_parents.Peek(), 3);

            m_parent.AddChild(newnode, m_parentContext.Peek());
            m_parents.Push(newnode);
            this.VisitTerminalInContext(context, context.IDENTIFIER().Symbol, m_parentContext,
                                        contextType.CT_FUNCTIONDEFINITION_IDENTIFIER);
            if (context.fargs() != null)
            {
                this.VisitElementInContext(context.fargs(), m_parentContext, contextType.CT_FUNCTIONDEFINITION_FARGS);
            }
            this.VisitElementInContext(context.compoundStatement(), m_parentContext, contextType.CT_FUNCTIONDEFINITION_BODY);
            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 13
0
        public override int VisitIfstatement(MINICParser.IfstatementContext context)
        {
            ASTComposite    m_parent = m_parents.Peek();
            CASTIfStatement newnode  = new CASTIfStatement(context.GetText(), m_parents.Peek(), 3);

            m_parent.AddChild(newnode, m_parentContext.Peek());
            m_parents.Push(newnode);

            this.VisitElementInContext(context.expression(), m_parentContext, contextType.CT_IFSTATEMENT_CONDITION);
            this.VisitElementInContext(context.statement(0), m_parentContext, contextType.CT_IFSTATEMENT_IFCLAUSE);
            if (context.statement(1) != null)
            {
                this.VisitElementInContext(context.statement(1), m_parentContext, contextType.CT_IFSTATEMENT_ELSECLAUSE);
            }
            m_parents.Pop();
            return(0);
        }
Ejemplo n.º 14
0
        /// ###########################################################################|
        /// ExtractSubgraphs ##########################################################|
        /// ###########################################################################|
        /// Αυτή η μέδοδος χωρίζει τα παιδιά σε περιοχές, ανάλογα με τον γωνέα τους ###|
        /// ###########################################################################|
        private void ExtractSubgraphs(ASTComposite node, contextType context)
        {
            if (node.MChildren[node.GetContextIndex(context)].Count != 0)
            {
                m_ostream.WriteLine("\tsubgraph cluster" + m_clusterSerial++ + "{");
                m_ostream.WriteLine("\t\tnode [style=filled,color=white];");
                m_ostream.WriteLine("\t\tstyle=filled;");
                m_ostream.WriteLine("\t\tcolor=lightgrey;");
                m_ostream.Write("\t\t");
                for (int i = 0; i < node.MChildren[node.GetContextIndex(context)].Count; i++)
                {
                    m_ostream.Write(node.MChildren[node.GetContextIndex(context)][i].MNodeName + ";");
                }

                m_ostream.WriteLine("\n\t\tlabel=" + context + ";");
                m_ostream.WriteLine("\t}");
            }
        }
Ejemplo n.º 15
0
        public override int VisitTerminal(ITerminalNode node)
        {
            ASTComposite m_parent = m_parents.Peek();

            switch (node.Symbol.Type)
            {
            case MINICLexer.NUMBER:
                CASTNUMBER newnode1 = new CASTNUMBER(node.Symbol.Text, m_parents.Peek());
                m_parent.AddChild(newnode1, m_parentContext.Peek());
                break;

            case MINICLexer.IDENTIFIER:
                CASTIDENTIFIER newnode2 = new CASTIDENTIFIER(node.Symbol.Text, m_parents.Peek());
                m_parent.AddChild(newnode2, m_parentContext.Peek());
                break;

            default:
                break;
            }
            return(base.VisitTerminal(node));
        }
Ejemplo n.º 16
0
        public override int VisitExpr_DIVMULT(MINICParser.Expr_DIVMULTContext context)
        {
            ASTComposite m_parent = m_parents.Peek();

            if (context.op.Type == MINICParser.MULT)
            {
                CASTExpressionMultiplication newnode = new CASTExpressionMultiplication(context.GetText(), m_parents.Peek(), 2);
                m_parent.AddChild(newnode, m_parentContext.Peek());
                m_parents.Push(newnode);
                this.VisitElementInContext(context.expression(0), m_parentContext, contextType.CT_EXPRESSION_MULTIPLICATION_LEFT);
                this.VisitElementInContext(context.expression(1), m_parentContext, contextType.CT_EXPRESSION_MULTIPLICATION_RIGHT);
            }
            else if (context.op.Type == MINICParser.DIV)
            {
                CASTExpressionDivision newnode = new CASTExpressionDivision(context.GetText(), m_parents.Peek(), 2);
                m_parent.AddChild(newnode, m_parentContext.Peek());
                m_parents.Push(newnode);
                this.VisitElementInContext(context.expression(0), m_parentContext, contextType.CT_EXPRESSION_DIVISION_LEFT);
                this.VisitElementInContext(context.expression(1), m_parentContext, contextType.CT_EXPRESSION_DIVISION_RIGHT);
            }

            m_parents.Pop();
            return(0);
        }