Exemplo n.º 1
0
        public static TYPE parseTypeSpecifier(iSCOPE context, out bool ref_val, out bool conc, out Span final)
        {
            TYPE type = null;

            bool opt = false;

            ref_val = false; conc = false;
            Token token = get();
            Token begin = token;

            if (token.code == TokenCode.Question)
            {
                forget(); token = get();
                opt             = true;
            }
            switch (token.code)
            {
            case TokenCode.As:
                forget();
                EXPRESSION example = PRIMARY.parse(null, context);
                type = example.type;
                if (type != null)
                {
                    type.setSpan(begin.span, example.span);
                    if (type is UNIT_REF)
                    {
                        (type as UNIT_REF).setSpecs(opt, true);
                    }
                }
                final = example.span;
                break;

            case TokenCode.Ref:        ref_val = true; forget(); goto ParseType;

            case TokenCode.Concurrent: conc = true; forget(); goto ParseType;

            case TokenCode.Val:                        forget(); goto ParseType;

            case TokenCode.LParen:
                // Seems to a tuple type
                type = TUPLE_TYPE.parse(context);
                context.add(type);
                final = type.span;
                break;

            default:
                // forget();
ParseType:
                UNIT_REF unitRef = UNIT_REF.parse(null, opt, context);
                if (unitRef == null)     /* An error was detected earlier */
                {
                    final = null; return(null);
                }
                final = unitRef.span;
                token = get();
                return(unitRef);
            }
            return(type);
        }
Exemplo n.º 2
0
        public static new EXPRESSION parse(Token first, iSCOPE context)
        {
            EXPRESSION result = PRIMARY.parse(first, context);

            if (result == null)
            {
                return(null);
            }

            Span begin = result.span;

            while (true)
            {
                Token token = get();
                switch (token.code)
                {
                case TokenCode.Dot:
                    forget();
                    IDENTIFIER identifier;
                    token = get();
                    if (token.code == TokenCode.Init)
                    {
                        forget();
                        // Initializer call in full form
                        identifier = new IDENTIFIER(INITIALIZER.initName);
                    }
                    else if (token.code == TokenCode.Identifier)
                    {
                        forget();
                        identifier = new IDENTIFIER(token);
                    }
                    else     // syntax error
                    {
                        identifier = new IDENTIFIER("ERROR");
                    }
                    result = new MEMBER(result, identifier);
                    result.setSpan(begin, token.span);
                    break;

                case TokenCode.LParen:
                    forget();
                    result = new CALL(result);
                    while (true)
                    {
                        token = get();
                        if (token.code == TokenCode.RParen)
                        {
                            forget(); break;
                        }
                        EXPRESSION actual = EXPRESSION.parse(null, context);
                        (result as CALL).add(actual);
                        token = get();
                        if (token.code == TokenCode.Comma)
                        {
                            forget(); continue;
                        }
                        token = expect(TokenCode.RParen);
                        break;
                    }
                    result.setSpan(begin, token.span);
                    break;

                default:
                    goto Out;
                }
            }
Out:
            return(result);
        }