`
alin_ass
  • 浏览: 34581 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

antlr解析googlecodewiki.1 -- 段落和标题

 
阅读更多

 

input:

 

= ab zx =
abc inline
XXX

== cd ==
zef
 

antlr syntax:

 

grammar bestpaper;  
options {  
    output=AST;  
    ASTLabelType=CommonTree;  
}  
chapter   
    :   (paragraph NEWLINE+)+;     
paragraph  
    :   heading NEWLINE+ content | heading;    
heading  
    :  SPACE? (heading1 | heading2 | heading3 | heading4 | heading5 | heading6) SPACE?;      
heading1  
    :   H1 SPACE title SPACE H1;  
heading2  
    :   H2 SPACE title SPACE H2;  
heading3  
    :   H3 SPACE title SPACE H3;  
heading4  
    :   H4 SPACE title SPACE H4;  
heading5  
    :   H5 SPACE title SPACE H5;  
heading6  
    :   H6 SPACE title SPACE H6;      
title     
    :   (WORD SPACE)* WORD;  
content   
    :   (line NEWLINE)* line;  
line  
    :	SPACE? (WORD SPACE)* WORD SPACE? | SPACE;

      
H1  
    :   '=';  
H2  
    :   '==';  
H3  
    :   '===';  
H4  
    :   '====';  
H5  
    :   '=====';  
H6  
    :   '======';     
INT   
    :   ('1'..'9')('0'..'9')* | '0';          
NEWLINE   
    :   '\r'? '\n' ;  
SPACE     
    :   (' ' | '\t')+;  
WORD  
    :   (~('\r' | '\n' | ' ' | '\t'))+; 

 

parse tree:



  • 大小: 11.9 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics