[antlr-interest] code gen can do both java source and bytecodes, btw

Terence Parr parrt at cs.usfca.edu
Fri Oct 22 09:04:00 PDT 2004


Howdy folks,

One thing I should make clear.  My design goals for the antlr code 
generator are anything but modest...  I want retargeting by changing a 
text file not code, optimizing the output by changing templates, etc... 
  These goals are starting to be validated.  Ric built the C code 
generator in 2 days and I built the bytecode output for the DFA 
generator yesterday (took me a while to get the infrastructure like the 
assembler together though <wink>).

The beauty is that I have *added* code gen capability not *changed* 
it...the "generate pure java source DFA" templates are still there.  
Just change a pointer and out comes Java in your generated parser.java 
file rather than bytecodes in another file.

These templates are really amazing.  The key insight to making 
templates so retargetable is avoiding code in the templates.  
StringTemplate is essentially the only widely-used (and powerful 
enough) engine that strictly enforces this rule.  Consequently, I know 
that any template I write can be retargeted.  That's pretty cool: 
bytecodes, java, and C all without changing the code generator (except 
for sending in a few more data attributes to the templates that C and 
bytecodes needed).

Ter
PS	for speed freaks, you can cut/paste (or use template 
inheritance<evil grin>) to make a variant of the bytecode generator 
that inlines all of the LA() and consume() method calls.  Given a 
buffered char or token stream, this should amount to buffer[i] and i++. 
  Can you say SPEEEED?  Each person can tweak for their own needs or 
not--all without changing the code!

PPS	 As I have the generator doing bytecodes now, I can estimate the 
number of max states in a single DFA before Java blocks me again.  it's 
somewhere near 2000, which I hope is good enough.  I looked at the 
oracle 7 grammar from antlr.org and it shows only like 80 keywords 
(although now that I say that, it sounds like a big language <wink>).  
Anyway, at a max of 10 states per keyword (it would be much less), you 
would still reach only 800 states for all keywords.  I think we'll be 
ok.

tallyho!





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list