public override int VisitExpr_PLUSMINUS(firstParser.Expr_PLUSMINUSContext context) { ASTComposite m_parent = m_parents.Peek(); if (context.op.Type == firstParser.MINUS) { CASTSubtraction newnode = new CASTSubtraction(context.GetText(), nodeType.NT_SUBSTRACTION, m_parents.Peek(), 2); m_parent.AddChild(newnode, m_parentContext.Peek()); m_parents.Push(newnode); this.VisitElementInContext(context.expr(0), m_parentContext, contextType.CT_SUBSTRACTION_LEFT); this.VisitElementInContext(context.expr(1), m_parentContext, contextType.CT_SUBSTRACTION_RIGHT); } else if (context.op.Type == firstParser.PLUS) { CASTAddition newnode = new CASTAddition(context.GetText(), nodeType.NT_ADDITION, m_parents.Peek(), 2); m_parent.AddChild(newnode, m_parentContext.Peek()); m_parents.Push(newnode); this.VisitElementInContext(context.expr(0), m_parentContext, contextType.CT_ADDITION_LEFT); this.VisitElementInContext(context.expr(1), m_parentContext, contextType.CT_ADDITION_RIGHT); } m_parents.Pop(); return(0); }
public override int VisitExpr_MULDIV(firstParser.Expr_MULDIVContext context) { ASTComposite m_parent = m_parents.Peek(); if (context.op.Type == firstParser.MULT) { CASTMultiplication newnode = new CASTMultiplication(context.GetText(), nodeType.NT_MULTIPLICATION, m_parents.Peek(), 2); m_parent.AddChild(newnode, m_parentContext.Peek()); m_parents.Push(newnode); this.VisitElementInContext(context.expr(0), m_parentContext, contextType.CT_MULTIPLICATION_LEFT); this.VisitElementInContext(context.expr(1), m_parentContext, contextType.CT_MULTIPLICATION_RIGHT); } else if (context.op.Type == firstParser.DIV) { CASTDivision newnode = new CASTDivision(context.GetText(), nodeType.NT_DIVISION, m_parents.Peek(), 2); m_parent.AddChild(newnode, m_parentContext.Peek()); m_parents.Push(newnode); this.VisitElementInContext(context.expr(0), m_parentContext, contextType.CT_DIVISION_LEFT); this.VisitElementInContext(context.expr(1), m_parentContext, contextType.CT_DIVISION_RIGHT); } m_parents.Pop(); return(0); }
public T VisitChildren(ASTComposite node) { for (int i = 0; i < node.MChildren.Length; i++) { foreach (ASTElement item in node.MChildren[i]) { item.Accept(this); } } return(default(T)); }
public override int VisitCompileUnit(firstParser.CompileUnitContext context) { CASTCompileUnit newnode = new CASTCompileUnit(context.GetText(), nodeType.NT_COMPILEUNIT, null, 1); m_root = newnode; m_parents.Push(newnode); this.VisitElementsInContext(context.expr(), m_parentContext, contextType.CT_COMPILEUNIT_EXPRESSIONS); m_parents.Pop(); return(0); }
public override int VisitExpr_ASSIGNMENT(firstParser.Expr_ASSIGNMENTContext context) { ASTComposite m_parent = m_parents.Peek(); CASTAssignment newnode = new CASTAssignment(context.GetText(), nodeType.NT_ASSIGNMENT, 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_ASSIGNMENT_LEFT); this.VisitElementInContext(context.expr(), m_parentContext, contextType.CT_ASSIGNMENT_RIGHT); m_parents.Pop(); return(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}"); } }
public override int VisitTerminal(ITerminalNode node) { ASTComposite m_parent = m_parents.Peek(); switch (node.Symbol.Type) { case firstLexer.NUMBER: CASTNUMBER newnode1 = new CASTNUMBER(node.Symbol.Text, nodeType.NT_NUMBER, m_parents.Peek(), 0); m_parent.AddChild(newnode1, m_parentContext.Peek()); break; case firstLexer.IDENTIFIER: CASTIDENTIFIER newnode2 = new CASTIDENTIFIER(node.Symbol.Text, nodeType.NT_IDENTIFIER, m_parents.Peek(), 0); m_parent.AddChild(newnode2, m_parentContext.Peek()); break; default: break; } return(base.VisitTerminal(node)); }
public T Visit(ASTComposite node) { return(node.Accept(this)); }