Ejemplo n.º 1
0
        // for (a = 0; a < 10; ++a)
        //      block
        private bool ForLoop(RhoAstNode @for)
        {
            if (!Expression())
            {
                return(FailLocation("Initialisation expression expected."));
            }

            @for.Add(Pop());
            if (!TryConsume(ERhoToken.Semi))
            {
                return(FailLocation("Semi expected."));
            }

            if (!Expression())
            {
                return(FailLocation("When does the for statement stop?"));
            }
            @for.Add(Pop());

            Expect(ERhoToken.Semi);

            if (!Expression())
            {
                return(FailLocation("What happens at end of for loop?"));
            }

            @for.Add(Pop());

            //Expect(ERhoToken.CloseParan);

            //return Block() || FailLocation("For each in what?");
            return(true);
        }
Ejemplo n.º 2
0
        private bool AddNamedBlock(RhoAstNode cont)
        {
            var ident = Expect(ERhoToken.Ident);

            Expect(ERhoToken.OpenParan);
            var args = NewNode(ERhoAst.ArgList);

            if (Try(ERhoToken.Ident))
            {
                args.Add(Consume());

                while (TryConsume(ERhoToken.Comma))
                {
                    args.Add(Expect(ERhoToken.Ident));
                }
            }

            Expect(ERhoToken.CloseParan);
            Expect(ERhoToken.NewLine);

            if (!Block())
            {
                return(FailLocation("Function block expected."));
            }

            // make the continuation
            var block = Pop();

            cont.Add(ident);
            cont.Add(args);
            cont.Add(block);

            // assign it within current scope
            var assign = NewNode(ERhoAst.Assignment);

            assign.Add(cont);
            assign.Add(ident);

            return(Append(assign));
        }