compiler construction - ANTLR return group of lexical rules? -


can replace indent_loop[3] in following grammar the group of 3 indent? indent lexical rule indentation.

i want write number of indent based on number.

match_node         :   match_node_name (tree_operator) (new_line (indent_loop[3]) ( modulecall | literals ))*             { match_node_list.push($match_node_name.text); }         |   single_quote pointe single_quote          ;       match_node_name         :   ident_small_letters         ;      indent_loop[int scope]         :   {scope == 3}? indent indent indent           |   {scope == 4}? indent indent indent indent            ;      indent :  '\t'; 

when did not able come calling rule , not able return group of indentation? means, ( modulecall | literals ))* not called.

where wrong? begining.

or there other way this?

you can using semantic predicate1:

grammar t;  parse  : digit[1] digit[2] digit[3] eof  ;  digit[int amount]  : ({amount > 0}?=> digit {amount--;})*  ;  digit  : '0'..'9'  ; 

parsing "456789" parser generated grammar above, result in following parse:

enter image description here

note in case, you're matching tab, not indentation (i.e. 1 or more tabs start of line). if want match indentations start of line, (imho) easiest way handle them in lexer2.


1 what 'semantic predicate' in antlr?
2 antlr simpliest way realize python indent-depending grammar?


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -