<html>
<body>
It is AntlrDT:
<a href="http://www.certiv.net/projects/antlrdt.html" eudora="autourl">
http://www.certiv.net/projects/antlrdt.html<br><br>
</a>At 07:20 PM 11/3/2009, you wrote:<br>
<blockquote type=cite class=cite cite="">Hi Gerald,<br><br>
What's the program you used to generate those diagrams in the last
message? I sometimes have a bit of trouble understanding what the 2nd
alternatives are in ANTLRWorks, and this might with it.<br><br>
Chi Ho Kwok<br><br>
On Tue, Nov 3, 2009 at 7:55 PM, Gerald Rosenberg
&lt;<a href="mailto:gerald@certiv.net">gerald@certiv.net</a>&gt;
wrote:<br>

<dl>
<dd>The first version is failing on the associative_dimension_1</i> not
having a star</i> or data_type</i> and no other alternative
available.<br><br>

<dd>The second version falls through the associative_dimension_2</i> to
sized_or_unsized_dimension</i> to recognize the '[]' <br><br>

<dd>Note, both have a bit of backtracking that may be problematic on more
complex inputs.<br><br>

<dd>HTHs,<br>

<dd>Gerald<br><br>
<br>

<dd>At 10:22 AM 11/3/2009,
<a href="mailto:alex.marin@amiq.ro">alex.marin@amiq.ro</a> wrote:<br>
<blockquote type=cite class=cite cite="">
<dd>Hello,<br><br>

<dd>We have trouble understanding why we get a &quot;no viable
alternative&quot; when<br>

<dd>running the attached parser grammar on the following input:<br><br>

<dd>bit bitstream [];<br><br>

<dd>The output is:<br><br>

<dd>line 1:15 no viable alternative at input ']'<br><br>

<dd>However, we have found two (very strange) workarounds for the
issue:<br>

<dd>1. Commenting out the 'real' option in the data_type rule<br>

<dd>2. Using associative_dimension_2 rule instead of
associative_dimension_1<br>

<dd>(although the two are equivalent)<br><br>

<dd>What is the explanation for this behavior?<br>

<dd>Is there a rigurous solution to avoid such behavior?<br><br>

<dd>Thanks,<br>

<dd>Alex Marin<br><br>

<dd>Notes:<br>

<dd>- the example is not intended to be useful by itself (it is an
excerpt from<br>

<dd>a much larger grammar)<br>

<dd>- the latest antlr version has been used for code generation<br>

<dd>(antlr-3.2.jar)<br>

<dd>- you can find the referred grammar inline at the end of this e-mail
and<br>

<dd>also in the attached file<br>

<dd>- by comparing the generated parsers, we noticed that the workarounds
cause<br>

<dd>the prediction to be done by some complicated if-conditions rather
than the<br>

<dd>dfa which throws the NoViableAlt<br><br>

<dd>////////////////// Example.g ////////////////////////<br><br>

<dd>grammar Example;<br><br>

<dd>options {<br>

<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k=1;<br>

<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output=AST;<br>

<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>

<dd>entry<br>

<dd>:<br>

<dd>(my_rule)+<br>

<dd>;<br><br>

<dd>my_rule<br>

<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<br>

<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tf_port_item
SEMI<br>

<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;<br><br>

<dd>tf_port_item<br>

<dd>: <br>

<dd>data_type ID variable_dimension<br>

<dd>;<br><br>
<br>

<dd>data_type<br>

<dd>:<br>

<dd>'bit'<br>

<dd>| 'byte'<br>

<dd>| 'real' // Comment this to suppress NoViableAlt<br>

<dd>| 'struct' <br>

<dd>| 'union' ( 'tagged' )? <br>

<dd>| 'enum' <br>

<dd>| 'virtual'<br>

<dd>| ps_identifier <br>

<dd>;<br><br>

<dd>ps_identifier<br>

<dd>:<br>

<dd>( ID COLON_COLON ) =&gt; ID COLON_COLON ID <br>

<dd>| ID<br>

<dd>;<br>

<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>

<dd>variable_dimension<br>

<dd>:<br>

<dd>( associative_dimension_1 ) =&gt; associative_dimension_1
variable_dimension&nbsp; <br>

<dd>// comment this line<br>

<dd>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (
associative_dimension_2 ) =&gt; associative_dimension_2<br>

<dd>variable_dimension&nbsp; // and uncomment this one to suppress
NoViableAlt (<br>

<dd>with 'real' alt in data_type)<br>

<dd>| ( sized_or_unsized_dimension )*<br>

<dd>;<br><br>

<dd>associative_dimension_1<br>

<dd>:<br>

<dd>LBRACK ( STAR | data_type ) RBRACK<br>

<dd>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><br>

<dd>associative_dimension_2<br>

<dd>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
:<br>

<dd>( LBRACK STAR ) =&gt; LBRACK STAR RBRACK<br>

<dd>| LBRACK data_type RBRACK<br>

<dd>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
;<br><br>
<br>

<dd>sized_or_unsized_dimension <br>

<dd>:<br>

<dd>LBRACK ( NUMBER )? RBRACK <br>

<dd>;<br><br>

<dd>/********** Lexer *************/<br><br>

<dd>SEMI: ';';<br>

<dd>STAR: '*';<br>

<dd>LBRACK: '[';<br>

<dd>RBRACK: ']';<br>

<dd>COLON_COLON: '::';<br><br>

<dd>WS<br>

<dd>:<br>

<dd>(' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}<br>

<dd>;<br><br>

<dd>ID<br>

<dd>:<br>

<dd>('a'..'z'|'A'..'Z'|'_') ('0'..'9'|'a'..'z'|'A'..'Z'|'_')*<br>

<dd>;<br><br>

<dd>NUMBER<br>

<dd>:<br>

<dd>('0'..'9')+<br>

<dd>;<br><br>
<br>

<dd>Content-Type: application/octet-stream;
charset=&quot;UTF-8&quot;;<br>

<dd>&nbsp;name=&quot;Example.g&quot;; <br>

<dd>Content-Disposition: attachment;<br>

<dd>&nbsp;filename=&quot;Example.g&quot;; <br><br>
<br>

<dd>List:
<a href="http://www.antlr.org/mailman/listinfo/antlr-interest">
http://www.antlr.org/mailman/listinfo/antlr-interest</a><br>

<dd>Unsubscribe:
<a href="http://www.antlr.org/mailman/options/antlr-interest/your-email-address">
http://www.antlr.org/mailman/options/antlr-interest/your-email-address</a>
 </blockquote><br><br>

<dd>List:
<a href="http://www.antlr.org/mailman/listinfo/antlr-interest">
http://www.antlr.org/mailman/listinfo/antlr-interest</a><br>

<dd>Unsubscribe:
<a href="http://www.antlr.org/mailman/options/antlr-interest/your-email-address">
http://www.antlr.org/mailman/options/antlr-interest/your-email-address</a>
<br><br>

</dl></blockquote></body>
</html>