コード例 #1
0
        private void EnterIdentifiers(IEnumerable <IdentifierNode> identifiers, SymbolTableEntryType type, ref int localVariableIndex)
        {
            int index;

            if (type == SymbolTableEntryType.Parameter)
            {
                index = 0;
            }
            else if (type == SymbolTableEntryType.Variable)
            {
                index = localVariableIndex;
            }
            else
            {
                throw new ArgumentException("type must be Parameter or Variable", "type");
            }

            foreach (var identifier in identifiers)
            {
                string scopeString = _scopeStack.CreateScopeString(identifier.Name);
                var    entry       = new SymbolTableEntry(identifier.Name, type, index);
                AddSymbol(scopeString, entry);
                ++index;
            }

            if (type == SymbolTableEntryType.Variable)
            {
                localVariableIndex = index;
            }
        }
コード例 #2
0
        public static void Initialize(ref Grammar grammar)
        {
            grammar.Add(new Production(ParserConstants.Declaration,
                                       new SubProduction
                                       (
                                           new List <ExpressionDefinition>
            {
                new TerminalExpressionDefinition {
                    TokenType = TokenType.TypeDeclaration
                },
                new TerminalExpressionDefinition {
                    TokenType = TokenType.Identifier
                },
                new SemanticActionDefinition((ParsingNode node) =>
                {
                    string type = node.GetAttributeForKey <WordToken>(ParserConstants.TypeDeclaration, ParserConstants.Token).Lexeme;

                    SymbolTable symbolTable = node.FirstParentWithAttribute(ParserConstants.SymTable).GetAttribute <SymbolTable>(ParserConstants.SymTable);
                    string key = node.GetAttributeForKey <WordToken>("Identifier", ParserConstants.Token).Lexeme;
                    SymbolTableEntryType symbolEntryType = SymbolTable.StringToSymbolTableEntryType(type);
                    SymbolTableEntry entry = symbolTable.Create(key, symbolEntryType);

                    DeclarationASTNode syntaxTreeNode = new DeclarationASTNode();
                    syntaxTreeNode.SymbolTableEntry   = entry;
                    node.Attributes.Add(ParserConstants.SyntaxTreeNode, syntaxTreeNode);
                })
            }
                                       )
                                       ));;
        }
コード例 #3
0
        public SymbolTableEntry Create(string name, SymbolTableEntryType type)
        {
            SymbolTableEntry entry = new SymbolTableEntry
            {
                Name = name,
                Type = type
            };

            Entries.Add(entry);

            return(entry);
        }
コード例 #4
0
        private void EnterIdentifiers(IEnumerable<IdentifierNode> identifiers, SymbolTableEntryType type, ref int localVariableIndex)
        {
            int index;
            if (type == SymbolTableEntryType.Parameter)
                index = 0;
            else if (type == SymbolTableEntryType.Variable)
                index = localVariableIndex;
            else
                throw new ArgumentException("type must be Parameter or Variable", "type");

            foreach (var identifier in identifiers)
            {
                string scopeString = _scopeStack.CreateScopeString(identifier.Name);
                var entry = new SymbolTableEntry(identifier.Name, type, index);
                AddSymbol(scopeString, entry);
                ++index;
            }

            if (type == SymbolTableEntryType.Variable)
                localVariableIndex = index;
        }
コード例 #5
0
 public SymbolTableEntry(string label, SymbolTableEntryType type, int index)
 {
     Label = label;
     Type  = type;
     Index = index;
 }
コード例 #6
0
 public SymbolTableEntry(string label, SymbolTableEntryType type, int index)
 {
     Label = label;
     Type = type;
     Index = index;
 }