Note that there are some explanatory texts on larger screens.

plurals
  1. POStripping actions from ANTLR grammar changes its parsing algorithm
    primarykey
    data
    text
    <p>I have a grammar <code>Foo.xtext</code> (too complex to include it here). Xtext generates <code>InternalFoo.g</code> from it. <a href="http://eclipse.org/Xtext/documentation/indigo/new_and_noteworthy.php" rel="nofollow">After some tweaking</a> it also generates <code>DebugInternalFoo.g</code> which claims to be the same thing without actions. Now, I strip off actions with ANTLR directly</p> <pre><code>java -cp antlr-3.4.jar org.antlr.tool.Strip Internal.g &gt; Stripped.g </code></pre> <p>I'd expect the three grammars to behave the same way when I check them. But here is what I experienced</p> <ul> <li><code>InternalFoo.g</code> - error, rule assignment has non-LL(*) decision</li> <li><code>DebugInternalFoo.g</code> - no problem, parses fine</li> <li><code>Stripped.g</code> - warnings at rule assignment, decision can match using multiple alternatives. It fails to parse properly.</li> </ul> <p>Is it possible that a grammar parses a text differently with or without actions? Or is it a bug in any of the action-remover tools? (The rule in question has syntactic predicates, and without them, it would really have a non-LL(*) decision.)</p> <p>UPDATE:</p> <p>I partly found what caused the problem. The rule in question was like this</p> <pre><code>trickyRule: ({ some complex action}) (expression '=')=&gt;... </code></pre> <p>Stripping with Antlr removed the action, but left an empty group there:</p> <pre><code>// Stripped.g trickyRule: () (expression '=')=&gt;... </code></pre> <p>The generation of the debug grammar removes both the action, and the now empty group around it:</p> <pre><code>// DebugInternalFoo.g trickyRule: (expression '=')=&gt;... </code></pre> <p>So the lesson learned is: an empty group before a syntactic predicate is not the same as nothing at all.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload