Exemplo n.º 1
0
 public void visitIdentifier(Identifier i)
 {
     i.declaration = _currentScope.find(i);
     if (_inImport)
     {
         // add the import as a declaration
         //i.declaration.accept(this);
     }
 }
Exemplo n.º 2
0
        public Variable find(Identifier i)
        {
            if (i.type == IdentifierType.Simple)
            {
                if (_locals.ContainsKey(i))
                {
                    return(_locals[i]);
                }
                else if (hasParent())
                {
                    return(_parent.find(i));
                }
                //else if (_componentScopes.ContainsKey(identifier))
                //{

                //}
                else
                {
                    throw new ScopeException(i.row, i.col, $"{i.name} has not been declared");
                }
            }
            else if (i.type == IdentifierType.Compound)
            {
                List <Identifier> parts = i.parts;
                // can only currently handle components
                if (parts.Count == 2)
                {
                    Scope componentScope = findImportScope(parts[0]);
                    return(componentScope.find(parts[1]));
                }
                else
                {
                    throw new ArgumentException();
                }

                //Scope activeScope = this;
                //Variable result = null;
                //while (parts.Count > 0)
                //{
                //    Identifier part = parts[0];
                //    parts.RemoveAt(0);

                //    Variable v = activeScope.find(part);
                //    if (parts.Count == 0)
                //    {
                //        result = v;
                //        break;
                //    }
                //    else
                //    {
                //        activeScope = v.scope;
                //    }
                //}

                //if (result != null)
                //{
                //    return result;
                //}
                //else
                //{
                //    throw new ScopeException(identifier.row, identifier.col, $"{identifier.name} has not been declared.");
                //}
            }
            else
            {
                throw new ArgumentException();
            }
        }