<!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"><ken@seehart.com></a> wrote:
<br>
<blockquote type="cite"> Never mind, this is really trivial. 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. 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). Everything else is regular
<br>
expressions. I definitely don't need an LALR parser for this :-)
<br>
<br>
So I don't have any further questions.
<br>
<br>
Thanks Dennis and Dennis for your comments.
<br>
<br>
- Ken
<br>
<br>
Ken Seehart wrote:
<br>
<br>
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). I
<br>
would like to use python tools as much as possible.
<br>
<br>
NICL code -> [C++ preprocessor (gcc)] -> [NICL translator] ->
[C++ compiler
<br>
(gcc)] -> object code
<br>
<br>
The translator needs to be able to parse special non-c++ syntax to
generate
<br>
c++, and leave other code intact.
<br>
<br>
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>
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. This
means I
<br>
have to know when I reach the closing brace (which I can't do with
regular
<br>
expressions). 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>
So I think one way or another I'm stuck with implementing an LALR
parser.
<br>
<br>
I'm wondering if there is anyone in this community with experience
doing
<br>
this kind of thing.
<br>
<br>
- 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. Apparently,
<br>
they had even overloaded the comma operator.
<br>
<br>
/me shudders
<br>
<br>
-jj
<br>
<br>
</blockquote>
Yikes. Template abuse is pretty scary stuff. 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). But good reasons do exist.<br>
<br>
Anyway, I have successfully completed my NICL compiler. It really
works!<br>
<br>
<b><small>NICL code -> [preprocessor (cpp)] -> [NICL translator]
-> [compiler
(gcc)] -> 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>
"How to extend the C++ grammar using Python"<br>
<br>
The documentation on my language is here: <br>
<br>
<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>