Subject: ambiguities in grammar with CFWS and the obs- stuff?

From: Sam Roberts <[email-masked]>
Date: Sun, 6 Feb 2000 19:04:00 -0500 (est)

I'm debugging my date-time parser, and I've found what appears
to me to be a conflict between the date-time rule, and the obs-year
rule.

date-time = ... date FWS time ...

The FWS is obviously non-optional, but date, in the obs- variation
can end with obs-year, and ops-year includes the trailing CFWS.

obs-year = ... 2*DIGIT [CFWS]

My parser is globbing all the FWS with the trailing CFWS of the obs-year.

A similar thing happens with the:

 obs-day obs-month obs-year

sequence, the CFWS becomes part of obs-day, leaving none of the
mandatory CFWS left for the obs-month.

In a slightly different fashion, a time such as:

20(comment):12

is failing:

time-of-day = hour ":" minute
hour = 2DIGIT / obs-hour
obs-hour = [CFWS] 2DIGIT [CFWS]

"20" matches the first form of the hour rule, no need to resort to
obs-hour, but "(comment):" doesn't match ":". Something like:

time-of-day = hour ":" minute [":" second] / obs-time-of-day
obs-time-of-day = hour [CFWS] ":" [CFWS] minute [CFWS] [":" [CFWS] second]

would match more naturally.

I don't know if this is really a problem, but my code was a literal
representation of the ABNF until I ran into these, now I'm having to
rewrite the ABNF. To me it seems like an ambiguity in the grammer, I
need to decide if:

top = left b c
left = a [b]

associates the b with the left or the right. This happens a bunch with
trailing [CFWS] in the obsolete forms followed by mandatory FWS.

Also problematic is:

top = left ":" right
left = a / else
else = (a space)

For input:

a space : ...

The a is matched right away. This happens with:

Fri(the 13th),

where "Fri" matches right away, no need to resort to the obs-dayofweek
that would've matched the comment, but we need the comment matched.

Any comments anyone? With my Rfc822 parser I just put statments before
and after looking for or getting a token that would attempt to match
as much whitespace or comments as I could. I'd rather that the grammer
completely specified where CFWS can appear, like DRUMS does, but unless
there's an interpretation of the ABNF that is less problematic for me
perhaps I'll go back to my Rfc822 parser for reading messages, and make a
simpler drums parser (minus all the obs- forms) that I use only to
verify compliance.

Sam

--
Sam Roberts, sroberts at uniserve dot com, www.emyr.net/Sam

---

From: Charles Lindsey <[email-masked]>
Date: Mon, 7 Feb 2000 10:24:32 +0000 (GMT)

On Sun, 6 Feb 2000 19:04:00 -0500 (est)
	Sam Roberts <[email-masked]> said...

> to me to be a conflict between the date-time rule, and the obs-year

No, you confuse the intent of the grammar which specifies the syntax.
It is not intended to define a parser, nor to specify any left-to-right
or right-to-left method of interpretation. Rather, anything that can be
"produced" by following the grammar is allowed, and anything than cannot
be so "produced" is not. Figuring out how to write a parser is left to
the implementor as an exercise :-( .

This has always been the traditional way when specifying programming
language (and I was a program language designer in an earlier life, so I
should know).

In fact, since the grammar as provided is context free, it IS
theoretically possible to derive a parser directly from it, but it would
need to have an arbitrarily complex backtracking mechanism built into
it. Implementors can surely figure out something simpler.

Charles H. Lindsey ---------At Home, doing my own thing------------------------
Email:     [email-masked]  Web:   http://www.cs.man.ac.uk/~chl
Voice/Fax: +44 161 437 4506      Snail: 5 Clerewood Ave, CHEADLE, SK8 3JU, U.K.
PGP: 2C15F1A9     Fingerprint: 73 6D C2 51 93 A0 01 E7  65 E8 64 7E 14 A4 AB A5