internal static CTFTypeSpecifier ParseTypeSpecifier(CTFScope scope, TokParser tp)
        {
            Token.EnumId id = tp.Token.Id;
            switch (id)
            {
            case Token.EnumId.VOID:
            case Token.EnumId.CHAR:
            case Token.EnumId.SHORT:
            case Token.EnumId.INT:
            case Token.EnumId.FLOAT:
            case Token.EnumId.DOUBLE:
            case Token.EnumId.SIGNED:
            case Token.EnumId.BOOL:
            case Token.EnumId.COMPLEX:
            case Token.EnumId.IMAGINARY:
                throw new CTFException();     // unsupported

            case Token.EnumId.LONG:
            case Token.EnumId.UNSIGNED:
                tp.Next();
                return(Get(id));

            case Token.EnumId.STRUCT:
                return(CTFStructSpecifier.Parse(scope, tp));

            case Token.EnumId.VARIANT:
                return(CTFVaraintSpecifier.Parse(scope, tp));

            case Token.EnumId.ENUM:
                return(CTFEnumSpecifier.Parse(scope, tp));

            // ctf-type-specifier
            case Token.EnumId.FLOATING_POINT:
            case Token.EnumId.INTEGER:
                tp.Next();
                tp.MustBe(Token.EnumId.LCURL);
                List <CTFAssignmentExpression> cael = CTFAssignmentExpression.ParseList(scope, tp);
                tp.MustBe(Token.EnumId.RCURL);
                return(new CTFATypeSpecifier(id, cael));

            case Token.EnumId.STRING:
                tp.Next();
                return(Get(Token.EnumId.STRING));

            case Token.EnumId.IDEN:     // must be a type in a scope
                CTFTypeSpecifier ct = CTFNTypeSpecifier.Get(scope, tp.Token.Buffer);
                if (ct == null)
                {
                    return(null);
                }

                tp.Next();
                return(ct);
            }

            return(null);
        }
Exemple #2
0
        private CTFFile Parse(TokParser tp)
        {
            for (;;)
            {
                switch (tp.Token.Id)
                {
                case Token.EnumId.CLOCK:
                    Clock = new CTFTClock(ParseAEList(tp));
                    break;

                case Token.EnumId.EVENT:
                    CTFTEvent ce = new CTFTEvent(scope, ParseAEList(tp));
                    Events.Add(ce.Id, ce);
                    break;

                case Token.EnumId.STREAM:
                    stream = new CTFTStream(scope, ParseAEList(tp));
                    break;

                case Token.EnumId.ENV:
                    env = new CTFTEnv(ParseAEList(tp));
                    break;

                case Token.EnumId.TRACE:
                    trace = new CTFTTrace(scope, ParseAEList(tp));
                    break;

                case Token.EnumId.TYPEALIAS:
                    tp.Next();
                    List <CTFTypeSpecifier> cds = CTFITypeSpecifier.ParseList(scope, tp);
                    if (cds == null)
                    {
                        throw new CTFException();
                    }

                    tp.MustBe(Token.EnumId.TYPE_ASSIGNMENT);
                    List <CTFTypeSpecifier> cds2 = CTFITypeSpecifier.ParseList(scope, tp);
                    CTFDeclarator           cd   = CTFDeclarator.Parse(tp);
                    CTFType.AddType(scope, cds, cds2, cd);
                    break;

                case Token.EnumId.STRUCT:
                    CTFITypeSpecifier.ParseTypeSpecifier(scope, tp);
                    break;

                case Token.EnumId.EOF:
                    return(this);

                case Token.EnumId.TERM:
                    tp.Next();     // Skip it
                    break;

                default:
                    throw new CTFException();
                }
            }
        }
Exemple #3
0
        private List <CTFAssignmentExpression> ParseAEList(TokParser tp)
        {
            tp.Next();
            tp.MustBe(Token.EnumId.LCURL);
            List <CTFAssignmentExpression> lcae = CTFAssignmentExpression.ParseList(scope, tp);

            if (lcae == null)
            {
                throw new CTFException();
            }

            tp.MustBe(Token.EnumId.RCURL);
            return(lcae);
        }
        internal static CTFPrimaryExpression Parse(TokParser tp)
        {
            Token t = tp.Token;

            switch (tp.Token.Id)
            {   // All this values can be used in expression
            case Token.EnumId.IDEN:
            case Token.EnumId.ALIGN:
            case Token.EnumId.SIGNED:
            case Token.EnumId.CLOCK:
            case Token.EnumId.EVENT:
            case Token.EnumId.INT_LITERAL:
            case Token.EnumId.STR_LITERAL:
                tp.Next();
                return(new CTFPrimaryExpression(t));
            }

            return(null);
        }
Exemple #5
0
        internal static CTFTypeSpecifier Parse(CTFScope scope, TokParser tp)
        {
            string name = null;
            List <CTFStructOrVariantDeclaration> list = null;

            if (!tp.Match(Token.EnumId.STRUCT))
            {
                return(null);
            }

            if (tp.Token.Id == Token.EnumId.IDEN)
            {
                name = tp.Token.Buffer;
                tp.Next();
            }

            if (tp.Match(Token.EnumId.LCURL))
            {
                list = CTFStructOrVariantDeclaration.ParseList(scope, tp);
                tp.MustBe(Token.EnumId.RCURL);
            }

            int align = 0;

            if (tp.Match(Token.EnumId.ALIGN))
            {
                tp.MustBe(Token.EnumId.LPAREN);
                CTFUnaryExpression cue = CTFUnaryExpression.Parse(tp);
                tp.MustBe(Token.EnumId.RPAREN);
                align = cue.Calculate();
            }

            CTFType ct = CTFType.GetStructType(scope, name, list, align);

            return(new CTFStructSpecifier(ct));
        }