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

📄 simplec.g

📁 antlr最新版本V3源代码
💻 G
字号:
grammar SimpleC;options {    language = Python;}program    :   declaration+    ;/** In this rule, the functionHeader left prefix on the last two *  alternatives is not LL(k) for a fixed k.  However, it is *  LL(*).  The LL(*) algorithm simply scans ahead until it sees *  either the ';' or the '{' of the block and then it picks *  the appropriate alternative.  Lookhead can be arbitrarily *  long in theory, but is <=10 in most cases.  Works great. *  Use ANTLRWorks to see the lookahead use (step by Location) *  and look for blue tokens in the input window pane. :) */declaration    :   variable    |   functionHeader ';'	{print $functionHeader.name+" is a declaration"}    |   functionHeader block	{print $functionHeader.name+" is a definition"}    ;variable    :   type declarator ';'    ;declarator    :   ID     ;functionHeader returns [name]    :   type ID '(' ( formalParameter ( ',' formalParameter )* )? ')'	{$name = $ID.text}    ;formalParameter    :   type declarator            ;type    :   'int'       |   'char'      |   'void'    |   ID            ;block    :   '{'            variable*            stat*        '}'    ;stat: forStat    | expr ';'          | block    | assignStat ';'    | ';'    ;forStat    :   'for' '(' assignStat ';' expr ';' assignStat ')' block            ;assignStat    :   ID '=' expr            ;expr:   condExpr    ;condExpr    :   aexpr ( ('==' | '<') aexpr )?    ;aexpr    :   atom ( '+' atom )*    ;atom    : ID          | INT          | '(' expr ')'    ; ID  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*    ;INT :	('0'..'9')+    ;WS  :   (   ' '        |   '\t'        |   '\r'        |   '\n'        )+        {$channel=HIDDEN}    ;    

⌨️ 快捷键说明

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