Exemplo n.º 1
0
        public static void parse(iSCOPE context)
        {
            bool useConst = false;

            Token token = get();
            Token begin = token;

            if (token.code == TokenCode.Const)
            {
                forget();
                useConst = true;
            }
            while (true)
            {
                UNIT_REF ur     = UNIT_REF.parse(null, false, context);
                USE      result = new USE(ur, useConst);
                result.parent = context.self;
                result.setSpan(begin.span, ur.span);

                if (context is UNIT)
                {
                    (context as UNIT).add(result);
                }
                else if (context is COMPILATION)
                {
                    (context as COMPILATION).add(result);
                }
                // else
                //     -- Some other use of 'use'

                token = get();
                if (token.code != TokenCode.Comma)
                {
                    break;
                }
                forget();
            }
        }
Exemplo n.º 2
0
 public void add(USE u)
 {
     uses.Add(u); u.parent = this;
 }
Exemplo n.º 3
0
 public void add(USE u)
 {
     uses.Add(u);
 }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static COMPILATION parse()
        {
            Debug.Indent();
            Debug.WriteLine("Entering COMPILATION.parse");

            COMPILATION compilation = new COMPILATION();

            Context.enter(compilation);

            Token start     = get();
            Token startAnon = null;
            Token endAnon   = null;

            int pure_safe = 0;

            while (true)
            {
                Token token = get();
                Token begin = token;
                switch (token.code)
                {
                case TokenCode.Final:
                    forget();
                    token = get();
                    switch (token.code)
                    {
                    case TokenCode.Unit:
                    case TokenCode.Package:
                    case TokenCode.Ref:
                    case TokenCode.Val:
                    case TokenCode.Concurrent:
                        // Don't forget()
                        UNIT.parse(false, true, false, compilation);
                        break;

                    case TokenCode.Abstract:
                        forget();
                        UNIT.parse(false, true, true, compilation);
                        break;

                    case TokenCode.Safe:
                    case TokenCode.Pure:
                    case TokenCode.Routine:
                        forget();
                        switch (token.code)
                        {
                        case TokenCode.Pure: pure_safe = 1; break;

                        case TokenCode.Safe: pure_safe = 2; break;
                        }
                        ROUTINE.parse(null, false, true, false, pure_safe, compilation);
                        pure_safe = 0;
                        break;
                    }
                    break;

                case TokenCode.Ref:
                case TokenCode.Val:
                case TokenCode.Concurrent:
                case TokenCode.Unit:
                case TokenCode.Package:
                    UNIT.parse(false, false, false, compilation);
                    break;

                case TokenCode.Abstract:
                    forget();
                    UNIT.parse(false, false, true, compilation);
                    break;

                case TokenCode.Use:
                    USE.parse(compilation);
                    break;

                case TokenCode.Routine:
                case TokenCode.Safe:
                case TokenCode.Pure:
                    forget();
                    switch (token.code)
                    {
                    case TokenCode.Pure: pure_safe = 1; break;

                    case TokenCode.Safe: pure_safe = 2; break;
                    }
                    ROUTINE.parse(null, false, false, false, pure_safe, compilation);
                    pure_safe = 0;
                    break;

                case TokenCode.EOS:
                    goto Finish;

                case TokenCode.EOL:
                    forget();
                    break;

                default:
                    // A call/assignment statement, or an error
                    if (startAnon == null)
                    {
                        startAnon = get();
                    }
                    bool result = STATEMENT.parse(compilation.anonymous.routineBody,
                                                  TokenCode.EOS, TokenCode.ERROR, TokenCode.ERROR);
                    if (!result)
                    {
                        // There was not a statement:
                        // apparently, this is a syntax error
                        goto Finish;
                    }
                    endAnon = get();
                    break;
                }
            }
Finish:
            compilation.setSpan(start, get());
            if (startAnon != null && endAnon != null)
            {
                compilation.anonymous.setSpan(startAnon, endAnon);
            }

            Debug.WriteLine("Exiting COMPILATION.parse");
            Debug.Unindent();

            Context.exit();
            return(compilation);
        }