Ejemplo n.º 1
0
        private Symbols.Type ParseTypeSpecifier()
        {
            ParseTypedefs();
            switch (scan.Peek().type)
            {
                case Token.Type.KW_VOID:
                case Token.Type.KW_INT:
                case Token.Type.KW_DOUBLE:
                case Token.Type.KW_CHAR:
                    return tstack.GetType(scan.Read());

                case Token.Type.KW_STRUCT:
                    scan.Read();
                    Token identifier = null;
                    if (scan.Peek().type == Token.Type.IDENTIFICATOR)
                    {
                        identifier = scan.Read();
                    }

                    if (scan.Peek().type == Token.Type.LBRACE || identifier == null)
                    {
                        CheckToken(scan.Peek(), Token.Type.LBRACE, true);
                        Symbols.RECORD res = null;
                        if (identifier == null)
                        {
                            res = new Symbols.RECORD();
                        }
                        else
                        {
                            res = new Symbols.RECORD(identifier);
                        }

                        tstack.NewTable();

                        try
                        {
                            ParseStructDeclarationList();
                        }
                        catch (Exception e)
                        {
                            res.SetFields(tstack.PopTable());
                            throw e;
                        }
                        res.SetFields(tstack.PopTable());
                        if (identifier != null)
                        {
                            tstack.AddTag(res);
                        }
                        CheckToken(scan.Peek(), Token.Type.RBRACE, true);
                        return res;
                    }
                    else
                    {
                        return (Symbols.Type)tstack.GetTag(identifier);
                    }
                default:
                    if (scan.Peek().type != Token.Type.IDENTIFICATOR)
                    {
                        throw new Syntax.Exception("требуется объявление", scan.GetPos(), scan.GetLine());
                    }
                    return tstack.GetType(scan.Read());
            }
        }
Ejemplo n.º 2
0
        private Symbols.Type ParseTypeSpecifier()
        {
            ParseTypedefs();
            switch (scan.Peek().type)
            {
            case Token.Type.KW_VOID:
            case Token.Type.KW_INT:
            case Token.Type.KW_DOUBLE:
            case Token.Type.KW_CHAR:
                return(tstack.GetType(scan.Read()));

            case Token.Type.KW_STRUCT:
                scan.Read();
                Token identifier = null;
                if (scan.Peek().type == Token.Type.IDENTIFICATOR)
                {
                    identifier = scan.Read();
                }

                if (scan.Peek().type == Token.Type.LBRACE || identifier == null)
                {
                    CheckToken(scan.Peek(), Token.Type.LBRACE, true);
                    Symbols.RECORD res = null;
                    if (identifier == null)
                    {
                        res = new Symbols.RECORD();
                    }
                    else
                    {
                        res = new Symbols.RECORD(identifier);
                    }

                    tstack.NewTable();

                    try
                    {
                        ParseStructDeclarationList();
                    }
                    catch (Exception e)
                    {
                        res.SetFields(tstack.PopTable());
                        throw e;
                    }
                    res.SetFields(tstack.PopTable());
                    if (identifier != null)
                    {
                        tstack.AddTag(res);
                    }
                    CheckToken(scan.Peek(), Token.Type.RBRACE, true);
                    return(res);
                }
                else
                {
                    return((Symbols.Type)tstack.GetTag(identifier));
                }

            default:
                if (scan.Peek().type != Token.Type.IDENTIFICATOR)
                {
                    throw new Syntax.Exception("требуется объявление", scan.GetPos(), scan.GetLine());
                }
                return(tstack.GetType(scan.Read()));
            }
        }