For Programmers: Free Programming Magazines  


Home > Archive > Compilers > February 2006 > Computation of FIRST set









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Computation of FIRST set
Ulrich Frank

2006-02-19, 3:56 am

Hello NG,

I have a big problem with ANTLR and the computation of the first set of
a rule. I've already read corresponing articles on the computation of
the first set but additionally want to ask you.

In the lexer I define a token ID : ('a'..'z'); and in the parser I have
the following rules:

rule1 = ID rule2 | rule2;
rule2 = "where" rule3;
rule3 ...

So FIRST(rule1) = {ID, "where"} and FIRST(rule2) = {"where"}
RIGHT?!!

And if I define rule1 as

rule1 = (ID)? rule2;

which is equivalent to the first rule1 definition, FIRST(rule1) also is
{ID, "where"} RIGHT?!!

Please say, that I'm right. Thanks.
Ulrich Hobelmann

2006-02-19, 7:00 pm

Ulrich Frank wrote:
> Hello NG,
>
> I have a big problem with ANTLR and the computation of the first set of
> a rule. I've already read corresponing articles on the computation of
> the first set but additionally want to ask you.
>
> In the lexer I define a token ID : ('a'..'z'); and in the parser I have
> the following rules:
>
> rule1 = ID rule2 | rule2;
> rule2 = "where" rule3;
> rule3 ...
>
> So FIRST(rule1) = {ID, "where"} and FIRST(rule2) = {"where"}
> RIGHT?!!


Yes.

> And if I define rule1 as
>
> rule1 = (ID)? rule2;
>
> which is equivalent to the first rule1 definition, FIRST(rule1) also is
> {ID, "where"} RIGHT?!!


Yes to both.

> Please say, that I'm right. Thanks.


Looks very much like it, yes. No need to be . ;)

--
Suffering from Gates-induced brain leakage...

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com