Re: Anyone know this book?

dwight@pentasoft.com (Dwight VandenBerghe)
6 Mar 1998 16:52:37 -0500

          From comp.compilers

Related articles
Anyone know this book? fpeelo@portablesolutions.com (Frank Peelo) (1998-03-03)
Re: Anyone know this book? dwight@pentasoft.com (1998-03-06)
Re: Anyone know this book? will@ccs.neu.edu (William D Clinger) (1998-03-13)
| List of all articles for this month |
From: dwight@pentasoft.com (Dwight VandenBerghe)
Newsgroups: comp.compilers
Date: 6 Mar 1998 16:52:37 -0500
Organization: All USENET -- http://www.Supernews.com
References: 98-03-019
Keywords: books, parse

On 3 Mar 1998 10:54:21 -0500, "Frank Peelo"
<fpeelo@portablesolutions.com> wrote:
>For example, in one section he discusses generating a "table" to
>represent a grammar. A construct like
> p = t { '+' | '-' t }.
>gets represented as
> +-----------------+
> v |
> p --> [ ] --> [ '+' ] --|
> ----/ | |
> / [ '-' ] --+
> t |
> [ EMP ]
>
>(Does that make sense? That's one reason I'd like to write to someone
>who has the book - so as not to have to copy the diagrams!)


The production was probably meant to be read more like


p ::= t { ('+' | '-') t }


>but what I don't understand is: why the pseudo-terminal symbol "EMP"
>(indicating a lack of an alternative terminal symbol) is needed.


I think the idea is that you need to know, if you are processing non-
terminal p and you have just parsed a valid t, what to do upon seeing
the next token from the input. If the token is a + or -, then you
stay where you are, process the following t, and then go back to
check to see if you need to do that any more, or if you are done.


Imagine this written as a recursive descent procedure instead of
a table:


void p()
{
t();
while (nextchar == '+' || nextchar == '-')
{
getchar();
t();
}
}


This isn't all that is needed by any means, but it shows the idea.
I'd recommend that you convert your grammars into C source code
instead of tables, until you get the hang of it.


Dwight
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.