Re: simple code translator - suggestions?

"Ira Baxter" <idbaxter@semdesigns.com>
23 Jun 2005 22:07:16 -0400

          From comp.compilers

Related articles
simple code translator - suggestions? makc.the.great@gmail.com (makc.the.great) (2005-06-02)
Re: simple code translator - suggestions? haberg@math.su.se (2005-06-02)
Re: simple code translator - suggestions? haberg@math.su.se (2005-06-04)
Re: simple code translator - suggestions? cfc@shell01.TheWorld.com (Chris F Clark) (2005-06-06)
Re: simple code translator - suggestions? haberg@math.su.se (2005-06-08)
Re: simple code translator - suggestions? bettini@dsi.unifi.it (Lorenzo Bettini) (2005-06-08)
Re: simple code translator - suggestions? codeworker@free.fr (=?iso-8859-1?q?C=E9dric_LEMAIRE?=) (2005-06-08)
Re: simple code translator - suggestions? idbaxter@semdesigns.com (Ira Baxter) (2005-06-23)
| List of all articles for this month |

From: "Ira Baxter" <idbaxter@semdesigns.com>
Newsgroups: comp.compilers
Date: 23 Jun 2005 22:07:16 -0400
Organization: http://extra.newsguy.com
References: 05-06-004
Keywords: C++, translator
Posted-Date: 23 Jun 2005 22:07:16 EDT

"makc.the.great" <makc.the.great@gmail.com> wrote in message
>Why can't I have my C++ code in the form:
>
> some-token
> script-to-cpp-mapping-declarations
> some-token-2-switch-2-cpp-code
> /* c++ code here */
> some-token-2-switch-2-script-code
> /* code written in simple dot-syntax script */
> some-token-2-switch-2-cpp-code
> /* c++ code here, if really necessary */
> some-token-2-switch-2-script-code
> /* more code written in simple dot-syntax script */
> ....
>
> And then this file gets translated in pure c++ with translator in
> question.


The DMS Software Reengineering Toolkit can do this pretty directly.
It can accept arbitrary language definitions using an analog to LEX
and YACC, so you can easily define your own domain-specific language
or "script". It already has a full, robust, C++ language definition,
including name/type resolution.


One can then write translation rules of the form of:
            "syntax-fragment1" -> "syntax-fragment2" IF <condition>,
where syntax-fragment1 is surface syntax with optional
pattern variables in any of DMS's language notations
(including C++), and likewise for syntax-fragment-2.
What these represent are tree-to-tree rewrites.
This enables one to code
translation rules from your scripting language to C++,
including conditional checks (e.g., name/type lookup).


One can group rules together to get rulesets to apply; often
cooperating rules can achieve what a single rule cannot easily do.
(Think of "simplify expression" as a set of rules). One can build
arbitrary metaprograms, triggered by arbitrary patterns, which apply
rulesets where the patterns match. This is our usual practice in
building interesting translators.


One can also write patterns which mix surface syntax fragments
arbitrarily (think of this as red trees mixed into blue trees), which
provides the "some-token-switch" idea above.


See http://www.semanticdesigns.com/Products/DMS/DMSToolkit.html.




--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.