Ejemplo n.º 1
0
        private Boolean inCurrentScope(String id)
        {
            Boolean   isNewId          = true;
            ScopeNode currentScopeNode = this.scopes[this.currentScope];

            for (int i = 0; i < currentScopeNode.scopeMembers.Count; i++)
            {
                if (id == currentScopeNode.scopeMembers[i].id.ToString())
                {
                    isNewId = false;
                }
            }
            return(isNewId);
        }
Ejemplo n.º 2
0
        private void generateVarDecl(Node root)
        {
            String  type  = root.children[0].name;
            String  id    = root.children[1].name;
            Boolean isNew = inCurrentScope(id);

            if (isNew)
            {
                ScopeNode currentScope = this.scopes[this.currentScope];
                currentScope.scopeMembers.Add(new ScopeElement(type, id));
                buildPrintMessage("id: " + id + " created in scope " + this.currentScope + ".");
            }
            else
            {
                buildPrintMessage("~~~Error: id " + id + " already exists in scope " + this.currentScope + ".");
                this.errorCount++;
            }
        }
Ejemplo n.º 3
0
        private Tuple <int, int> findScope(String id)
        {
            Boolean   foundId          = false;
            int       scopeIndex       = -1;
            int       locationInScope  = -1;
            ScopeNode currentScopeNode = this.scopes[this.currentScope];
            int       scopePlaceHolder = this.currentScope;

            while (this.currentScope != -1 && !foundId)
            {
                foundId = !inCurrentScope(id);
                if (!foundId)
                {
                    this.currentScope = currentScopeNode.parentId;
                    if (this.currentScope != -1)
                    {
                        currentScopeNode = this.scopes[this.currentScope];
                    }
                }
            }

            if (foundId)
            {
                scopeIndex        = this.currentScope;
                this.currentScope = scopePlaceHolder;
                currentScopeNode  = this.scopes[scopeIndex];
                for (int i = 0; i < currentScopeNode.scopeMembers.Count; i++)
                {
                    if (id == currentScopeNode.scopeMembers[i].id)
                    {
                        locationInScope = i;
                    }
                }
            }
            return(new Tuple <int, int>(scopeIndex, locationInScope));
        }