antlr最新版本V3源代码

源代码在线查看: t.g

软件大小: 3471 K
上传用户: LotusAwhaT
关键词: antlr 版本 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				grammar T;								options {				    language=Python;				}								program : method ;								method				/* name is visible to any rule called by method directly or indirectly.				 *  There is also a stack of these names, one slot for each nested				 *  invocation of method.  If you have a method nested within another				 *  method then you have name strings on the stack.  Referencing				 *  $method.name access the topmost always.  I have no way at the moment				 *  to access earlier elements on the stack.				 */				scope {				name				}				    :   'method' ID '(' ')' {$method::name=$ID.text;} body				    ; 								body:   '{' stat* '}'				    ;								stat:   ID '=' expr ';'				    |   method // allow nested methods to demo stack nature of dynamic attributes				    ;								expr:   mul ('+' mul)* 				    ;								mul :   atom ('*' atom)*				    ;								/** Demonstrate that 'name' is a dynamically-scoped attribute defined				 *  within rule method.  With lexical-scoping (variables go away at				 *  the end of the '}'), you'd have to pass the current method name				 *  down through all rules as a parameter.  Ick.  This is much much better.				 */				atom:   ID  {print "ref "+$ID.text+" from method "+$method::name}				    |   INT {print "int "+$INT.text+" in method "+$method::name}				    ;								ID  :   ('a'..'z'|'A'..'Z')+ ;								INT :   '0'..'9'+ ;								WS  :   (' '|'\t'|'\n')+ {$channel=HIDDEN}				    ;							

相关资源