Welcome!<br><br>I am new to ANTLR and trying to create a simple mini-C interpreter. I wanted to interpret all the language actions in the parser action section. I&#39;m trying not to process the AST etc. I have managed to implement conditional statements, but still have one problem with loops. I&#39;m trying to rewind the input stream like in the following example (I know that the loop counter is static etc. - I wanted only to test rewinding input stream):<br>
<br>(for full grammar see: miniC.g)<br><br>scope CScope {<br>    String name;<br>    List symbols;<br>}<br><br>@members {<br>   int loopCounter = 5;<br>}<br><br>loop<br>@init {<br>    int start = -1;<br>}<br>@after {<br>    if (--loopCounter &gt; 0) {<br>
       System.out.println(&quot;rewinding: &quot; + loopCounter);<br>       input.rewind(start);<br>    }<br>}<br>     : &#39;for&#39; val=ID &#39;in&#39; set=ID<br>     {start = input.mark(); System.out.println(&quot;start: &quot; + start);}<br>
     block<br>     {if (--loopCounter &gt; 0) {System.out.println(&quot;rewinding: &quot; + loopCounter); input.rewind(start);}}<br>     ;<br><br>block<br>scope CScope;<br>@init {<br>    // initialize a scope for this code block<br>
    $CScope::symbols = new ArrayList();<br>    $CScope::name = &quot;level &quot;+$CScope.size();<br>}<br>}<br>    :   &#39;{&#39; block_content* &#39;}&#39; //decl* stat+ loop* cond* &#39;}&#39;<br>    ;<br><br>block_content <br>
    :    decl<br>    |    stat<br>    |    loop<br>    |    &#39;{&#39; block_content* &#39;}&#39;<br>    ;<br><br>decl:   &#39;int&#39; ID {if (evaluate) { $CScope::symbols.add($ID.text); System.out.println(&quot;Decalred variable: &quot; + $ID.text);}} &#39;;&#39;<br>
    ;<br><br>stat:   ID &#39;=&#39; INT &#39;;&#39;<br>        {<br>        if ( !isDefined($ID.text) ) {<br>            System.err.println(&quot;undefined variable level &quot;+<br>                $CScope.size()+&quot;: &quot;+$ID.text);<br>
        }<br>        }<br>
<br>Example file:<br>void g()<br>{<br>    for a in set<br>    {<br>        int x;<br>        x = 10;<br>    }<br><br>I&#39;ll be gratefull for any suggestions.<br><br>Regards,<br>Lukasz<br>