예제 #1
0
        private Type ReadType()
        {
            Token tok;
            Type  elementType = ReadNonArrayType();
            List <List <Annotation> > dims = new List <List <Annotation> >();

            while (IsSymbol(tok = PeekToken(), "@") || IsSymbol(tok, "["))
            {
                List <Annotation> annotations = new List <Annotation>();
                while (IsSymbol(PeekToken(), "@"))
                {
                    annotations.Add(ReadAnnotation());
                }
                ReadSymbol("[");
                ReadSymbol("]");
                dims.Add(annotations);
            }
            if (dims.Count == 0)
            {
                return(elementType);
            }
            else
            {
                return(new ArrayType(elementType, dims));
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            string path = "../../test_files/test.txt";

            using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                StreamReader sr = new StreamReader(fs);

                Parser        parser = new Parser(sr);
                PrivateObject prv    = new PrivateObject(parser);
                Type          type   = (Type)(prv.Invoke("ReadType", new object[0]));

                CompilationUnit unit = parser.ReadCompilationUnit();
            }

            Console.WriteLine("Done.");
            Console.ReadLine();
        }
예제 #3
0
        private NormalClassDeclaration ReadNormalClassDeclaration()
        {
            List <Modifier>      modifiers = new List <Modifier>();
            Identifier           iden;
            List <TypeParameter> typeParams = new List <TypeParameter>();
            Type        superclass          = null;
            List <Type> superinterfaces     = new List <Type>();
            ClassBody   body;

            while (!IsSymbol(PeekToken(), "class"))
            {
                modifiers.Add(ReadModifier());
            }
            ReadSymbol("class");
            iden = ReadIdentifier();
            if (IsSymbol(PeekToken(), "<"))
            {
                ReadSymbol("<");
                bool readParams = true;
                while (readParams)
                {
                    typeParams.Add(ReadTypeParameter());
                    if (IsSymbol(PeekToken(), ","))
                    {
                        ReadSymbol(",");
                    }
                    else
                    {
                        readParams = false;
                    }
                }
                ReadSymbol(">");
            }
            if (IsSymbol(PeekToken(), "extends"))
            {
                ReadSymbol("extends");
                superclass = ReadType();
            }
            if (IsSymbol(PeekToken(), "implements"))
            {
                ReadSymbol("implements");
                superinterfaces.Add(ReadType());
            }
            body = ReadClassBody();
            return(new NormalClassDeclaration(modifiers, iden, typeParams, superclass, superinterfaces, body));
        }