|Simple Expression Recursion vs Expression/Term/Factor firstname.lastname@example.org (Mike Stogden) (2001-08-02)|
|Re: Simple Expression Recursion vs Expression/Term/Factor email@example.com (Vinay Kakade) (2001-08-06)|
|From:||Vinay Kakade <firstname.lastname@example.org>|
|Date:||6 Aug 2001 04:00:36 -0400|
|Posted-Date:||06 Aug 2001 04:00:36 EDT|
expr -> expr + expr | expr * expr | id | num
is an ambiguous one. For example, for the string "id + id * id", it generates
two different parse trees.
On the other hand, the grammar involving term, factor is an umambiguous one. It
generates a unique parse tree for the above string.
By the way, if you are using yacc, you can resolve the ambiguity in first case
by giving precedences to "+" and "-" using %prec.
Mike Stogden wrote:
> Please could someone offer an explanation as to the relative merits of
> describing expressions as productions based on two comparable
> I have seen expressions for the same language described as...
> expr -> expr + expr
> expr -> expr * expr
> expr -> expr + term
> term -> factor | term * factor
> factor -> number | identifier
Return to the
Search the comp.compilers archives again.