Example #1
0
        public override bool ResolveNames(LexicalScope scope)
        {
            // Step 1: Create new scope and populate the symbol table
            var newScope = getNewScope(scope, null);

            // Step 1a: add all class declarations to the current scope
            foreach (Statement each in ClassDeclarations)
            {
                Declaration classDec = each as Declaration;
                if (classDec != null)
                {
                    classDec.AddItemsToSymbolTable(newScope);
                }
            }

            // Step 2: ResolveNames for each part of the complilation unit
            bool loopResolve = true;

            if (ClassDeclarations != null)
            {
                foreach (ClassDeclaration each in ClassDeclarations)
                {
                    loopResolve = loopResolve & each.ResolveNames(newScope);
                }
            }

            // need to do something special with package declarations and import declarations - Nathan

            return(loopResolve);
        }
Example #2
0
        public override bool ResolveNames(LexicalScope scope)
        {
            // Step 1: Create new scope and populate the symbol table
            // Special case with blocks - add to symbol table line by line as the names are resolved.
            // This is the catch the situation where the declaration is after the use of the variable.
            //var newScope = getNewScope(scope, null);

            // Step 2: ResolveNames for each part of the complilation unit
            bool loopResolve = true;

            if (statements != null)
            {
                foreach (Statement each in statements)
                {
                    Declaration decl = each as Declaration; // try to cast statement as a declaration
                    if (decl != null)
                    {
                        decl.AddItemsToSymbolTable(scope);
                    }
                    loopResolve = loopResolve & each.ResolveNames(scope);
                }
            }

            return(loopResolve);
        }
Example #3
0
		public static LexicalScope getNewScope(LexicalScope oldScope, List<Expression> variableList)
		{
            // Step 1: Create scope that includes standard libraries (ie Java.Lang) if oldScope == null.
            if (oldScope == null)
            {
                var JLnode = new JavaLang();
                oldScope = new LexicalScope();
                oldScope.Symbol_table = new Dictionary<string, Declaration>();
                JLnode.AddItemsToSymbolTable(oldScope);
            }

			// Step 1: set the new scope
			var newScope = new LexicalScope();
			newScope.ParentScope = oldScope;
			newScope.Symbol_table = new Dictionary<string, Declaration>();

			// Step 2: Check for declarations in the new scope and add to symbol_table of old scope
			if (variableList != null)
			{
				foreach (Expression each in variableList)
				{
					Declaration decl = each as Declaration; // try to cast statement as a declaration
					if (decl != null)
					{
                        decl.AddItemsToSymbolTable(newScope);
					}
				}
			}

			return newScope;
		}
Example #4
0
        public override Boolean ResolveNames(LexicalScope scope)
        {
            // Step 2: Create new scope
            var newScope = getNewScope(scope, null);

            // Step 1: Add class name to current scope
            //AddItemsToSymbolTable(scope);
            // Step 0: add all class declarations to the current scope
            foreach (Statement each in classBody)
            {
                Declaration methodDec = each as Declaration;

                // Should create new scope and add here. This will allow diffrent class
                // have a method with similar name.
                if (methodDec != null)
                {
                    if (methodDec is MethodDeclaration)
                    {
                        // We want Main method at global scope
                        var dec = (MethodDeclaration)methodDec;
                        if (dec.isMainMethod())
                        {
                            methodDec.AddItemsToSymbolTable(scope);
                        }
                    }
                    methodDec.AddItemsToSymbolTable(newScope);
                }
            }

            // Step 3: ResolveNames for each statement in the class
            bool loopResolve = true;

            if (classBody != null)
            {
                foreach (Statement each in classBody)
                {
                    loopResolve = loopResolve & each.ResolveNames(newScope);
                }
            }

            return(loopResolve);
        }
Example #5
0
        public override bool ResolveNames(LexicalScope scope)
        {
            // Step 2: ResolveNames for each part of the complilation unit
            bool loopResolve = true;

            if (statements != null)
            {
                foreach (Statement each in statements)
                {
                    Declaration decl = each as Declaration; // try to cast statement as a declaration
                    if (decl != null)
                    {
                        decl.AddItemsToSymbolTable(scope);
                    }
                    loopResolve = loopResolve & each.ResolveNames(scope);
                }
            }

            return(loopResolve);
        }
Example #6
0
        public override bool ResolveNames(LexicalScope scope)
        {
            //note each switch block is a new scope
            var newScope = getNewScope(scope, null);

            bool loopResolve = true;

            if (block != null)
            {
                foreach (Statement each in block)
                {
                    Declaration decl = each as Declaration; // try to cast statement as a declaration
                    if (decl != null)
                    {
                        decl.AddItemsToSymbolTable(scope);
                    }
                    loopResolve = loopResolve & each.ResolveNames(scope);
                }
            }

            return(loopResolve && expression.ResolveNames(scope));
        }