ATN for zero or more occurences

32 views
Skip to first unread message

Andrzej Borucki

unread,
Dec 3, 2012, 6:26:11 PM12/3/12
to antlr-di...@googlegroups.com

?

We have simple grammar
s : ID
    | ID '=' expr
    | 'unsigned'* 'int' ID
    | 'unsigned'* ID ID
    ;
is zero or more occurences of 'unsigned'. How work with it?
I see two ways:
First, change grammar to:
s : ID
    | ID '=' expr
    | occur_unsigned 'int' ID
    | occur_unsigned ID ID
    ;

occur_unsigned: :eps
                          occur_unsigned 'unsigned'
                        ;
or
occur_unsigned: :eps
                          'unsigned' occur_unsigned
                        ;

or create ATN with edges back (image above):

ATNpg2.dot

Terence Parr

unread,
Dec 3, 2012, 9:30:53 PM12/3/12
to antlr-di...@googlegroups.com
that s grammar should work fine. what is the question/problem? antlr with -nfa option in v3 gives what? should be same NFA (or more correctly ATN).

Ter
> --
>
>
> <ATNpg2.dot>

Andrzej Borucki

unread,
Dec 4, 2012, 4:26:00 AM12/4/12
to antlr-di...@googlegroups.com
W dniu wtorek, 4 grudnia 2012 03:30:53 UTC+1 użytkownik the_antlr_guy napisał:
that s grammar should work fine. what is the question/problem? antlr with -nfa option in v3 gives what? should be same NFA (or more correctly ATN).

Question is solved, and was: what to do if production is defined by regular expression instead od simple list of terminals and nonterminals. Antrl with -nfa options generated more complicated NFA. 
I think, procedure creating NFA is similar to creating standard NFA from regulat expression (for example http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH16/CH16-2.html

Reply all
Reply to author
Forward
0 new messages