I. Oppenheim wrote:
On Mon, 7 Jul 2003, T.M. Sommers wrote:


These are not problems with lex and yacc specifically; any program
parsing abc will have to face them.  They are ambiguities, or potential
ambiguities, in the language itself.

In the first case above, there should be no problem: the composer field
is only in the header and starts a line, and the staff labels are in the
V field also in the header.


Contrary to what one would expect, this is more
problematic to deal with in Lex/Yacc than in other
parsers. The point is that Lex/Yacc do not have
facilities for context dependent tokenizing (are we in
a header or outside) nor a clean interface to exchange
information between the scanner and the parser. So one
would have to resort to global flags, which would make
the parser among other things thread-unsafe.

flex has context dependent tokenizing; it calls the contexts 'start conditions'. Since flex is free, and runs just about everywhere, I don't see why a reference implementatin could not use it.


In the second case (which is really a lexing issue), either disallow two
single bars next to each other (does such a construct even make sense?),
or require whitespace between them.


Well,

bar:  '|'     { $$.type = T_REG_BAR   }
    | '|' '|' { $$.type = T_DBL_BAR_1 }
;

Is all it takes to create a shift/reduce conflict in
Yacc.

'|' and '||' should be tokens, and distinguished in the lexer. C manages to distinguish between them without any problems.



To subscribe/unsubscribe, point your browser to: http://www.tullochgorm.com/lists.html

Reply via email to