Exemplo n.º 1
0
        /// <summary>
        /// CompilationUnit :: = { "import" Identifier {"." Identifier} ";"} {ClassDeclaration}.
        /// </summary>
        /// <returns></returns>
        public PROGRAM parseCompilationUnit()
        {
            PROGRAM result = new PROGRAM(errors);

            while (true)
            {
                CLASS cls = parseClassDeclaration();
                if ( cls == null ) break;
                result.classes.Add(cls.name,cls);
            }
            if ( !hasMain ) errors.issue(33); // no 'Main'
            return result;
        }
Exemplo n.º 2
0
        public override void resolve(PROGRAM p, CLASS c, METHOD m)
        {
            base.resolve(p,c,m);
            if ( field == null ) return; // error was detected

            if ( field is FIELD )
            {
                FIELD f = field as FIELD;
                f.type.resolve(p,c,m);
                if ( f.type.classRef != null )
                {
                    member = findFieldInClass(f.type.classRef,sname);
                    if ( member == null ) member = findMethodInClass(f.type.classRef,sname);
                    if ( member == null ) p.errors.issue(21,"field or method",sname);
                    if ( member != null )
                    {
                        if ( member.isStatic ) p.errors.issue(26,member.name);
                        if ( member.isPrivate ) p.errors.issue(27,member,name); // access violation
                    }
                }
                else // a non-class variable in selector
                    p.errors.issue(25);
            }
            else if ( field is CLASS )
            {
                CLASS cls = field as CLASS;
                member = findFieldInClass(cls,sname);
                if ( member == null ) member = findMethodInClass(cls,sname);
                if ( member == null ) p.errors.issue(21,"field or method",name);
                if ( member != null )
                {
                    if ( !member.isStatic ) p.errors.issue(24,member.name);
                    if ( member.isPrivate ) p.errors.issue(27,member.name); // access violation
                }
            }
            else if ( field is METHOD )
                p.errors.issue(25); // a method in the left part of the selector
        }
Exemplo n.º 3
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     if ( result == null ) return;
     result.resolve(p,c,m);
 }
Exemplo n.º 4
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     expression1.resolve(p,c,m);
     expression2.resolve(p,c,m);
 }
Exemplo n.º 5
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     foreach ( CLASS cls in classes.Values )
         cls.resolve(this,null,null);
 }
Exemplo n.º 6
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     if ( bname != null )
     {
         baseClass = findClass(p,bname);
         if ( baseClass == null ) p.errors.issue(21,"base class");
     }
     foreach ( FIELD f in fields.Values )
         f.resolve(p,this,null);
     foreach ( METHOD meth in methods.Values )
         meth.resolve(p,this,null);
 }
 public Generator(Source s, Errors e, PROGRAM p)
 {
     source = s;
     errors = e;
     program = p;
 }
Exemplo n.º 8
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     if (classRef != null) return; // already resolved
     if (className == "int") return; // not necessary to resolve
     classRef = findClass(p,className);
     if ( classRef == null ) p.errors.issue(21,"class",className);
 }
Exemplo n.º 9
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     if ( m != null ) field = findFieldInMethod(m,name);
     if ( field == null && c != null ) field = findFieldInClass(c,name);
     if ( field == null && c != null ) field = findMethodInClass(c,name);
     if ( field == null ) p.errors.issue(21,"name",name);
     else
     {
         FIELD f = field as FIELD;
         if ( f != null && (f.isLocal || f.isParameter) ) return;
         if ( field is FIELD || field is METHOD )
         {
             if ( field.isStatic && !m.isStatic ) p.errors.issue(28,field.name);
             if ( !field.isStatic && m.isStatic ) p.errors.issue(29,field.name);
         }
     }
 }
Exemplo n.º 10
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     if ( type != null ) type.resolve(p,c,m);
     foreach ( FIELD f in parameters.Values )
         f.resolve(p,c,this);
     foreach ( FIELD f in locals.Values )
         f.resolve(p,c,this);
     foreach ( STATEMENT s in statements )
         s.resolve(p,c,this);
 }
Exemplo n.º 11
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     relation.resolve(p,c,m);
     thenPart.resolve(p,c,m);
     elsePart.resolve(p,c,m);
 }
Exemplo n.º 12
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     if ( type == null ) return;
     type.resolve(p,c,m);
 }
Exemplo n.º 13
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     term.resolve(p,c,m);
     foreach ( TERM t in terms )
         t.resolve(p,c,m);
 }
Exemplo n.º 14
0
 public virtual void resolve(PROGRAM p, CLASS c, METHOD m)
 {
 }
Exemplo n.º 15
0
 public CLASS findClass(PROGRAM program, string name)
 {
     if (program.classes.ContainsKey(name)) return program.classes[name];
     return null;
 }
Exemplo n.º 16
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     factor.resolve(p,c,m);
     foreach ( FACTOR f in factors )
         f.resolve(p,c,m);
 }
Exemplo n.º 17
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     foreach ( STATEMENT s in statements )
         s.resolve(p,c,m);
 }
Exemplo n.º 18
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     if (name == null) return; // new int
     classRef = findClass(p,name);
     if (classRef == null) p.errors.issue(21,"class",name);
 }
Exemplo n.º 19
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     relation.resolve(p,c,m);
     body.resolve(p,c,m);
 }
Exemplo n.º 20
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     base.resolve(p,c,m);
     size.resolve(p,c,m);
 }
Exemplo n.º 21
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     value.resolve(p,c,m);
 }
Exemplo n.º 22
0
 public override void resolve(PROGRAM p, CLASS c, METHOD m)
 {
     name.resolve(p,c,m);
     foreach ( EXPRESSION a in arguments )
         a.resolve(p,c,m);
 }