computing the first set (concretely)

"aegis" <aegis@mad.scientist.com>
11 Mar 2006 23:36:56 -0500

          From comp.compilers

Related articles
computing the first set (concretely) aegis@mad.scientist.com (aegis) (2006-03-11)
Re: computing the first set (concretely) DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-03-12)
Re: computing the first set (concretely) wyrmwif@tsoft.org (SM Ryan) (2006-03-12)
| List of all articles for this month |

From: "aegis" <aegis@mad.scientist.com>
Newsgroups: comp.compilers
Date: 11 Mar 2006 23:36:56 -0500
Organization: http://groups.google.com
Keywords: parse, analysis

I know how to compute the first set however I am conflicted on how I
should represent the syntactical specification of my language in order
to compute the first set programmatically.


I was thinking along the lines of a two dimensional matrix by where
the rows are indexed by a particular nonterminal to find all terminals
for the given production.


It would look something like:


int table[X][Y] = { { ... } ,
                                                    { expr, '+', digit },
                                                    { 0, 1, 2, 3, 4, 5 },
                                                    { ... }
                                                };


and where my specification would look like:


...
expr: expr '+' digit ;
digit: 0 | 1 | 2 | 3 | 4 | 5 ;
...


so then I can compute the set of terminals that would appear first
when applying some production. (my non terminals could be represented
with enumerated constants produced by enum)


I'm looking for feedback from people who have implemented a FIRST()
operator. Is there a general way of doing it? Am I on the wrong path?


--
aegis


Post a followup to this message

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