protected static IEnumerable <Node> generateLeafNodes(NodeClass c, NodeTypeFrequencyProfile profile) { Node n = null; switch (c) { case NodeClass.directive: n = new directiveTerminal(); yield return(n); break; case NodeClass.numeric: for (int i = 0; i < 2; i++) { n = new NumericConstant(i); yield return(n); } break; case NodeClass.boolean: yield return(new BoolConstant(false)); yield return(new BoolConstant(true)); break; default: break; } }
/// <summary> /// Creates a fully initialized node of given type. If the node requires successors, these successors will also be created and assigned to the node. Successors will be default-value-nodes of required types. /// </summary> /// <param name="type"></param> /// <returns></returns> public static Node createRandomNode(NodeType type, NodeCreationConstrains constrains = null) { Node n; if (type == NodeType.BoolConstant) { n = new BoolConstant(r.NextDouble() < 0.5); return(n); } if (type == NodeType.NumConst) { n = new NumericConstant(r.Next(10)); return(n); } if (type == NodeType.NumInput) { n = new InputNode(r.Next(10)); return(n); } n = createPrototypeNode(type); for (int i = 0; i < n.successors.count; i++) { n.setSuccessor(createDefaultNode(n.successors.GetSlot(i).argumentClass, constrains), i); } return(n); }
public virtual SyntaxBlock BuildEquation() { SyntaxBlock Sum = new NumericConstant(0); foreach (var incoming in In) { Sum = new Sum(Sum, incoming.BuildEquation()); } return Sum; }
//Sin(Expr) //Random(10,20) //Avg([1,3,4]) //Sum([10,20,30,40,50]) private Expression Factor() { Token token; Expression expression; if (_currentToken == Token.Double) { expression = new NumericConstant(_lexicalAnalyzer.GetDigits()); _currentToken = _lexicalAnalyzer.GetToken(); } else if (_currentToken == Token.Param) { expression = new Var(); _currentToken = _lexicalAnalyzer.GetToken(); } else if (_currentToken == Token.Sin || _currentToken == Token.Cos) { Token old = _currentToken; _currentToken = _lexicalAnalyzer.GetToken(); if (_currentToken != Token.OParen) { throw new Exception("Illegal Token"); } _currentToken = _lexicalAnalyzer.GetToken(); expression = Expr(); if (_currentToken != Token.CParen) { throw new Exception("Missing Closeing Parenthesis\n"); } if (old == Token.Cos) { expression = new CosExpression(expression); } else { expression = new SinExpression(expression); } _currentToken = _lexicalAnalyzer.GetToken(); } else if (_currentToken == Token.OParen) { _currentToken = _lexicalAnalyzer.GetToken(); expression = Expr(); if (_currentToken != Token.CParen) { throw new Exception("Missing Closing Parenthesis\n"); } _currentToken = _lexicalAnalyzer.GetToken(); } else if (_currentToken == Token.Plus || _currentToken == Token.Sub) { var old = _currentToken; _currentToken = _lexicalAnalyzer.GetToken(); expression = Factor(); expression = new UnaryExpression(expression, old == Token.Plus?Operator.Plus:Operator.Minus); } else { throw new Exception("error"); } return(expression); }
public void ExitNumericconstant(BASICParser.NumericconstantContext context) { currentNumericConstant = haveSign ? new NumericConstant(currentSign, currentNumericRep) : new NumericConstant(currentNumericRep); primaryOp = PrimaryOptions.CONST; }