|Query: Writing a translator for an extended version of C++ email@example.com (1994-04-13)|
|RE: Query: Writing a translator for an extended version of C++ firstname.lastname@example.org (1994-04-27)|
|From:||email@example.com (Raju Pandey)|
|Keywords:||C++, parse, question, comment|
|Date:||Wed, 13 Apr 1994 20:43:05 GMT|
I am working on including a set of concurrency and synchronization
mechanisms to C++. I am looking at techniques for implementing a
translator that will transform the extended C++ code to C++. My focus at
this point is more on verifying the suitability of the language
constructs, and less on their efficient implementation. Hence, I am
looking for mechanisms that will allow me to build this translator quickly
(by utilizing existing tools, and source code).
I have looked at the compiler FAQ as well as the list of compiler
tools that are available. I could think of the following ways of
implementing the translator:
o Extend an existing C++ grammar (available from many sources), use
parser generators (such as yacc, yacc++, pccts, and others) to
parse the extended source file, and manipulate the parse tree to
generate suitable C++ code.
o Use "TXL" to create a parse tree from the extended grammar of C++,
transform the parse tree into one that includes only C++ code, and
let "txl" traverse the tree to spit out the resulting C++ code.
o Extend gnu g++ compiler by embedding proper code generation
capabilities in the compiler.
I am sure that many readers on the net have defined (similar) extensions
to programming languages, and have built similar translators. The
questions that I have are:
o What do people think about the above mechanisms? Any
positive/negative experiences with either of the above?
o Are there other techniques that I have overlooked?
o Are there translators available that I can look at and modify
appropriately to suit my purposes?
I apologize if this has been discussed earlier. I will post a summary
of all the replies (and my experiences) I receive.
[Parsing C++ is a pain in the neck because it is so ambiguous. I'd suggest
the quick and dirty approach: don't try to parse C++, but rather surround
your extensions with easy to recognize syntax delimiters and pass through
the stuff outside the delimiters. Later you might want to try a better
integrated version of the language, in which case you'd have to bite the
bullet and be prepared to parse the whole thing. -John]
Return to the
Search the comp.compilers archives again.