Пример #1
0
        IBoundExpr IUnboundExprVisitor<IBoundExpr>.Visit(BlockExpr block)
        {
            // create an inner scope
            if (block.HasScope) Scope.Push();

            var exprs = new List<IBoundExpr>();
            var index = 0;
            foreach (IUnboundExpr expr in block.Exprs)
            {
                var bound = expr.Accept(this);

                // all but last expression must be void
                if (index < block.Exprs.Count - 1)
                {
                    if (bound.Type != Decl.Unit) throw new CompileException(expr.Position, "All expressions in a block except the last must be of type Unit. " + block.ToString());
                }

                index++;

                exprs.Add(bound);
            }

            if (block.HasScope) Scope.Pop();

            return new BoundBlockExpr(exprs);
        }
Пример #2
0
        private IUnboundExpr SyntaxExpr()
        {
            Position position;

            if (ConsumeIf(TokenType.LeftCurly, out position))
            {
                // ignore a leading line
                ConsumeIf(TokenType.Line);

                var expressions = new List <IUnboundExpr>();

                while (true)
                {
                    expressions.Add(Expression());

                    if (ConsumeIf(TokenType.RightCurly))
                    {
                        break;
                    }
                    Consume(TokenType.Line);
                    if (ConsumeIf(TokenType.RightCurly))
                    {
                        break;
                    }
                }

                IUnboundExpr expr;
                if (expressions.Count > 1)
                {
                    expr = new BlockExpr(expressions);
                }
                else
                {
                    expr = expressions[0];
                }

                return(new SyntaxExpr(position, expr));
            }
            else
            {
                return(DefineExpr());
            }
        }
 public virtual IUnboundExpr Transform(BlockExpr expr)
 {
     return(expr);
 }
Пример #4
0
 IUnboundExpr IUnboundExprVisitor <IUnboundExpr> .Visit(BlockExpr expr)
 {
     return(Call("BlockExpr", Array(expr.Exprs.Accept(this))));
 }