[antlr-interest] Sparql Grammar & Huge C Files

Todor Dimitrov todor.dimitrov at stud.uni-due.de
Sat Aug 20 07:39:07 PDT 2011


Dear *,

generating the C lexer and parser for the Sparql grammar using the options below produces huge files:

options {
	language = C;
	output = AST;
	ASTLabelType = pANTLR3_BASE_TREE;
}

2.4K Sparql.tokens
85M SparqlLexer.c <---
30K SparqlLexer.h
1.5M SparqlParser.c <---
69K SparqlParser.h

In addition, the files cannot be compiled as it seems that the generators have not been updated to reflect the API changes in the latest C runtime (or maybe it is the other way round :)). In particular, I see errors like these:

SparqlLexer.c:1214276:48: error: member reference type 'pANTLR3_STRING' (aka 'struct ANTLR3_STRING_struct *') is a
      pointer; maybe you meant to use '->'?
                     setText(LEXER->getText(LEXER).substring(1, LEXER->getText(LEXER).length()-1)); 
                             ~~~~~~~~~~~~~~~~~~~~~^
                                                  ->
SparqlLexer.c:1214276:49: error: no member named 'substring' in 'struct ANTLR3_STRING_struct'; did you mean 'subString'?
                     setText(LEXER->getText(LEXER).substring(1, LEXER->getText(LEXER).length()-1)); 
                                                   ^~~~~~~~~
                                                   subString
./antlr3string.h:179:8: note: 'subString' declared here
                                        (*subString)    (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 ...
                                          ^
SparqlLexer.c:1214276:83: error: member reference type 'pANTLR3_STRING' (aka 'struct ANTLR3_STRING_struct *') is a
      pointer; maybe you meant to use '->'?
                     setText(LEXER->getText(LEXER).substring(1, LEXER->getText(LEXER).length()-1)); 
                                                                ~~~~~~~~~~~~~~~~~~~~~^
                                                                                     ->
SparqlLexer.c:1214276:84: error: no member named 'length' in 'struct ANTLR3_STRING_struct'
                     setText(LEXER->getText(LEXER).substring(1, LEXER->getText(LEXER).length()-1)); 


I'm using antlr 3.4, but I have also tested this with antlr 3.3. Generating the Java lexer and parser works as expected and the files are much smaller:

2.4K Sparql.tokens
582K SparqlLexer.java
876K SparqlParser.java

Any suggestions and help are highly appreciated.

Thanks in advance,

Todor




More information about the antlr-interest mailing list