views:

22

answers:

1

Inconvenience in specifying grammars - we cannot factor out bin_op in following example (Bison):

expr : expr bin_op expr ;
bin_op : Add
    | Mul
    ;

because of shift/reduce conflicts. Is there parsing technique or parser generator which allows such thing?

A: 

Yes

Yacc has been employed to parse almost every real programming language and some other types. I'm not nearly its biggest fan but it can certainly parse that grammar or perhaps an equivalent that is written with yacc in mind.

And shift/reduce conflicts are not errors.

DigitalRoss
Equivalent - yes, that - no. It's the point of question.Text from one pdf file on the Net (I cannot find it again):A hint: following grammar does not work…precedence left AND,OR;precedence left PLUS,MINUS;precedence left STAR,SLASH;expr ::= expr bin_op expr;expr ::= ID;bin_op ::= AND|OR|PLUS|MINUS|STAR|SLASH;Consider parser stacks:expr/exprbin_opexprexprbin_opexprWhat to do if next token is PLUS?Could shift PLUSCould reduce expr bin_op exprDepends on precedence of bin_op vs PLUSPrecedence has been lost
DSblizzard
Here it is: http://www.cs.uvm.edu/~skalka/202/lecture-5.pdf
DSblizzard