Writing compilers

jeremy at itassist.net.au jeremy at itassist.net.au
Tue Nov 20 00:58:49 EST 2001


Just to make a change from talking about Telstra, here's a chance for
one of you comp sci guys to show off a bit...

I've been having a look at implementing compilers and so I've been
trying to educate myself by reading lecture notes from other
universities (posted on the web).

Before I started however I wrote half a cruddy parser using Perl's
Parse::RecDescent.  Recently touched it up to the point where it could
be useful with a bit more work.  But at the moment I can't do
precendence at all.  My current fudge is to surround everything with
brackets and then push and pop as necessary to allow the recursive part
of the parser to ignore the bits of the expression outside the brackets.

e.g. 

x = 1 + ( 2 * 3 )...

becomes
set I1, 1
push I1
set I1, 2
mult I1, 3
pop I2
add I1, I2
...

In short, I don't get this 'shift and reduce' thing at all.  Could
someone explain if I have to use it if I have a recursive descent parser
(the notes I came across implied that I do, but I think I can do it
using look-ahead).  If I do have to use it, what is it?  I've seen a run
through of it, but it just didn't click.  I get the 'shift' bit - keep
pushing operations(or should that be states?) onto a stack, but what's
the go with taking them back off?  And how does it magically turn into a
useful parse tree?


While I'm at it, what is a handle plus sentential form?  Is this like
subject+predicate in english grammar?


-- 
I/O, I/O,
It's off to disk I go,
A bit or byte to read or write,
I/O, I/O, I/O...

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
Url : http://lists.samba.org/archive/linux/attachments/20011120/4f946097/attachment.bin


More information about the linux mailing list