Message from discussion
Macro
Received: by 10.66.86.130 with SMTP id p2mr3025273paz.22.1351474685508;
Sun, 28 Oct 2012 18:38:05 -0700 (PDT)
X-BeenThere: treetop-dev@googlegroups.com
Received: by 10.68.141.79 with SMTP id rm15ls22823184pbb.1.gmail; Sun, 28 Oct
2012 18:38:05 -0700 (PDT)
Received: by 10.68.212.72 with SMTP id ni8mr8644965pbc.14.1351474685220;
Sun, 28 Oct 2012 18:38:05 -0700 (PDT)
Date: Sun, 28 Oct 2012 18:38:04 -0700 (PDT)
From: Joel Jauregui <joel.jaure...@gmail.com>
To: treetop-dev@googlegroups.com
Cc: Joel Jauregui <joel.jaure...@gmail.com>
Message-Id: <4b2a6816-bcc6-4fac-ba2e-5ca1bffaf54e@googlegroups.com>
In-Reply-To: <508DDBC8.4040206@it.aoyama.ac.jp>
References: <e850fb39-73da-42b4-9a83-6fd85e6e0c50@googlegroups.com>
<508DDBC8.4040206@it.aoyama.ac.jp>
Subject: Re: Macro
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_455_28287401.1351474684959"
------=_Part_455_28287401.1351474684959
Content-Type: multipart/alternative;
boundary="----=_Part_456_27162292.1351474684959"
------=_Part_456_27162292.1351474684959
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Yeah I ended up just using a ruby regex to do the preprocessing. This is=20
for a simple assembler so its not really adding full blown C macros, its=20
just to generate some synthetic instructions. Thanks for the advice anyway!
On Sunday, October 28, 2012 6:28:42 PM UTC-7, Martin D=C3=BCrst wrote:
>
> On 2012/10/28 19:59, Joel Jauregui wrote:=20
> > I am trying to figure out a way in which I can make a given rule expand=
=20
> > into code that could be parsed by other rules, so essentially a simple=
=20
> > macro. Something along the lines of the C preprocessor where it is just=
=20
> > doing a simple lexical replacement which is then parsed by the language=
=20
> > grammar. Is there an easy way to do this, or should I use a different=
=20
> tool=20
> > besides treetop to do the preprocessing?=20
>
> First, macros such as in C are considered a bad idea these days. You may=
=20
> start out with a simple use case, and for that, they are quite simple=20
> and straightforward, but then you add more use cases, and it gets more=20
> and more complex. As far as I know, newer languages all avoid macros.=20
> Most of what is done with macros in C can be done in the language in=20
> C++, for example.=20
>
> Second, if you really decide to have some macro language, then this is a=
=20
> separate step of (pre)processing. You may be able to use treetop for=20
> both steps, or may want to use it only for one or the other step. For=20
> very simple macros, you may be able to get away with a script based on=20
> pure ruby and regular expressions, but that won't last long. Using a=20
> different parsing formalism for preprocessing and for the actual=20
> processing may help in some cases, but usually, it's easier for you as=20
> the programmer to use the same formalism twice.=20
>
> Regards, Martin.=20
>
------=_Part_456_27162292.1351474684959
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Yeah I ended up just using a ruby regex to do the preprocessing. This is fo=
r a simple assembler so its not really adding full blown C macros, its just=
to generate some synthetic instructions. Thanks for the advice anyway!<br>=
<br>On Sunday, October 28, 2012 6:28:42 PM UTC-7, Martin D=C3=BCrst wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;">On 2012/10/28 19:59, Joel Jaure=
gui wrote:
<br>> I am trying to figure out a way in which I can make a given rule e=
xpand
<br>> into code that could be parsed by other rules, so essentially a si=
mple
<br>> macro. Something along the lines of the C preprocessor where it is=
just
<br>> doing a simple lexical replacement which is then parsed by the lan=
guage
<br>> grammar. Is there an easy way to do this, or should I use a differ=
ent tool
<br>> besides treetop to do the preprocessing?
<br>
<br>First, macros such as in C are considered a bad idea these days. You ma=
y=20
<br>start out with a simple use case, and for that, they are quite simple=
=20
<br>and straightforward, but then you add more use cases, and it gets more=
=20
<br>and more complex. As far as I know, newer languages all avoid macros.=
=20
<br>Most of what is done with macros in C can be done in the language in=20
<br>C++, for example.
<br>
<br>Second, if you really decide to have some macro language, then this is =
a=20
<br>separate step of (pre)processing. You may be able to use treetop for=20
<br>both steps, or may want to use it only for one or the other step. For=
=20
<br>very simple macros, you may be able to get away with a script based on=
=20
<br>pure ruby and regular expressions, but that won't last long. Using a=20
<br>different parsing formalism for preprocessing and for the actual=20
<br>processing may help in some cases, but usually, it's easier for you as=
=20
<br>the programmer to use the same formalism twice.
<br>
<br>Regards, Martin.
<br></blockquote>
------=_Part_456_27162292.1351474684959--
------=_Part_455_28287401.1351474684959--