[Haskell-cafe] Happy Parser problem
Aaron Gray
aaronngray.lists at gmail.com
Fri Dec 31 15:43:42 CET 2010
On 31 December 2010 13:21, Aaron Gray <aaronngray.lists at gmail.com> wrote:
> I am trying to get a grammar where keywords are also valid identifiers.
>
>
Sorry working now !
Aaron
> Been messing round with the following Happy grammar :-
>
> %token
> 'let' { TokenIdent "let" }
> 'in' { TokenIdent "in" }
> ident { TokenIdent $$ }
> int { TokenInt $$ }
> '=' { TokenEq }
> '+' { TokenPlus }
> '-' { TokenMinus }
> '*' { TokenTimes }
> '/' { TokenDiv }
> '(' { TokenOB }
> ')' { TokenCB }
>
> %%
>
> Exp : 'let' Var '=' Exp 'in' Exp { Let $2 $4 $6 }
> | Exp1 { Exp1 $1 }
>
> Exp1 : Exp1 '+' Term { Plus $1 $3 }
> | Exp1 '-' Term { Minus $1 $3 }
> | Term { Term $1 }
>
> Term : Term '*' Factor { Times $1 $3 }
> | Term '/' Factor { Div $1 $3 }
> | Factor { Factor $1 }
>
> Factor :: { Factor }
> : int { Int $1 }
> | ident { Var $1 }
> | '(' Exp ')' { Brack $2 }
>
> Var :: { Factor }
> : ident { Var $1 }
> | 'let' { Var "let" }
>
> Here 'Var' should be able to represent a 'let' identifier, as well as a
> keyword. Happy accepts the grammar but it does not parser the expected 'let
> let = x in let'.
>
> I have attached the full Happy grammar.
>
> I don't think this is an LR thing, but could be wrong.
>
> Many thanks in advance,
>
> Aaron
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101231/79353cde/attachment.htm>
More information about the Haskell-Cafe
mailing list