Esempio n. 1
0
        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);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
 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))
     });
Esempio n. 5
0
 /// <summary>
 /// Visits the var statement tree.
 /// </summary>
 /// <param name="expr"></param>
 public object VisitBreak(BreakExpr expr)
 {
     _callBackOnNodeStart(expr);
     return(null);
 }
Esempio n. 6
0
 /// <summary>
 /// break;
 /// </summary>
 /// <returns></returns>
 public override Expr Parse()
 {
     var expr = new BreakExpr();
     _tokenIt.Expect(Tokens.Break);
     return expr;
 }
Esempio n. 7
0
 /// <summary>
 /// Visits the var statement tree.
 /// </summary>
 /// <param name="assignExpr"></param>
 public object VisitBreak(BreakExpr expr)
 {
     _callBackOnNodeStart(expr);
     return null;
 }