private Node ParseMultiplicative() { var lNode = this.ParseUnary(); while (this.AreMoreTokens) { if (this.currentToken.Equals(TokenType.Symbol, "*")) { this.ReadNextToken(); lNode = new MultiplyNode(lNode, this.ParseUnary()); } else if (this.currentToken.Equals(TokenType.Symbol, "/")) { this.ReadNextToken(); lNode = new DivideNode(lNode, this.ParseUnary()); } else if (this.currentToken.Equals(TokenType.Symbol, "%")) { this.ReadNextToken(); lNode = new ModulusNode(lNode, this.ParseUnary()); } else { break; } } return(lNode); }
public object Visit(DivideNode node) { return(this.Calculate(node.Value1, node.Value2, (v1, v2) => v1 / v2, (v1, v2) => v1 / v2, (v1, v2, ex) => throw new InvalidOperationException($"[{v1 ?? "(null)"} / {v2 ?? "(null)"}] failed!", ex))); }
public void DivideNode() { int val1 = 50, val2 = 5, result = val1 / val2; var node = new DivideNode(new ConstantNode(val1), new ConstantNode(val2)); Assert.AreEqual(node.Value, result); }
public DomainId <IAstNode> CreateDivisionOperation( string definition, DomainId <ICalculationNode> leftExpression, DomainId <ICalculationNode> rightExpression) { var divisionNode = new DivideNode( m_ids.Next, definition, leftExpression, rightExpression); return(DomainItemRegistration <IDivideNode>(divisionNode)); }
private object Visit(DivideNode node) { dynamic left = Visit(node.Left); dynamic right = Visit(node.Right); try { return(left / right); } catch (Exception error) { ReportError(error); return(null); } }
protected override AbstractMaterialNode CreateNode(ShaderGraphBuilder builder, MaterialExpressionDivide unrealNode) { var node = new DivideNode() { previewExpanded = false, }; if (unrealNode.A == null) { node.FindInputSlot <DynamicVectorMaterialSlot>(0).value = new Vector4(unrealNode.ConstA, 0); } if (unrealNode.B == null) { node.FindInputSlot <DynamicVectorMaterialSlot>(1).value = new Vector4(unrealNode.ConstB, 0); } return(node); }
private bool TryTerm(ParserContext context, out IAstNode instr) { IAstNode value2; if (context.Stream.Consume <IAstNode>(TryFactor, context, out var currInstr)) { instr = currInstr; while (!context.Stream.Eof) { if (context.Stream.Consume(TokenTypes.Times)) { if (!context.Stream.Consume <IAstNode>(TryFactor, context, out value2)) { throw new ParserException("Syntax error: expected factor", context.Stream); } currInstr = new MultiplyNode(currInstr, value2); instr = currInstr; } else if (context.Stream.Consume(TokenTypes.Divide)) { if (!context.Stream.Consume <IAstNode>(TryFactor, context, out value2)) { throw new ParserException("Syntax error: expected factor", context.Stream); } currInstr = new DivideNode(currInstr, value2); instr = currInstr; } else { return(true); } } return(true); } instr = null; return(false); }
private static void TestExpTree() { AddNode <Real> root = new AddNode <Real>(); MultiplyNode <Real> c1 = new MultiplyNode <Real>(); SubtractNode <Real> c2 = new SubtractNode <Real>(); DivideNode <Real> c3 = new DivideNode <Real>(); root.LeftChild = c1; root.RightChild = c2; c1.LeftChild = new ConstantNode <Real>(2); c1.RightChild = c3; c2.LeftChild = new ConstantNode <Real>(7); c2.RightChild = new ConstantNode <Real>(4); c3.LeftChild = new ConstantNode <Real>(8); c3.RightChild = new ConstantNode <Real>(16); Console.WriteLine(root.ToString() + " = " + root.Evaluate()); }
private AstNode Term() { // TERM = FACTOR (MULTIPLY | DIVIDE FACTOR)* var node = Factor(); var ops = new[] { Tokens.Multiply, Tokens.Divide }; while (ops.Contains(_currentToken.Type)) { var token = _currentToken; Eat(token.Type); if (token.Type == Tokens.Multiply) { node = new MultiplyNode(node, Factor()); } else if (token.Type == Tokens.Divide) { node = new DivideNode(node, Factor()); } } return(node); }
/// <summary> /// This method type checks the DivideNode node in the AST. /// </summary> /// <param name="divideNode">The node to check.</param> /// <returns>Divide operator type context</returns> public override object Visit(DivideNode divideNode) { return(new TypeContext(OP_DIVIDE)); }
/// <summary> /// This visits a Divide node /// </summary> /// <param name="divideNode">The visited node</param> /// <returns></returns> public abstract object Visit(DivideNode divideNode);
public abstract T Visit(DivideNode node);
/// <summary> /// This method visits a divide node /// </summary> /// <param name="divideNode">The name of the node</param> /// <returns>It returns a "/"</returns> public override object Visit(DivideNode divideNode) { return(" / "); }
private VarType Parsing(DivideNode node, string methodName) { return ParseElementaryOperation(node, methodName); }
/// <summary> /// This method prints the divideNode /// </summary> /// <param name="divideNode">The node to print.</param> /// <returns>Returns null</returns> public override object Visit(DivideNode divideNode) { Print("DivideNode"); return(null); }
// $ANTLR start "multiplicativeExpression" // JavaScript.g:309:1: multiplicativeExpression : unaryExpression ( ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) )* ; public JavaScriptParser.multiplicativeExpression_return multiplicativeExpression() // throws RecognitionException [1] { JavaScriptParser.multiplicativeExpression_return retval = new JavaScriptParser.multiplicativeExpression_return(); retval.Start = input.LT(1); object root_0 = null; IToken LT362 = null; IToken char_literal363 = null; IToken char_literal364 = null; IToken char_literal365 = null; IToken LT366 = null; JavaScriptParser.unaryExpression_return unaryExpression361 = default(JavaScriptParser.unaryExpression_return); JavaScriptParser.unaryExpression_return unaryExpression367 = default(JavaScriptParser.unaryExpression_return); object LT362_tree=null; object char_literal363_tree=null; object char_literal364_tree=null; object char_literal365_tree=null; object LT366_tree=null; try { // JavaScript.g:310:2: ( unaryExpression ( ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) )* ) // JavaScript.g:310:4: unaryExpression ( ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) )* { root_0 = (object)adaptor.GetNilNode(); PushFollow(FOLLOW_unaryExpression_in_multiplicativeExpression2787); unaryExpression361 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression361.Tree); // JavaScript.g:310:20: ( ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) )* do { int alt191 = 2; alt191 = dfa191.Predict(input); switch (alt191) { case 1 : // JavaScript.g:310:21: ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) { // JavaScript.g:310:23: ( LT )* do { int alt188 = 2; int LA188_0 = input.LA(1); if ( (LA188_0 == LT) ) { alt188 = 1; } switch (alt188) { case 1 : // JavaScript.g:310:23: LT { LT362=(IToken)Match(input,LT,FOLLOW_LT_in_multiplicativeExpression2790); if (state.failed) return retval; } break; default: goto loop188; } } while (true); loop188: ; // Stops C# compiler whining that label 'loop188' has no statements // JavaScript.g:310:25: ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) // JavaScript.g:310:26: ( '*' | '/' | '%' ) ( LT )* unaryExpression { // JavaScript.g:310:26: ( '*' | '/' | '%' ) int alt189 = 3; switch ( input.LA(1) ) { case 101: { alt189 = 1; } break; case 102: { alt189 = 2; } break; case 103: { alt189 = 3; } break; default: if ( state.backtracking > 0 ) {state.failed = true; return retval;} NoViableAltException nvae_d189s0 = new NoViableAltException("", 189, 0, input); throw nvae_d189s0; } switch (alt189) { case 1 : // JavaScript.g:310:27: '*' { char_literal363=(IToken)Match(input,101,FOLLOW_101_in_multiplicativeExpression2795); if (state.failed) return retval; if ( state.backtracking == 0 ) {char_literal363_tree = new MultiplyNode(char_literal363) ; root_0 = (object)adaptor.BecomeRoot(char_literal363_tree, root_0); } } break; case 2 : // JavaScript.g:310:48: '/' { char_literal364=(IToken)Match(input,102,FOLLOW_102_in_multiplicativeExpression2803); if (state.failed) return retval; if ( state.backtracking == 0 ) {char_literal364_tree = new DivideNode(char_literal364) ; root_0 = (object)adaptor.BecomeRoot(char_literal364_tree, root_0); } } break; case 3 : // JavaScript.g:310:67: '%' { char_literal365=(IToken)Match(input,103,FOLLOW_103_in_multiplicativeExpression2811); if (state.failed) return retval; if ( state.backtracking == 0 ) {char_literal365_tree = new ModuloNode(char_literal365) ; root_0 = (object)adaptor.BecomeRoot(char_literal365_tree, root_0); } } break; } // JavaScript.g:310:87: ( LT )* do { int alt190 = 2; int LA190_0 = input.LA(1); if ( (LA190_0 == LT) ) { alt190 = 1; } switch (alt190) { case 1 : // JavaScript.g:310:87: LT { LT366=(IToken)Match(input,LT,FOLLOW_LT_in_multiplicativeExpression2818); if (state.failed) return retval; } break; default: goto loop190; } } while (true); loop190: ; // Stops C# compiler whining that label 'loop190' has no statements PushFollow(FOLLOW_unaryExpression_in_multiplicativeExpression2822); unaryExpression367 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression367.Tree); } } break; default: goto loop191; } } while (true); loop191: ; // Stops C# compiler whining that label 'loop191' has no statements } retval.Stop = input.LT(-1); if ( (state.backtracking==0) ) { retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);} } catch (RecognitionException re) { ReportError(re); Recover(input,re); // Conversion of the second argument necessary, but harmless retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re); } finally { } return retval; }
public double CalcDivideNode(DivideNode node) { return((double)(node.NodeA.value / node.NodeB.value)); }