HasSymbol() private méthode

private HasSymbol ( string symName ) : bool
symName string
Résultat bool
Exemple #1
0
 private Symbol GetClosestSymbol(string symName)
 {
     if (_methodSymTable.HasSymbol(symName))
     {
         return(_methodSymTable.GetSymbol(symName));
     }
     if (_classSymTable.HasSymbol(symName))
     {
         return(_classSymTable.GetSymbol(symName));
     }
     return(null);
 }
Exemple #2
0
        private void ParseLocalVarDecl()
        {
            Contract.Requires(IsNextTokenLocalVarDecl());

            Match(new Token(TokenType.Keyword, "var"));
            Token varType = NextToken();

            while (true)
            {
                Token varName = NextToken();

                Symbol variable = new Symbol(
                    varType.Value, varName.Value, SymbolKind.Local, _currentClassName);

                //Locals can't clash with parameter names. This will fail when
                //adding to the symbol table, but crash explicitly:
                if (_methodSymTable.HasSymbol(variable.Name))
                {
                    ThrowCompilationException(
                        "Variable name '" + variable.Name +
                        "' conflicts with existing local variable or formal parameter");
                }

                _methodSymTable.AddSymbol(variable);
                _currentSub.Locals.Add(variable);

                //NOTE: We don't notify the CG of the local declaration,
                //because we include this information when declaring the whole
                //subroutine to the CG.

                if (LookAheadToken.Value != ",")
                {
                    break;
                }
                Match(new Token(TokenType.Symbol, ","));
            }

            Match(new Token(TokenType.Symbol, ";"));
        }