[antlr-interest] C Parser generated with antlr v3.0b not working

Jim Idle jimi at intersystems.com
Mon Dec 11 09:58:24 PST 2006


Renjith,
 
Unless you are already familiar with ANTLR 3 and ANTLR stuff, then you might be want to wait before workgin with the C output. However:
 
The warning:
 
error(10):  internal error: group C does not satisfy interface ANTLRCore: missing templates [lexerRulePropertyRef_text, lexerRulePropertyRef_type, lexerRulePropertyRef_line, lexerRulePropertyRef_pos, lexerRulePropertyRef_index, lexerRulePropertyRef_channel]
 
Can be ignored (though it is now fixed pending one addition from Ter so you can reference $start) – it does not affect the code that is output.
 
The rest of the errors are nothing to do with the C output but appear to be errors or ambiguities in the grammar itself, with the possibl exception of:
 
error(10):  internal error: Class java.lang.String has no such attribute: name in template context [outputFile parser genericParser(...) rule ruleInitializations ruleInitializations anonymous <invoke scopeTop arg context>] : java.lang.NoSuchFieldException: name
 
Which I will take a look at if you send me your grammar (or post it here if small enough). If this is referencing a global scope, then that might be the problem. However, I wonder if we have changed the scope of the name attribute, which the C codegen relies on as the global scope code gen also gives this error. I don’t have it in my own grammars, which are pretty extensive, but then, I am probably not using absolutely everything that can be used.
 
Why don’t you first put this grammar through ANTLRWorks, without the C output option and see if you can make it work there. Until you absolutely have to have code in actions and so on, this is generally a good idea anyway as you can debug the actual parsing of the grammar etc.
 
There should be no need to modify the output code to do tree parsing etc, that is what the tree rewriting actions and the tree parser grammars are for and they already work in the C output. 
 
Jim
 
 
 
 
   _____  

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Renjith Varma
Sent: Sunday, December 10, 2006 12:18 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] C Parser generated with antlr v3.0b not working
 
Hi,

I am a newbie to antlr. I downloaded antlr3.0b as well as the ANSI C grammar from the antlr home page. I tried to generate the parser in  C language by giving 
language=C; in options. It gave a lot of errors (a part of which I am attaching below) but created CParser__.g, CParserLexer.c, CParserLexer.h, CParserParser.c, CParserParser.h and CParser.tokens.
Now i tried to compile all these .c files into one object file and it is showing lots of errors. Am i doing something wrong? Please help
Also, my idea is to modify the parser files in C to do tree walking. Is this already available? If so could you help me in finding it?
The errors during C code generation are:

[root at localhost ansic]# java org.antlr.Tool CParser.g
ANTLR Parser Generator  Version 3.0b5 (November 15, 2006)  1989-2006
error(10):  internal error: group C does not satisfy interface ANTLRCore: missing templates [lexerRulePropertyRef_text, lexerRulePropertyRef_type, lexerRulePropertyRef_line, lexerRulePropertyRef_pos, lexerRulePropertyRef_index, lexerRulePropertyRef_channel]

warning(200): CParser.g:457:38: Decision can match input such as "'else'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
error(10):  internal error: Class java.lang.String has no such attribute: name in template context [outputFile parser genericParser(...) rule ruleInitializations ruleInitializations anonymous <invoke scopeTop arg context>] : java.lang.NoSuchFieldException: name
java.lang.Class.getField(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
org.antlr.stringtemplate.language.ASTExpr.rawGetObjectProperty(org.antlr.stringtemplate.StringTemplate, java.lang.Object, java.lang.String) (Unknown Source)
org.antlr.stringtemplate.language.ASTExpr.getObjectProperty(org.antlr.stringtemplate.StringTemplate, java.lang.Object, java.lang.String) (Unknown Source)
org.antlr.stringtemplate.language.ActionEvaluator.attribute(antlr.collections.AST) (Unknown Source)
org.antlr.stringtemplate.language.ActionEvaluator.expr(antlr.collections.AST) (Unknown Source)
org.antlr.stringtemplate.language.ActionEvaluator.argumentAssignment(antlr.collections.AST, org.antlr.stringtemplate.StringTemplate, java.util.Map) (Unknown Source)


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.15/581 - Release Date: 12/9/2006 3:41 PM

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.15/581 - Release Date: 12/9/2006 3:41 PM
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20061211/797eee7b/attachment.html 


More information about the antlr-interest mailing list