⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symtabtest.g

📁 antlr最新版本V3源代码
💻 G
字号:
grammar SymtabTest;options {    language=Python;}/* Scope of symbol names.  Both globals and block rules need to push a new * symbol table upon entry and they must use the same stack.  So, I must * define a global scope and say that globals and block use this by saying * 'scope Symbols;' in those rule definitions. */scope Symbols {names}@init {self.level = 0}prog:   globals (method)*    ;globalsscope Symbols;@init {self.level += 1$Symbols::names = []}    :   (decl)*        {print "globals: [\%s]" \% ", ".join([str(n) for n in $Symbols::names])self.level -= 1        }    ;method    :   'method' ID '(' ')' block    ;blockscope Symbols;@init {self.level += 1$Symbols::names = []}    :   '{' (decl)* (stat)* '}'        {print "level \%s symbols: [\%s]" \% (self.level, ", ".join([str(n) for n in $Symbols::names]))self.level -= 1        }    ;stat:   ID '=' INT ';'    |   block    ;decl:   'int' ID ';'        {$Symbols::names.append($ID)} // add to current symbol table    ;ID  :   ('a'..'z')+    ;INT :   ('0'..'9')+    ;WS  :   (' '|'\n'|'\r')+ {$channel=HIDDEN}    ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -