5 May 1997 22:00:12 -0400

Related articles |
---|

trivial rule does not reduce in ML-Yacc gergoe@math.bme.hu (Buday Gergely) (1997-05-05) |

From: | Buday Gergely <gergoe@math.bme.hu> |

Newsgroups: | comp.compilers |

Date: | 5 May 1997 22:00:12 -0400 |

Organization: | Compilers Central |

Keywords: | ML, yacc, question |

Hello,

My problem surely has an easy solution, but I cannot see it.

I'm trying to write a parser, and encountered to an error, what I

reproduced in a very simple example. In ML-Yacc, the START symbol (the

sentence symbol) cannot appear on the right hand side of a rule. So, I

introduced EXPR, what I expected to reduce to START

straightforward. But it does not work this way. What did I wrong?

- Gergely

I've got:

1 rule not reduced

warning: rule <START : EXPR > will never be reduced

----------

trivi.grm:

----------

%%

%name Trivi

%term NUMBER of string | PLUS | EOF

%nonterm START of string | EXPR of string

%pos int

%verbose

%noshift EOF

%%

START : EXPR (EXPR)

EXPR : EXPR PLUS NUMBER (EXPR ^ "PLUS" ^ NUMBER)

| NUMBER (NUMBER)

---------------

trivi.grm.desc:

---------------

1 rule not reduced

warning: rule <START : EXPR > will never be reduced

state 0:

START : . EXPR

NUMBER shift 2

START goto 5

EXPR goto 1

. error

state 1:

START : EXPR . (reduce by rule 0)

EXPR : EXPR . PLUS NUMBER

PLUS shift 3

. error

state 2:

EXPR : NUMBER . (reduce by rule 2)

. reduce by rule 2

state 3:

EXPR : EXPR PLUS . NUMBER

NUMBER shift 4

. error

state 4:

EXPR : EXPR PLUS NUMBER . (reduce by rule 1)

. reduce by rule 1

state 5:

. error

3 of 9 action table entries left after compaction

2 goto table entries

--

Post a followup to this message

Return to the
comp.compilers page.

Search the
comp.compilers archives again.