help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help constructing tiny expression grammar


From: Laurence Finston
Subject: Re: Help constructing tiny expression grammar
Date: Tue, 19 Oct 2004 14:17:36 +0200 (MEST)

On Tue, 19 Oct 2004, Randy W. Sims wrote:

> Laurence Finston wrote:
> > On Tue, 19 Oct 2004, Randy W. Sims wrote:

>
> Anyway, in my perl implementation I was thinking that macros would be
> parsed into syntax trees and stored in the symbol table. Then, anywhere
> the macro is invoked, a copy of the already parsed tree would just be
> inserted into the main expression tree.
>
> My second implementation is just an exercise for me to play with Bison
> and try to learn something new; to learn more about Bison its self and
> to learn more about parsing.
>
> I wrote a naive prototype at <http://thepierianspring.org/perl/expr.pl>.

Typically, macros can be used to make it possible to use
constructions that do not obey the syntax rules of the
compiler or interpreter which the expansions are passed
to.  Obviously, the expansions must obey these rules or they
will cause errors.  However, the compiler or interpreter
should be able to catch these errors.  Catching errors in
the macros themselves requires a different approach and can
be quite tricky, and may even be impossible.  This is one of
the main reasons Stroustrup recommends avoiding the use of
preprocessor macros in C++ programs.

For this reason, I think you might find it easier to
treat macro expansion and grammar parsing as separate
issues.  If you're interested in reading up on macro
processors, I recommend Knuth's _The TeXbook_ and the GNU M4
manual.  If you're really ambitious, you could try reading
Knuth's _TeX: The Program_.

Laurence




reply via email to

[Prev in Thread] Current Thread [Next in Thread]