Re: Bug in C target generation
Mike Lischke <
mike@...>
2012-04-20 07:48:40 GMT
Hey Jim,
It is a problem with the code generation templates for all the targets (well, Java and C at least), someone did post a fix for it on the list, but it has not been issued as any formal patch yet.
Definitely not for C# because this code was taken from a grammar that works well with C#.
privilege_level
: privs -> ^(PRIVILEGE_LEVEL $privs)
;
privs
: (MULT|IDENTIFIER) (DOT^ (MULT|IDENTIFIER))?
;
Though in fact I would avoid the PRIVILEGE_LEVEL node altogether unless its absence causes ambiguity issues in the tree grammar.
Hmm, in fact, what I want to achieve actually is a bit different. But I have some difficulties to formulate the grammar properly. These are the cases I want to handle:
id
id. (error: missing id or star)
id.*
id.id
id.id. (error: missing id or star)
id.id.*
id.id.id
I would be thankful for a hint to get my brain into the right direction. The best I could come up with is that I get a tree with an invalid node. Tho actually I would like the special node with the missing value (to ease their handling, e.g. for code completion). My current grammar is:
primary:
parExpression
| literal
| number
| { LA(2) != DOT }? identifier (INC | DEC)?
| identifier DOT qualified_field
;
number:
NUM
| HEX_NUM
| DIGITS
| DECIMAL_NUM
;
qualified_field:
MULT
| { LA(2) != DOT }? identifier
| identifier DOT qualified_field2
;
qualified_field2:
MULT
| { LA(2) != DOT }? identifier
;
Without the lookaheads the matching process stops for cases like "id." returning only the id without error.
<div>
<br><div>
<div>Hey Jim,</div>
<br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span"><div lang="EN-US" link="blue" vlink="purple"><div class="WordSection1"><div><span>It is a problem with the code generation templates for all the targets (well, Java and C at least), someone did post a fix for it on the list, but it has not been issued as any formal patch yet.</span></div></div></div></span></blockquote>
<div><br></div>Definitely not for C# because this code was taken from a grammar that works well with C#.</div>
<div>
<br><blockquote type="cite"><span class="Apple-style-span"><div lang="EN-US" link="blue" vlink="purple"><div class="WordSection1">
<p class="MsoNormal"><span> </span></p>
<div><span>privilege_level</span></div>
<div><span>: privs -> ^(PRIVILEGE_LEVEL $privs)</span></div>
<div><span>;</span></div>
<div><span>privs</span></div>
<div><span>: (MULT|IDENTIFIER) (DOT^ (MULT|IDENTIFIER))?</span></div>
<div><span>;</span></div>
<p class="MsoNormal"><span> </span></p>
<div><span>Though in fact I would avoid the PRIVILEGE_LEVEL node altogether unless its absence causes ambiguity issues in the tree grammar.</span></div>
</div></div></span></blockquote>
<br>
</div>
<div>Hmm, in fact, what I want to achieve actually is a bit different. But I have some difficulties to formulate the grammar properly. These are the cases I want to handle:</div>
<div><br></div>
<div>id</div>
<div>id.<span class="Apple-tab-span"> </span>(error: missing id or star)</div>
<div>id.*</div>
<div>id.id</div>
<div>id.id.<span class="Apple-tab-span"> </span>(error: missing id or star)</div>
<div>id.id.*</div>
<div>id.id.id</div>
<div><br></div>
<div>I would be thankful for a hint to get my brain into the right direction. The best I could come up with is that I get a tree with an invalid node. Tho actually I would like the special node with the missing value (to ease their handling, e.g. for code completion). My current grammar is:</div>
<div><br></div>
<div>
<div>primary:</div>
<div>
<span class="Apple-tab-span"> </span>parExpression</div>
<div>
<span class="Apple-tab-span"> </span>| literal</div>
<div>
<span class="Apple-tab-span"> </span>| number</div>
<div>
<span class="Apple-tab-span"> </span>| { LA(2) != DOT }? identifier (INC | DEC)?</div>
<div>
<span class="Apple-tab-span"> </span>| identifier DOT qualified_field</div>
<div>;</div>
<div><br></div>
<div>number:</div>
<div>
<span class="Apple-tab-span"> </span>NUM</div>
<div>
<span class="Apple-tab-span"> </span>| HEX_NUM</div>
<div>
<span class="Apple-tab-span"> </span>| DIGITS</div>
<div>
<span class="Apple-tab-span"> </span>| DECIMAL_NUM</div>
<div>;</div>
<div><br></div>
<div>qualified_field:</div>
<div>
<span class="Apple-tab-span"> </span>MULT</div>
<div>
<span class="Apple-tab-span"> </span>| { LA(2) != DOT }? identifier</div>
<div>
<span class="Apple-tab-span"> </span>| identifier DOT qualified_field2</div>
<div>;</div>
<div><br></div>
<div>qualified_field2:</div>
<div>
<span class="Apple-tab-span"> </span>MULT</div>
<div>
<span class="Apple-tab-span"> </span>| { LA(2) != DOT }? identifier</div>
<div>;</div>
<div><br></div>
</div>Without the lookaheads the matching process stops for cases like "id." returning only the id without error.<div>
<br><div apple-content-edited="true">
Mike<br>-- <br><a href="http://www.soft-gems.net">www.soft-gems.net</a><br>
</div>
<br>
</div>
</div>