private void Resolve(BreakExpr @break) { if (!_currentLoop) { throw new Exception("Cannot break when not in a loop!"); } // TODO: resolve label }
public Expr OnParseBreak() { var tokenIt = this._parser.TokenIt; var initiatorToken = tokenIt.NextToken; var expr = new BreakExpr(); // <codeBreak> tokenIt.Advance(); // </codeBreak> this._parser.SetupContext(expr, initiatorToken); return(expr); }
/// <summary> /// Execute the break. /// </summary> public object VisitBreak(BreakExpr expr) { var loop = expr.FindParent <ILoop>(); if (loop == null) { throw new LangException("syntax error", "unable to break, loop not found", string.Empty, 0); } loop.DoBreakLoop = true; return(LObjects.Null); }
private object Evaluate(Expr expression) { return(expression switch { BinaryExpr binaryExpr => Evaluate(binaryExpr), BlockExpr blockExpr => Evaluate(blockExpr), BreakExpr breakExpr => Evaluate(breakExpr), CallExpr callExpr => Evaluate(callExpr), ContinueExpr continueExpr => Evaluate(continueExpr), Identifier identifier => Evaluate(identifier), IfExpr ifExpr => Evaluate(ifExpr), LambdaExpr lambdaExpr => Evaluate(lambdaExpr), Literal literal => Evaluate(literal), ReturnExpr returnExpr => Evaluate(returnExpr), UnaryExpr unaryExpr => Evaluate(unaryExpr), _ => throw new ArgumentOutOfRangeException(nameof(expression)) });
/// <summary> /// Visits the var statement tree. /// </summary> /// <param name="expr"></param> public object VisitBreak(BreakExpr expr) { _callBackOnNodeStart(expr); return(null); }
/// <summary> /// break; /// </summary> /// <returns></returns> public override Expr Parse() { var expr = new BreakExpr(); _tokenIt.Expect(Tokens.Break); return expr; }
/// <summary> /// Visits the var statement tree. /// </summary> /// <param name="assignExpr"></param> public object VisitBreak(BreakExpr expr) { _callBackOnNodeStart(expr); return null; }