Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, you are using the wrong tool for the job (assuming you are also looking for nested scopes)</p> <p>Note that regex (in the traditional form of regex) stands for Regular Expression - which is a way to describe a <a href="http://en.wikipedia.org/wiki/Regular_language" rel="nofollow">Regular Language</a>.</p> <p>However, the language <code>L = { all words with legal scopings }</code> is irregular - and thus cannot be identified by regex.</p> <p>This langauge is actually <a href="http://en.wikipedia.org/wiki/Context-free_language" rel="nofollow">Conext Free Langauge</a>, and can be represented by a <a href="http://en.wikipedia.org/wiki/Context-free_grammar" rel="nofollow">Context Free Grammer</a>.</p> <p>For parsing: <br>For relatively simple langauges (scoping is among them) - a deterministic <a href="http://en.wikipedia.org/wiki/Pushdown_automaton" rel="nofollow">push-down automaton</a> is enough to verify them.</p> <p>Some languages require non deterministic push down automaton - which is not very efficiently created, but there is a <a href="http://en.wikipedia.org/wiki/CYK_algorithm" rel="nofollow">dynamic programming algorithm</a> to parse them as well.</p> <hr> <p>As a side note, there are some tools such as <a href="http://www.google.co.il/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;ved=0CDYQFjAA&amp;url=http://javacc.java.net/&amp;ei=Yq1iUubUGqqk4gSY0IDABg&amp;usg=AFQjCNFvozNJ_Rxewupu63AzhtcPSHJu5A&amp;sig2=HCqX8AkfU3h4mGPIXA5adQ&amp;bvm=bv.54934254,d.bGE" rel="nofollow">JavaCC</a> that you can use to parse (and generate code/output) - have a look on them, but if you are simply looking for the scoping issue - it is probably an overkill.</p> <hr> <p>Edit - pseudo code:</p> <pre><code>curr &lt;- 0 count &lt;- 0 //integer imitates the stack for this simple usage l &lt;- string.length() while (curr &lt; l): if string.charAt(curr) == '{': count++; else if string.charAt(curr) == '}': if curr &lt;= 0: return ERROR; count--; curr++; if count != 0: return ERROR; return SUCCESS; </code></pre> <p>Note that in here we can use an integer to imitate the stack, in here an increase is basically a push() and a decrease is a pop().</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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