Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The following ANTLR grammar:</p> <pre><code>parse : exp EOF ; exp : add_exp ; add_exp : mul_exp ('+' mul_exp)* ; mul_exp : atom ('*' atom)* ; atom : Number | '(' exp ')' ; Number : 'a'..'z' ; </code></pre> <p>parses the input <code>a + b * c + d + e</code> as:</p> <p><a href="http://img266.imageshack.us/img266/7099/17212574.png" rel="nofollow noreferrer">alt text http://img266.imageshack.us/img266/7099/17212574.png</a></p> <p>As you can see, the <code>mul_exp</code> is the furthest away in the tree and (using an appropriate "walk" through your tree) will be evaluated first.</p> <p>and the input <code>a + b * (c + d) + e</code> is parsed as:</p> <p><a href="http://img688.imageshack.us/img688/2207/89332200.png" rel="nofollow noreferrer">alt text http://img688.imageshack.us/img688/2207/89332200.png</a></p> <p>The images were generated with <a href="http://www.antlr.org/works/index.html" rel="nofollow noreferrer">ANTLRWorks</a>. </p> <p><strong>EDIT:</strong></p> <p>A tool like <a href="http://www.antlr.org/works/index.html" rel="nofollow noreferrer">ANTLRWorks</a> makes debugging a grammar a breeze! For example, if I click on the <code>atom</code> rule in the grammar above, the following is automatically generated and displayed at the bottom of the screen:</p> <p><a href="http://img340.imageshack.us/img340/6793/53395907.png" rel="nofollow noreferrer">alt text http://img340.imageshack.us/img340/6793/53395907.png</a></p> <p>Of course, that rule isn't complex at all, but when you do get to work with more complex rules, it's pretty darn easy to visualize them like that.</p> <p>HTH.</p>
 

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