H98 Report: expression syntax glitch
Arthur Baars
arthurb@cs.uu.nl
Wed, 27 Feb 2002 16:00:39 +0100
In the context-free grammar proposed by Ross Paterson
the following line:
expix -> expi+1B [qop(n,i) expi+1x]
should be replaced by
expix -> [expi+1B qop(n,i)] expi+1x
Without this modification a single exp10A-expression can not be derived from
the nonterminal exp.
Apart from this small mistake, I think that the proposed grammar correctly
specifies the language we want.
Cheers Arthur
On 27-02-2002 11:42, "Ross Paterson" <ross@soi.city.ac.uk> wrote:
> OK, so you have a context-free grammar qualified by a rule forbidding
> some of the derivations of that grammar.
>
> Another solution would be to subdivide exp^10 using a superscript I've
> called A or B from lack of imagination:
>
> exp10A -> \ apat[1] ... apat[n] -> exp (lambda abstraction, n>=1)
> | let decls in exp (let expression)
> | if exp then exp else exp (conditional)
> exp10B -> case exp of { alts } (case expression)
> | do { stmts } (do expression)
> | fexp
>
> Only the latter sort can be followed by infix operators or type signatures.
> We could extend the distinction to the exp^i (here x ranges over {A,B}):
>
> exp -> exp0B :: [context =>] type (expression type signature)
> | exp0
> expi -> expiA
> | expiB
> expix -> expi+1B [qop(n,i) expi+1x]
> | lexpix
> | rexpix
> lexpix -> (lexpiB | expi+1B) qop(l,i) expi+1x
> lexp6x -> - exp7x
> rexpix -> expi+1B qop(r,i) (rexpix | expi+1x)
>
> and the rules for sections would be
>
> aexp -> ...
> | ( expi+1B qop(a,i) ) (left section)
> | ( qop(a,i) expi+1 ) (right section)
>
> It's complicated, but it does at least specify precisely the language
> and parses we want in a single context-free description.