Как принять объем во внимание при создании таблицы символов с yacc?

Когда я пишу сервис, я поместил всю сервисную логику в dll проект и создаю два "хоста", которые звонят в этот dll, каждый - служба Windows, и другой приложение командной строки.

я использую приложение командной строки для отладки и присоединяю отладчик к реальному сервису только для ошибок, которые я не могу воспроизвести в приложении командной строки.

я Вы используете этот подход, просто помнят, что необходимо протестировать весь код при выполнении в реальном сервисе, в то время как инструмент командной строки является хорошей помощью для отладки, это - различная среда, и это не ведет себя точно как реальный сервис.

5
задан neuromancer 30 November 2009 в 22:12
поделиться

2 ответа

There are many ways to handle scoping in a symbol table. One very simple way is to have a separate table for each scope and maintain a list of active scopes.

Whenever a new scope is entered, you can create a table for it and add it to the beginning of the active scope list. When you leave the scope, simply remove the head of the active scope list.

I generally find that you don't want to destroy the table when you are done parsing a scope. You may need it later to do semantic analysis, generate debug info, etc.

3
ответ дан 14 December 2019 в 19:16
поделиться

This is issue is only indirectly related to yacc, as you seem to have properly determined. (All yacc does is match input strings to strings in your grammar.)

So, you get to do all the symbol management and all other semantic processing in code. You have any data structure you can imagine at your disposal.

Some thoughts to get organized with:

  • You could create new symbol tables as you enter nested scopes, and then simply perform multiple lookups in an outward direction until you find a given symbol.

  • You could use a single table and tag each symbol with its originating lexical level. You would then need to handle duplicate symbols that differ only in lexical level and would need a lookup that could return multiple symbols, but you would need only a single table. If you don't plan on keeping all the symbols after exiting a scope then this might be more trouble than its worth. If you do this, you might want to keep a separate stack containing a root pointer to links that thread all the symbols in a given scope together.

2
ответ дан 14 December 2019 в 19:16
поделиться
Другие вопросы по тегам:

Похожие вопросы: