[antlr-interest] 2. Attempt: ANTLR code generation target: modifying the C-Runtime I
Udo Weik
WeikEngOff at aol.com
Wed Nov 9 13:39:39 PST 2011
I would be really happy to get an answer...
Hello,
yep, I startet to modify the C-Runtime and have a first bunch of
questions. Be sure, more will follow - "Eeek, what a pain!"...
1. Header-file not created
I just added a new directory \Cmod to \org\antlr\codegen\templates
and copied the entire content of \C in that directory. Then I
renamed C.stg in Cmod.stg. The *Lexer.c/*Parser.c-files are created,
but no header (*.h)-files. Why?
2. <token> in <action>
I need the token of an rule in the <action>-section
/** How to execute an action (when not backtracking) */
execAction(action) ::= <<
<if(backtracking)>
<if(actions.(actionScope).synpredgate)>
if ( <actions.(actionScope).synpredgate> )
...
<ruleDescriptor.name> and <ruleName> are replaced (what is the
difference?) but <token> not. Why?
3. Blank lines
The C-Parser-file of my grammar consits of ~150.000 lines, ~20.000
lines are blank. As mentioned in another email from me, I can't debug
more than 65535 lines. The only solution is to reorder the (parser) rules.
But apart from that severe problem, I looked for a solution to get
a much more compact code. Some examples, section...
1. // Forward declare the locally static matching functions we have generated.
//
static
XYZParser_RULE_return
RULE (pXYZParser ctx);
3 lines - the result of
<rules:{r | static <headerReturnType(ruleDescriptor=r.ruleDescriptor)> <r.ruleDescriptor.name> (p<name> ctx<if(r.ruleDescriptor.parameterScope)>, <endif>
<r.ruleDescriptor.parameterScope:parameterScope()>);}; separator="\n">
How can I avoid 2 lines?
2. /* ==============================================
* Parsing rules
*/
...
static XYZParser_RULE_return
port_RULE(pXYZParser ctx)
2 lines - the result of
<rules; separator="\n\n">
How can I avoid 1 line?
4. I added a comment to section
ruleReturnValue() ::= <%
//! UW Test ruleReturnValue
<if(!ruleDescriptor.isSynPred)>
<if(ruleDescriptor.hasReturnValue)>
<if(ruleDescriptor.hasSingleReturnValue)>
<ruleDescriptor.singleValueReturnName>
<else>
retval
<endif>
<endif>
<endif>
%>
The result looks like
return //! UW Test ruleReturnValueretval;
1. The problem of the missing blank between "ruleReturnValue" and "retval"
can be solved by adding a blank after the comment "//! UW Test ruleReturnValue ".
2. But how can I add an additional line before the "retval"? I tried
<else>
retval
<endif>
without success.
Many thanks and greetings
Udo
More information about the antlr-interest
mailing list