Ejemplo n.º 1
0
 public IfItem(IParseExp exp, BlockItem block, ElseInfo[] elses, BlockItem elseBlock = null)
 {
     Expression = exp;
     Block      = block;
     Elses      = elses;
     ElseBlock  = elseBlock;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds an else expression to this instance.
        /// </summary>
        /// <param name="exp">The else expression.</param>
        /// <param name="block">The else block.</param>
        /// <exception cref="System.ArgumentNullException">If exp or block is null.</exception>
        /// <exception cref="System.ArgumentException">If exp is not an expression.</exception>
        public void AddElse(IParseExp exp, BlockItem block)
        {
            if (exp == null)
            {
                throw new ArgumentNullException(nameof(exp));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            elses.Add(new ElseInfo(exp, block));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when the item is a block item.
        /// </summary>
        /// <param name="target">The object that was passed to IParseItem.Accept.</param>
        /// <returns>The passed target or a modification of it.</returns>
        /// <exception cref="System.ArgumentNullException">If target is null.</exception>
        public IParseItem Visit(BlockItem target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            using (tree.Block(true))
            {
                foreach (var item in target.Children)
                    item.Accept(this);

                if (target.Return != null)
                    target.Return.Accept(this);
            }
            return target;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new ForNumItem with the given name.
        /// </summary>
        /// <param name="name">The name of the variable defined.</param>
        /// <param name="limit">The item that defines the limit of the loop.</param>
        /// <param name="start">The item that defines the start of the loop.</param>
        /// <param name="step">The item that defines the step of the loop.</param>
        /// <exception cref="System.ArgumentNullException">If name, start, or limit is null.</exception>
        public ForNumItem(NameItem name, IParseExp start, IParseExp limit, IParseExp step,
                          BlockItem block)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (start == null)
            {
                throw new ArgumentNullException(nameof(start));
            }

            if (limit == null)
            {
                throw new ArgumentNullException(nameof(limit));
            }

            Start = start;
            Limit = limit;
            Step  = step;
            Name  = name;
            Block = block;
        }
Ejemplo n.º 5
0
 public IfItem(IParseExp exp, BlockItem block) : this(exp, block, new ElseInfo[0], null)
 {
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a new instance of ElseInfo.
 /// </summary>
 /// <param name="exp">The expression for the else if statement.</param>
 /// <param name="block">The block of the else if statement.</param>
 public ElseInfo(IParseExp exp, BlockItem block)
 {
     Expression = exp;
     Block      = block;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates a new instance of WhileItem.
 /// </summary>
 public WhileItem(IParseExp exp, BlockItem block)
 {
     Expression = exp;
     Block      = block;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds an else expression to this instance.
        /// </summary>
        /// <param name="exp">The else expression.</param>
        /// <param name="block">The else block.</param>
        /// <exception cref="System.ArgumentNullException">If exp or block is null.</exception>
        /// <exception cref="System.ArgumentException">If exp is not an expression.</exception>
        public void AddElse(IParseExp exp, BlockItem block)
        {
            if (exp == null)
                throw new ArgumentNullException("exp");
            if (block == null)
                throw new ArgumentNullException("block");

            elses.Add(new ElseInfo(exp, block));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a new instance of ElseInfo.
 /// </summary>
 /// <param name="exp">The expression for the else if statement.</param>
 /// <param name="block">The block of the else if statement.</param>
 public ElseInfo(IParseExp exp, BlockItem block)
 {
     Expression = exp;
     Block = block;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Called when the item is a block item.
        /// </summary>
        /// <param name="target">The object that was passed to IParseItem.Accept.</param>
        /// <returns>The passed target or a modification of it.</returns>
        /// <exception cref="System.ArgumentNullException">If target is null.</exception>
        public IParseItem Visit(BlockItem target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            using (compiler.LocalBlock())
            {
                foreach (IParseItem child in target.Children)
                    child.Accept(this);

                if (target.Return != null)
                {
                    // return {Return};
                    target.Return.Accept(this);
                    compiler.CurrentGenerator.Emit(OpCodes.Ret);
                }
            }

            return target;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates a new instance of ForGenItem with the given names definition.
 /// </summary>
 /// <param name="names">The names that are defined by this statement.</param>
 public ForGenItem(NameItem[] names, IParseExp[] exps, BlockItem block)
 {
     Names       = names;
     Expressions = exps;
     Block       = block;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates a new instance of RepeatItem.
 /// </summary>
 public RepeatItem(IParseExp exp, BlockItem block)
 {
     Block      = block;
     Expression = exp;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a new FuncDefItem with the given name.
 /// </summary>
 /// <param name="name">The name of the method, must be a NameItem or IndexerItem.</param>
 public FuncDefItem(NameItem[] args, BlockItem block)
 {
     Arguments = args;
     Block     = block;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Reads a block of code from the input.  Any end tokens
        /// should not be read and are handled by the parrent call
        /// (e.g. 'end' or 'until').
        /// </summary>
        /// <param name="input">Where to read input from.</param>
        /// <param name="prev">The token to append the total token onto.</param>
        /// <returns>The item that was read.</returns>
        protected virtual BlockItem ReadBlock(ITokenizer input, ref Token prev)
        {
            BlockItem ret = new BlockItem();
            Token total = input.Peek();
            total.Value = "";
            Token name;

            while ((name = input.Peek()).Value != null)
            {
                if (Functions.ContainsKey(name.Value))
                {
                    var temp = Functions[name.Value](input, ref total);
                    ret.AddItem(temp);
                }
                else if (name.Value == "return")
                {
                    ret.Return = ReadReturn(input, ref total);
                    return ret;
                }
                else if (name.Value == ";")
                {
                    Read(input, ref total); // read ';'
                }
                else if (name.Value == "end" || name.Value == "else" || name.Value == "elseif" ||
                    name.Value == "until")
                {
                    // don'type read as it will be handled by the parrent
                    prev.Append(total); // don't add 'end' to the prev 
                    ret.Debug = total;  //   or the current block, this 
                    return ret;         //   end belongs to the parrent.
                }
                else
                {
                    Token debug = name;
                    debug.Value = "";
                    var exp = ReadExp(input, ref debug);
                    if (exp is FuncCallItem)
                    {
                        (exp as FuncCallItem).Statement = true;
                        ret.AddItem((FuncCallItem)exp);
                    }
                    else if (exp is LiteralItem)
                    {
                        throw new SyntaxException(
                            "A literal is not a variable.",
                            input.Name, debug);
                    }
                    else if (exp is NameItem || exp is IndexerItem)
                    {
                        var i = ReadAssignment(input, ref debug, false, (IParseVariable)exp);
                        ret.AddItem(i);
                    }
                    else
                        throw new SyntaxException(
                            string.Format(Resources.TokenStatement, name.Value),
                            input.Name, debug);

                    total.Append(debug);
                }
            } // end While

            // only gets here if this is the global function
            ret.Debug = total;
            ret.Return = ret.Return ?? new ReturnItem();
            return ret;
        }