AddSymbol() public method

public AddSymbol ( Symbol symbol ) : void
symbol Symbol
return void
Esempio n. 1
0
        //formal-param-list ::= ((<type> <var-name>) (',' <type> <var-name>)*)?
        private void ParseFormalParamList()
        {
            while (LookAheadToken.Value != ")")
            {
                Token paramType = NextToken();
                Token paramName = NextToken();

                if (paramType.Type != TokenType.Keyword &&
                    paramType.Type != TokenType.Ident)
                {
                    ThrowCompilationException("Invalid parameter type '" + paramType.Value + "'");
                }
                if (paramName.Type != TokenType.Ident)
                {
                    ThrowCompilationException("Invalid parameter name '" + paramName.Value + "'");
                }

                Symbol parameter = new Symbol(paramType.Value, paramName.Value,
                                              SymbolKind.Parameter, _currentClassName);
                _currentSub.Parameters.Add(parameter);
                _methodSymTable.AddSymbol(parameter);

                if (LookAheadToken.Value == ",")
                {
                    NextToken();//Skip the comma
                }
            }
        }
Esempio n. 2
0
        private void ParseClassVarDecl()
        {
            Contract.Requires(IsNextTokenClassVarDecl());

            Token varKind  = NextToken();
            bool  isStatic = varKind.Value == "static";
            Token varType  = NextToken();
            Token varName  = NextToken();

            do
            {
                if (isStatic)
                {
                    Symbol variable = new Symbol(
                        varType.Value, varName.Value, SymbolKind.Static, _currentClassName);
                    _classSymTable.AddSymbol(variable);
                    _codeGenerator.StaticDeclaration(variable);
                }
                else
                {
                    Symbol variable = new Symbol(
                        varType.Value, varName.Value, SymbolKind.Field, _currentClassName);
                    _classSymTable.AddSymbol(variable);
                    _codeGenerator.FieldDeclaration(variable);
                }
            } while (LookAheadToken.Value == ",");

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