[antlr-interest] using ANTLR for IDL compiling/code generation

Tim Black timblack0 at gmail.com
Tue Jun 23 14:11:04 PDT 2009


I am investigating customizable IDL compilers / code-generation tools for an
embedded C++ application. What I need is very close to the many available
CORBA IDL compilers. These typically have customizable back-ends which allow
you to do whatever you want with the generated Abstract Syntax Tree (AST),
but you are constrained to using their front-ends (typically implemented
with lex/flex/yacc/bison) which are hard-coded to work with CORBA IDL
specification. (The front-end can be modified, but that's too big a
project.) This means that I am somewhat limited in terms of what I can
represent in the IDL files. (Using CORBA IDL, I can extend the IDL by adding
new constructs into the comments, which can be preserved and passed to the
back-end.)

ANTLR seems capable of helping me create a CORBA-like, but custom, IDL
compiler/code generator. My understanding is that I would define the grammar
for my IDL (using ANTLRWorks), and from this ANTLR generates an
implementation for lexing and parsing an IDL file. I just did this for the
SimpleCalc.g tutorial and generated the lexer/parser code in Python, my
preferred language. It is not obvious to me how to use the resulting
SimpleCalcLexer and SimpleCalcParser classes to create my code generation
application. Is there an example of this somewhere?

Also, I found the ANTLR grammars for CORBA IDL (
http://www.antlr.org/grammar/1072891676218/idl.g and
http://www.antlr.org/grammar/1203688376660/Idl.g) and tried running ANTLR on
them and got these errors:

Running ANTLR on grammar from
http://www.antlr.org/grammar/1072891676218/idl.g:

~tblack\My Documents\Serialization\antlr-3.1.3\grammars\CORBA_IDL_AST>java
org.antlr.Tool idl_ast.g
error(10):  internal error:  : java.lang.Error: Error parsing idl_ast.g:
'header' not expected 'grammar'
org.antlr.tool.GrammarSpelunker.match(GrammarSpelunker.java:74)
org.antlr.tool.GrammarSpelunker.grammarHeader(GrammarSpelunker.java:112)
org.antlr.tool.GrammarSpelunker.parse(GrammarSpelunker.java:84)
org.antlr.Tool.sortGrammarFiles(Tool.java:525)
org.antlr.Tool.process(Tool.java:383)
org.antlr.Tool.main(Tool.java:91)
error(100): idl_ast.g:1:1: syntax error: antlr: idl_ast.g:1:1: unexpected
token: header
error(100):  syntax error: invalid char literal: '\3'
error(100):  syntax error: invalid char literal: '\377'
warning(149): idl_ast.g:0:0: rewrite syntax or operator with no output
option; setting output=AST
error(150):  grammar file idl_ast.g has no rules
error(100): idl_ast.g:0:0: syntax error: assign.types: <AST>:0:0: unexpected
end of subtree
error(100): idl_ast.g:0:0: syntax error: define: <AST>:0:0: unexpected end
of subtree

Running ANTLR on grammar from
http://www.antlr.org/grammar/1203688376660/Idl.g:

~tblack\My Documents\Serialization\antlr-3.1.3\grammars\CORBA_IDL>java
org.antlr.Tool Idl.g
warning(200): Idl.g:717:2: Decision can match input such as "'0'..'9'{'E',
'e'}{'+', '-'}'0'..'9'{'D', 'F', 'd', 'f'}" using multiple alternatives: 3,
4
As a result, alternative(s) 4 were disabled for that input
error(208): Idl.g:723:1: The following token definitions can never be
matched because prior tokens match the same input: FIXED_PT_LITERAL

This one still generated the Lexer/Parser source files, despite the error
(is this correct?)

Terrence's C grammar (http://www.antlr.org/grammar/1153358328744/C.g)
compiled fine.

Any ideas what's wrong with these grammars? Can someone point me in the
right direction?

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090623/5212ce24/attachment.html 


More information about the antlr-interest mailing list