<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Shannon -jj Behrens wrote:
<blockquote
 cite="midc41f67b90605081633p617607f9s24cde54875467429@mail.gmail.com"
 type="cite">On 5/7/06, Ken Seehart <a class="moz-txt-link-rfc2396E" href="mailto:ken@seehart.com">&lt;ken@seehart.com&gt;</a> wrote:
  <br>
  <blockquote type="cite">&nbsp;Never mind, this is really trivial.&nbsp; Any C++
code that is outside my
    <br>
"cellclass" block is passed on unmodified. The only recursion I have to
deal
    <br>
with in my grammar is a C++ function body.&nbsp; And since I don't actually
need
    <br>
to process the function body, I just need to recursively scan for a
pair of
    <br>
matching braces (not rocket science).&nbsp; Everything else is regular
    <br>
expressions.&nbsp; I definitely don't need an LALR parser for this :-)
    <br>
    <br>
&nbsp;So I don't have any further questions.
    <br>
    <br>
&nbsp;Thanks Dennis and Dennis for your comments.
    <br>
    <br>
&nbsp;- Ken
    <br>
    <br>
&nbsp;Ken Seehart wrote:
    <br>
    <br>
&nbsp;I want to implement a simple language translator (a superset of C++),
but I
    <br>
haven't done anything of this kind since college (a couple decades
ago).&nbsp; I
    <br>
would like to use python tools as much as possible.
    <br>
    <br>
&nbsp;NICL code -&gt; [C++ preprocessor (gcc)] -&gt; [NICL translator] -&gt;
[C++ compiler
    <br>
(gcc)] -&gt; object code
    <br>
    <br>
&nbsp;The translator needs to be able to parse special non-c++ syntax to
generate
    <br>
c++, and leave other code intact.
    <br>
    <br>
&nbsp;More documentation on my project here:
    <br>
    <br>
<a class="moz-txt-link-freetext" href="http://www.seehart.com/neuralintegrator.com/documentation/ni_book/defining_cell_types.st">http://www.seehart.com/neuralintegrator.com/documentation/ni_book/defining_cell_types.st</a>
    <br>
    <br>
&nbsp;I could almost get by with just a python script using regular
expressions
    <br>
(my grammar is simple enough), but I need to know a certain amount of
    <br>
contextual information. E.g., if I am parsing "cellclass mycell { ...
}",
    <br>
the contents between the braces must be processed accordingly.&nbsp; This
means I
    <br>
have to know when I reach the closing brace (which I can't do with
regular
    <br>
expressions).&nbsp; However, I'm sure I could do a prototype this way, using
the
    <br>
assumption that the a closing brace on a class matches "^};", but that
would
    <br>
be just plain sloppy :-)
    <br>
    <br>
&nbsp;So I think one way or another I'm stuck with implementing an LALR
parser.
    <br>
    <br>
&nbsp;I'm wondering if there is anyone in this community with experience
doing
    <br>
this kind of thing.
    <br>
    <br>
&nbsp;- Ken Seehart
    <br>
  </blockquote>
  <br>
I once interviewed at a company that had implemented a mini-language
  <br>
on top of C++ using templates and operator overloading.&nbsp; Apparently,
  <br>
they had even overloaded the comma operator.
  <br>
  <br>
/me shudders
  <br>
  <br>
-jj
  <br>
  <br>
</blockquote>
Yikes.&nbsp; Template abuse is pretty scary stuff.&nbsp; Here's a scary book on
the subject,<br>
for those who are interested. : <a
 href="http://boost-consulting.com/mplbook/">http://boost-consulting.com/mplbook/</a>
<br>
<br>
Kind of reminds me of people who get way into John Conways "Life", and
build<br>
computers and things out of glider guns.<br>
<br>
Perhaps a more elegant way to do metaprogramming would be to kind of
squish<br>
python into the preprocessor phase.<br>
<br>
I recommend making sure you actually have a good reason to do this kind
of thing.<br>
Usually more straightforward techniques suffice (e.g. write your
program in python<br>
and use extending and embedding).&nbsp; But good reasons do exist.<br>
<br>
Anyway, I have successfully completed my NICL compiler.&nbsp; It really
works!<br>
<br>
<b><small>NICL code -&gt; [preprocessor (cpp)] -&gt; [NICL translator]
-&gt; [compiler
(gcc)] -&gt; object code</small></b><br>
<br>
If there is interest, I'd be willing to give a short talk on the topic
some time:<br>
&nbsp; "How to extend the C++ grammar using Python"<br>
<br>
The documentation on my language is here: <br>
<br>
&nbsp;&nbsp;&nbsp; <a
 href="http://www.neuralintegrator.com/documentation/ni_book/nicl.st">http://www.neuralintegrator.com/documentation/ni_book/nicl.st</a><br>
<br>
- Ken Seehart<br>
<br>
</body>
</html>