void forloop(out Node forloop) { Node node; ForLoopNode loopNode = new ForLoopNode(); NodeList body = null; Expect(23); Expect(8); arrayident(out node); loopNode.id = node; Expect(34); expr(out node); loopNode.expression = node; Expect(9); if (StartOf(2)) { Node singleStmt = null; stmt(out singleStmt); loopNode.body.Add(singleStmt); } else if (la.kind == 32) { Get(); stmtlist(out body); loopNode.body = body; Expect(33); } else { SynErr(57); } forloop = loopNode; }
public override DynValue Visit(ForLoopNode forLoopNode) { Environment.EnterScope(); { foreach (var assignment in forLoopNode.Assignments) { Visit(assignment); } try { Environment.LoopStack.Push(new LoopFrame()); while (true) { var conditionEvaluation = Visit(forLoopNode.Condition); if (!conditionEvaluation.IsTruth) { break; } var loopStackTop = Environment.LoopStack.Peek(); if (loopStackTop.BreakLoop) { break; } if (!loopStackTop.SkipThisIteration) { Environment.EnterScope(); { ExecuteStatementList(forLoopNode.StatementList); } Environment.ExitScope(); } foreach (var iterationStatement in forLoopNode.IterationStatements) { Visit(iterationStatement); } if (loopStackTop.SkipThisIteration) { loopStackTop.SkipThisIteration = false; } } } finally { Environment.LoopStack.Pop(); } } Environment.ExitScope(); return(DynValue.Zero); }
public void visitForLoop(ForLoopNode node) { IdentifierNode identifier = (IdentifierNode)node.getChildren()[0]; string variableName = identifier.getVariableName(); if (!variableAlreadyDeclared(variableName)) { throw new SemanticException("The control variable '" + variableName + "' in for loop has not been declared."); } this.forLoopControlVariables.Push(variableName); node.getChildren()[2].accept(this); this.forLoopControlVariables.Pop(); }
public void TranslateStartForLoopNode(ForLoopNode node) { // Translate all the pure nodes this node depends on in // the correct order TranslateDependentPureNodes(node); builder.AppendLine($"{GetOrCreatePinName(node.IndexPin)} = {GetPinIncomingValue(node.InitialIndexPin)};"); builder.AppendLine($"if({GetOrCreatePinName(node.IndexPin)} < {GetPinIncomingValue(node.MaxIndexPin)})"); builder.AppendLine("{"); WritePushJumpStack(node.ContinuePin); WriteGotoOutputPin(node.LoopPin); builder.AppendLine("}"); }
//NB: This one might break, there was talk about refactoring all for loops to while loops behind the scenes protected override CrawlSyntaxNode VisitForLoop(ForLoopNode forLoop) { GenericScope scope = new GenericScope(new[] { new KeyValuePair <string, TypeInformation>( forLoop.LoopVariable.Value, new TypeInformation( forLoop.Loopvariable.ActualType, ProtectionLevel.NotApplicable, forLoop.LoopVariable.Interval.a, DeclaringScope.MethodLike) ), }); ForLoopNode afterVisit = (ForLoopNode)base.VisitForLoop(forLoop); return(afterVisit.WithScope(scope)); }
public override void Visit(ForLoopNode node) { SymbolTable.SetCurrentNode(node); SymbolTable.OpenScope(BlockType.ForLoop); if (node.VariableDeclaration != null) { node.VariableDeclaration.Accept(this); } node.ToValueOperation.Accept(this); if (node.Increment != null) { node.Increment.Accept(this); } VisitChildren(node); SymbolTable.CloseScope(); }
public void CreateForLoopMethod() { // Create method forLoopMethod = new Method("ForLoop") { Modifiers = MethodModifiers.Public }; // Create nodes LiteralNode maxIndexLiteralNode = new LiteralNode(forLoopMethod, typeof(int), 10); ForLoopNode forLoopNode = new ForLoopNode(forLoopMethod); // Connect exec nodes GraphUtil.ConnectExecPins(forLoopMethod.EntryNode.InitialExecutionPin, forLoopNode.ExecutionPin); GraphUtil.ConnectExecPins(forLoopNode.CompletedPin, forLoopMethod.ReturnNode.ReturnPin); // Connect node data GraphUtil.ConnectDataPins(maxIndexLiteralNode.ValuePin, forLoopNode.MaxIndexPin); }
public override ImperativeNode VisitForLoopNode(ForLoopNode node) { var newLoopVar = node.LoopVariable.Accept(this); if (node.LoopVariable != newLoopVar) { node.LoopVariable = newLoopVar; } var newExpr = node.Expression.Accept(this); if (node.Expression != newExpr) { node.Expression = newExpr; } node.Body = VisitNodeList(node.Body); return(node); }
public void CreateForLoopMethod() { // Create method forLoopMethod = new Method("ForLoop") { Visibility = MemberVisibility.Public }; // Create nodes LiteralNode maxIndexLiteralNode = LiteralNode.WithValue(forLoopMethod, 10); ForLoopNode forLoopNode = new ForLoopNode(forLoopMethod); // Connect exec nodes GraphUtil.ConnectExecPins(forLoopMethod.EntryNode.InitialExecutionPin, forLoopNode.ExecutionPin); GraphUtil.ConnectExecPins(forLoopNode.CompletedPin, forLoopMethod.ReturnNodes.First().ReturnPin); // Connect node data GraphUtil.ConnectDataPins(maxIndexLiteralNode.ValuePin, forLoopNode.MaxIndexPin); }
public void visitForLoop(ForLoopNode forLoopNode) { IdentifierNode identifier = (IdentifierNode)forLoopNode.getChildren()[0]; string controlVariable = identifier.getVariableName(); RangeOperatorNode rangeNode = (RangeOperatorNode)forLoopNode.getChildren()[1]; StatementListNode forStatements = (StatementListNode)forLoopNode.getChildren()[2]; rangeNode.getChildren()[0].accept(this); int begin = popInt(); rangeNode.getChildren()[1].accept(this); int end = popInt(); for (int i = begin; i <= end; i++) { this.symbolTable.updateVariable(controlVariable, i); foreach (INode child in forStatements.getChildren()) { child.accept(this); } } }
public void visitForLoop(ForLoopNode node) { RangeOperatorNode rangeOperatorNode = (RangeOperatorNode)node.getChildren()[1]; this.typeStack = new Stack <MiniPLTokenType>(); INode leftExpression = rangeOperatorNode.getChildren()[0]; this.typeStack.Push(MiniPLTokenType.TYPE_IDENTIFIER_INTEGER); accessChildren(leftExpression); if (this.typeStack.Pop() != MiniPLTokenType.TYPE_IDENTIFIER_INTEGER) { throw new SemanticException("Expected an integer. Wrong type in the left hand side of range operator."); } INode rightExpression = rangeOperatorNode.getChildren()[1]; this.typeStack.Clear(); this.typeStack.Push(MiniPLTokenType.TYPE_IDENTIFIER_INTEGER); accessChildren(rightExpression); if (this.typeStack.Pop() != MiniPLTokenType.TYPE_IDENTIFIER_INTEGER) { throw new SemanticException("Expected an integer. Wrong type in the right hand side of range operator."); } }
public abstract DynValue Visit(ForLoopNode forLoopNode);
public ForLoopNode(ForLoopNode rhs) : base(rhs) { Body = new List<ImperativeNode>(); foreach (ImperativeNode iNode in rhs.Body) { ImperativeNode newNode = NodeUtils.Clone(iNode); Body.Add(newNode); } LoopVariable = NodeUtils.Clone(rhs.LoopVariable); Expression = NodeUtils.Clone(rhs.Expression); KwForLine = rhs.KwForLine; KwForCol = rhs.KwForCol; KwInLine = rhs.KwInLine; KwInCol = rhs.KwInCol; }
public AddressNode VisitForLoop(ForLoopNode forLoop) { throw new System.NotImplementedException(); }
public virtual void VisitForLoopNode(ForLoopNode node) { DefaultVisit(node); }
public ForLoopNode(ForLoopNode rhs) : base(rhs) { body = new List<ImperativeNode>(); foreach (ImperativeNode iNode in rhs.body) { ImperativeNode newNode = ProtoCore.Utils.NodeUtils.Clone(iNode); body.Add(newNode); } loopVar = ProtoCore.Utils.NodeUtils.Clone(rhs.loopVar); expression = ProtoCore.Utils.NodeUtils.Clone(rhs.expression); KwForLine = rhs.KwForLine; KwForCol = rhs.KwForCol; KwInLine = rhs.KwInLine; KwInCol = rhs.KwInCol; }
public virtual bool VisitForLoopNode(ForLoopNode node) { return(DefaultVisit(node)); }
public override DynValue Visit(ForLoopNode forLoopNode) { _ = Visit(forLoopNode.Assignment).Number; DynValue step = new DynValue(1); var targetValue = Visit(forLoopNode.TargetValue); if (forLoopNode.Step != null) { step = Visit(forLoopNode.Step); } var isLocalScope = false; var assignmentNode = (forLoopNode.Assignment as AssignmentNode); var iteratorName = assignmentNode.Variable.Name; if (assignmentNode.LocalScope) { isLocalScope = true; } try { LoopStack.Push(new LoopStackItem()); while (true) { ExecuteStatementList(forLoopNode.StatementList).GetAwaiter().GetResult(); double iterator; if (isLocalScope) { var callStackTop = CallStack.Peek(); iterator = callStackTop.LocalVariableScope[iteratorName].Number; } else { iterator = Environment.Globals[iteratorName].Number; } if (step.Number < 0) { if (iterator < targetValue.Number) { break; } else { iterator -= step.Number; } } else { if (iterator >= targetValue.Number) { break; } else { iterator += step.Number; } } if (isLocalScope) { // no throw on localvar token, so // guaranteed we're inside a function var callStackTop = CallStack.Peek(); callStackTop.LocalVariableScope[iteratorName] = new DynValue(iterator); } else { Environment.Globals[iteratorName] = new DynValue(iterator); } var loopStackTop = LoopStack.Peek(); if (loopStackTop.BreakLoop) { break; } if (loopStackTop.SkipThisIteration) { loopStackTop.SkipThisIteration = false; continue; } } } catch { throw; } finally { LoopStack.Pop(); } return(DynValue.Zero); }
public string VisitForLoop(ForLoopNode forLoop) { throw new NotImplementedException(); }
public virtual T VisitForLoop(ForLoopNode forLoop) { throw new NotImplementedException(); }
public virtual XzaarExpression Visit(ForLoopNode loop) { return(null); }
public virtual ForLoopNode Visit(ForLoopNode loop) { return(loop); }