public void Visit(IncrementNode node) { foreach (var subnode in node) { Visit((dynamic)subnode); } }
private static bool NextNode(CharEnumerator enumerator, out INode node) { do { switch (enumerator.Current) { case '>': node = new MoveRightNode(); return(true); case '<': node = new MoveLeftNode(); return(true); case '+': node = new IncrementNode(); return(true); case '-': node = new DecrementNode(); return(true); case ',': node = new InputNode(); return(true); case '.': node = new OutputNode(); return(true); case '[': var nodes = new List <INode>(); while (enumerator.MoveNext()) { switch (enumerator.Current) { case ']': node = new LoopNode(nodes); return(true); default: if (NextNode(enumerator, out var nextNode)) { nodes.Add(nextNode); } break; } } throw new InvalidBFProgramException("Expected more symbols after encountering a loop begin symbol", true); case ']': throw new InvalidBFProgramException("Encountered a loop end symbol without matching loop begin", false); default: break; } }while (enumerator.MoveNext()); node = null; return(false); }
public virtual Value evaluate(Context cx, IncrementNode node) { output("<IncrementNode position=\"" + node.pos() + "\">"); indent_Renamed_Field++; if (node.expr != null) { node.expr.evaluate(cx, this); } indent_Renamed_Field--; output("</IncrementNode>"); return null; }
public virtual Value evaluate(Context cx, IncrementNode node) { output("<IncrementNode position=\"" + node.pos() + "\">"); indent_Renamed_Field++; if (node.expr != null) { node.expr.evaluate(cx, this); } indent_Renamed_Field--; output("</IncrementNode>"); return(null); }
private object IncrementNode(IncrementNode i) { var name = i.l.Name; object output; if (variables.TryGetValue(name, out output)) { if (output is decimal) { variables[name] = ((decimal)output) + 1; return(((decimal)output) + 1); } else { throw(new Exception($"Can't decrement {output.GetType()}")); } } else { throw(new Exception("Undefined Variable")); } }
public Node Stmt() { switch (CurrentToken) { case TokenCategory.IDENTIFIER: var idToken = Expect(TokenCategory.IDENTIFIER); switch (CurrentToken) { case TokenCategory.ASSIGN: Expect(TokenCategory.ASSIGN); var ass = new AssignmentNode() { AnchorToken = idToken }; ass.Add(Expr()); Expect(TokenCategory.SEMICOLON); return(ass); case TokenCategory.INCREMENT: Expect(TokenCategory.INCREMENT); var inc = new IncrementNode() { AnchorToken = idToken }; Expect(TokenCategory.SEMICOLON); return(inc); case TokenCategory.DECREMENT: Expect(TokenCategory.DECREMENT); var dec = new DecrementNode() { AnchorToken = idToken }; Expect(TokenCategory.SEMICOLON); return(dec); case TokenCategory.PARENTHESIS_OPEN: Expect(TokenCategory.PARENTHESIS_OPEN); var fun = new FunCallNode() { AnchorToken = idToken }; fun.Add(ExprList()); Expect(TokenCategory.PARENTHESIS_CLOSE); Expect(TokenCategory.SEMICOLON); return(fun); } break; case TokenCategory.IF: return(If()); case TokenCategory.WHILE: return(While()); case TokenCategory.BREAK: var bre = new StmtNode() { AnchorToken = Expect(TokenCategory.BREAK) }; Expect(TokenCategory.SEMICOLON); return(bre); case TokenCategory.RETURN: return(Return()); case TokenCategory.SEMICOLON: return(new StmtNode() { AnchorToken = Expect(TokenCategory.SEMICOLON) }); default: throw new SyntaxError(firstOfStmt, tokenStream.Current); } throw new SyntaxError(firstOfStmt, tokenStream.Current); }