[antlr-interest] Translating PASCAL (or C) into JAVA
Terence Parr
parrt at jguru.com
Thu Feb 14 10:27:41 PST 2002
Hi Piet,
7 years ago, Gary Funck built a translator from an ancient language from
the 60's similar to pascal to C if I remember. As the others have
stated, there are issues with equivalency of languages, but you're real
question is "can it be done." Emphatically yes. The ANTLR system was
specifically designed to aid language translators (I built the tree
translator component to help me build 10 pass f-77 to parallel fortran
translators back in the early 90s).
So, it's just a matter of learning the tricks. In most general terms it
can be summarized as follows:
1) Parse the old input file, constructing a tree representing the
structure of the input and constructing a symbol table (that may have to
be saved and used across parses/translations).
2) Manipulate the tree (intermediate form) in multiple passes using a
tree grammar, slowing morphing it towards your target language.
3) When you think that your intermediate form is very close to the
target language then you can do a simple walk of the tree spitting out
text again. Each action in the grammar does a small bit of the work and
you pray that the emergent behavior results in valid output text. ;)
I think i'll start a simple faq entry on this :)
Terence
--
Chief Scientist & Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list