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

📄 t.g

📁 antlr最新版本V3源代码
💻 G
字号:
/** Convert the simple input to be java code; wrap in a class, *  convert method with "public void", add decls.  This shows how to insert *  extra text into a stream of tokens and how to replace a token *  with some text.  Calling toString() on the TokenRewriteStream *  in Main will print out the original input stream. * *  Note that you can do the instructions in any order as the *  rewrite instructions just get queued up and executed upon toString(). */grammar T;options {    language=Python;}program@init {    start = self.input.LT(1)}    :   method+        {        self.input.insertBefore(start,"public class Wrapper {\n")        # note the reference to the last token matched for method:        self.input.insertAfter($method.stop, "\n}\n")        }    ;method    :   m='method' ID '(' ')' body        {self.input.replace($m, "public void");}    ; body// decls is on body's local variable stack but is visible to// any rule that body calls such as stat.  From other rules// it is referenced as $body::decls// From within rule body, you can use $decls shorthandscope {    decls}@init {    $body::decls = set()}    :   lcurly='{' stat* '}'        {        # dump declarations for all identifiers seen in statement list        for it in $body::decls:            self.input.insertAfter($lcurly, "\nint "+it+";")        }    ;stat:   ID '=' expr ';' {$body::decls.add($ID.text);} // track left-hand-sides    ;expr:   mul ('+' mul)*     ;mul :   atom ('*' atom)*    ;atom:   ID    |   INT    ;ID  :   ('a'..'z'|'A'..'Z')+ ;INT :   ('0'..'9')+ ;WS  :   (' '|'\t'|'\n')+ {$channel=HIDDEN;}    ;

⌨️ 快捷键说明

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