public override ASTNode VisitArithmetic([NotNull] CoolParser.ArithmeticContext context) { ArithmeticOperation operators; switch (context.op.Text) { case "*": operators = new MulNode(context); break; case "/": operators = new DivNode(context); break; case "+": operators = new AddNode(context); break; case "-": operators = new SubNode(context); break; default: throw new NotSupportedException(); } operators.LeftOperand = Visit(context.expression(0)) as ExpressionNode; // LEFT EXPRESSION operators.RightOperand = Visit(context.expression(1)) as ExpressionNode; //RIGHT EXPRESSION return(operators); }
public DivNode Divide() { DivNode divNode = new DivNode(); Match(TokenType.DIV); return(divNode); }
public override Node VisitArithmetic([NotNull] TigerParser.ArithmeticContext context) { ArithmeticNode node; switch (context.op.Text) { case "*": node = new MulNode(context); break; case "/": node = new DivNode(context); break; case "+": node = new PlusNode(context); break; case "-": node = new MinusNode(context); break; default: throw new NotSupportedException(); } node.Children.Add(Visit(context.expr(0))); // LEFT EXPRESSION node.Children.Add(Visit(context.expr(1))); // RIGHT EXPRESSION return(node); }
public override ASTNode VisitArithmetic([NotNull] CoolParser.ArithmeticContext context) { BinaryOperatorNode boNode = null; if (context.op.Text == "+") { boNode = new SumNode(context.Start.Line, context.Start.Column); } if (context.op.Text == "-") { boNode = new SubNode(context.Start.Line, context.Start.Column); } if (context.op.Text == "*") { boNode = new MulNode(context.Start.Line, context.Start.Column); } if (context.op.Text == "/") { boNode = new DivNode(context.Start.Line, context.Start.Column); } boNode.LeftOperand = Visit(context.expr(0)) as ExpressionNode; boNode.RightOperand = Visit(context.expr(1)) as ExpressionNode; return(boNode); }
private ExpressionNode TP(ExpressionNode param) { if (currentToken.Type == TokenTypes.Mult) { currentToken = lexer.GetNextToken(); var fValue = F(); var node = new MultNode { LeftOperand = param, RightOperand = fValue }; return(TP(node)); } else if (currentToken.Type == TokenTypes.Div) { currentToken = lexer.GetNextToken(); var fValue = F(); var node = new DivNode() { LeftOperand = param, RightOperand = fValue }; return(TP(node)); } else { return(param); } }
public override ASTN VisitMuldiv([NotNull] MuldivContext context) { ExprNode Leftexpr = (VisitExpr(context.left) as ExprNode); ExprNode Rigthexpr = (VisitExpr(context.right) as ExprNode); AritmethicNode node; if (context.op.Type == MUL) { node = new MulNode(context); } else { node = new DivNode(context); } node.Leftexpr = Leftexpr; node.Rigthexpr = Rigthexpr; return(node); }
private TypeInfo Visit(DivNode node, MethodBuilder builder, CodegenContext context) { return(BinaryOperatorVisit(node, builder, (x) => x.Div(), context)); }
public abstract T Visit(DivNode node);
public void Visit(DivNode node) { VisitChildren(node); builder.AppendLine("\t\tdiv"); }
public Type Visit(DivNode node) { VisitBinaryOperator(node, Type.INT); return(Type.INT); }
// throws RecognitionException [1] // $ANTLR end "expr_pm" // $ANTLR start "expr_dm" // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:154:1: expr_dm returns [TigerNode dm] : exp1= expr ( MULT a= expr | DIV b= expr )* ; public TigerNode expr_dm() { TigerNode dm = null; IToken MULT12 = null; IToken DIV13 = null; TigerNode exp1 = null; TigerNode a = null; TigerNode b = null; try { // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:154:32: (exp1= expr ( MULT a= expr | DIV b= expr )* ) // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:154:34: exp1= expr ( MULT a= expr | DIV b= expr )* { PushFollow(FOLLOW_expr_in_expr_dm1033); exp1 = expr(); state.followingStackPointer--; if (state.failed) return dm; if ( (state.backtracking==0) ) { dm = exp1; } // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:155:36: ( MULT a= expr | DIV b= expr )* do { int alt6 = 3; int LA6_0 = input.LA(1); if ( (LA6_0 == MULT) ) { alt6 = 1; } else if ( (LA6_0 == DIV) ) { alt6 = 2; } switch (alt6) { case 1 : // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:155:37: MULT a= expr { MULT12=(IToken)Match(input,MULT,FOLLOW_MULT_in_expr_dm1073); if (state.failed) return dm; PushFollow(FOLLOW_expr_in_expr_dm1077); a = expr(); state.followingStackPointer--; if (state.failed) return dm; if ( (state.backtracking==0) ) { dm = new MultNode(dm, a); dm.Col=MULT12.CharPositionInLine; dm.Row = MULT12.Line; } } break; case 2 : // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:160:37: DIV b= expr { DIV13=(IToken)Match(input,DIV,FOLLOW_DIV_in_expr_dm1118); if (state.failed) return dm; PushFollow(FOLLOW_expr_in_expr_dm1122); b = expr(); state.followingStackPointer--; if (state.failed) return dm; if ( (state.backtracking==0) ) { dm = new DivNode(dm, b); dm.Col=DIV13.CharPositionInLine; dm.Row = DIV13.Line; } } break; default: goto loop6; } } while (true); loop6: ; // Stops C# compiler whining that label 'loop6' has no statements } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { } return dm; }
private ValInfo Visit(DivNode node) { return(BinaryOperator(node, (x, y) => x / y)); }
private TypeDescriptor Visit(DivNode node, Context context) { return(MathOperator(node, context)); }