Haskell 98 Grammar

Top level symbols:

1 Lexical Syntax
program ::= 2.2 9.2
lexeme ::= 2.2 9.2
qvarid | qconid | qvarsym | qconsym | literal | special | reservedop | reservedid
literal ::= 2.2 9.2
integer | float | char | string
special ::= 2.2 9.2
( | ) | , | ; | [ | ] | ` | { | }
whitespace ::= 2.2 9.2
whitestuff ::= 2.2 9.2
whitechar | comment | ncomment
whitechar ::= 2.2 9.2
newline | vertab | space | tab | uniWhite
newline ::= 2.2 9.2
|
|
|
return ::= 2.2 9.2
a_carriage_return
linefeed ::= 2.2 9.2
a_line_feed
vertab ::= 2.2 9.2
a_vertical_tab
formfeed ::= 2.2 9.2
a_form_feed
space ::= 2.2 9.2
a_space
tab ::= 2.2 9.2
a_horizontal_tab
uniWhite ::= 2.2 9.2
any_Unicode_character_defined_as_whitespace
comment ::= 2.2 9.2
dashes ( any except symbol ( any )* )? newline
dashes ::= 2.2 9.2
-- ( - )*
opencom ::= 2.2 9.2
{-
closecom ::= 2.2 9.2
-}
ncomment ::= 2.2 9.2
ANYseq ::= 2.2 9.2
( ANY )* except ( ( ANY )* ( opencom | closecom ) ( ANY )* )
ANY ::= 2.2 9.2
graphic | whitechar
any ::= 2.2 9.2
graphic | space | tab
graphic ::= 2.2 9.2
small | large | symbol | digit | special | : | " | '
small ::= 2.2 9.2
ascSmall | uniSmall | _
ascSmall ::= 2.2 9.2
a | b | ... | z
uniSmall ::= 2.2 9.2
any_Unicode_lowercase_letter
large ::= 2.2 9.2
ascLarge | uniLarge
ascLarge ::= 2.2 9.2
A | B | ... | Z
uniLarge ::= 2.2 9.2
any_uppercase_or_titlecase_Unicode_letter
symbol ::= 2.2 9.2
|
uniSymbol except ( special | _ | : | " | ' )
ascSymbol ::= 2.2 9.2
! | # | $ | % | & | * | + | . | / | < | = | > | ? | @ | \ | ^ | | | - | ~
uniSymbol ::= 2.2 9.2
any_Unicode_symbol_or_punctuation
digit ::= 2.2 9.2
ascDigit | uniDigit
ascDigit ::= 2.2 9.2
0 | 1 | ... | 9
uniDigit ::= 2.2 9.2
any_Unicode_decimal_digit
octit ::= 2.2 9.2
0 | 1 | ... | 7
hexit ::= 2.2 9.2
digit | A | ... | F | a | ... | f
varid ::= 2.4 9.2
( small ( small | large | digit | ' )* ) except reservedid
conid ::= 2.4 9.2
large ( small | large | digit | ' )*
reservedid ::= 2.4 9.2
case | class | data | default | deriving | do | else | if | import | in | infix | infixl | infixr | instance | let | module | newtype | of | then | type | where | _
varsym ::= 2.4 9.2
( symbol ( symbol | : )* ) except ( reservedop | dashes )
consym ::= 2.4 9.2
( : ( symbol | : )* ) except reservedop
reservedop ::= 2.4 9.2
.. | : | :: | = | \ | | | <- | -> | @ | ~ | =>
tyvar ::= 2.4 4.1.3 9.2
varid
tycon ::= 2.4 9.2
conid
tycls ::= 2.4 4.1.3 9.2
conid
modid ::= 2.4 5.1 9.2
conid
qvarid ::= 2.4 9.2
( modid . )? varid
qconid ::= 2.4 9.2
( modid . )? conid
qtycon ::= 2.4 9.2
( modid . )? tycon
qtycls ::= 2.4 4.1.3 9.2
( modid . )? tycls
qvarsym ::= 2.4 9.2
( modid . )? varsym
qconsym ::= 2.4 9.2
( modid . )? consym
decimal ::= 2.5 9.2
digit ( digit )*
octal ::= 2.5 9.2
octit ( octit )*
hexadecimal ::= 2.5 9.2
hexit ( hexit )*
integer ::= 2.5 9.2
|
0o octal
|
0O octal
|
|
float ::= 2.5 9.2
|
exponent ::= 2.5 9.2
( e | E ) ( + | - )? decimal
char ::= 2.6 9.2
' ( graphic except ( ' | \ ) | space | escape except \& ) '
string ::= 2.6 9.2
" ( graphic except ( " | \ ) | space | escape | gap )* "
escape ::= 2.6 9.2
charesc ::= 2.6 9.2
a | b | f | n | r | t | v | \ | " | ' | &
ascii ::= 2.6 9.2
cntrl | NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | HT | LF | VT | FF | CR | SO | SI | DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | CAN | EM | SUB | ESC | FS | GS | RS | US | SP | DEL
cntrl ::= 2.6 9.2
^ ( ascLarge | @ | [ | \ | ] | ^ | _ )
gap ::= 2.6 9.2
2 Context Free Syntax
module ::= 4 5.1 9.5
module modid ( exports )? where body
|
body ::= 4 5.1 9.5
|
|
impdecls ::= 5.1 9.5
exports ::= 5.2 9.5
( ( export ( , export )* )? ( , )? )
export ::= 5.2 9.5
|
qtycon ( (..) | ( ( cname ( , cname )* )? ) )?
|
qtycls ( (..) | ( ( qvar ( , qvar )* )? ) )?
|
module modid
impdecl ::= 5.3 9.5
import ( qualified )? modid ( as modid )? ( impspec )?
|
impspec ::= 5.3 9.5
( ( import ( , import )* ( , )? )? )
|
hiding ( ( import ( , import )* ( , )? )? )
import ::= 5.3 9.5
|
tycon ( (..) | ( ( cname ( , cname )* )? ) )?
|
tycls ( (..) | ( ( var ( , var )* )? ) )?
cname ::= 5.2 5.3 9.5
var | con
topdecls ::= 4 5.1 9.5
( topdecl ( ; topdecl )* )?
topdecl ::= 4 4.2.1 4.2.2 4.2.3 4.3.1 4.3.2 4.3.4 9.5
|
data ( context => )? simpletype = constrs ( deriving )?
|
newtype ( context => )? simpletype = newconstr ( deriving )?
|
class ( scontext => )? tycls tyvar ( where cdecls )?
|
instance ( scontext => )? qtycls inst ( where idecls )?
|
default ( ( type ( , type )* )? )
|
decls ::= 4 9.5
{ ( decl ( ; decl )* )? }
decl ::= 4 4.4.3 9.5 11.1 11.2
|
cdecls ::= 4 4.3.1 9.5
{ ( cdecl ( ; cdecl )* )? }
cdecl ::= 4 4.3.1 9.5
|
( funlhs | var ) rhs
idecls ::= 4 4.3.2 9.5
{ ( idecl ( ; idecl )* )? }
idecl ::= 4 4.3.2 9.5
( funlhs | var ) rhs
|
gendecl ::= 4 4.4.1 4.4.2 9.5
vars :: ( context => )? type
|
|
ops ::= 4 4.4.2 9.5
op ( , op )*
vars ::= 4 4.4.1 9.5
var ( , var )*
fixity ::= 4 4.4.2 9.5
infixl | infixr | infix
type ::= 4.1.2 9.5
btype ( -> type )?
btype ::= 4.1.2 9.5
( btype )? atype
atype ::= 4.1.2 9.5
|
|
( type ( , type )+ )
|
[ type ]
|
( type )
gtycon ::= 4.1.2 9.5
|
( )
|
[ ]
|
( -> )
|
( , ( , )* )
context ::= 4.1.3 9.5
|
( ( class ( , class )* )? )
class ::= 4.1.3 9.5
|
qtycls ( tyvar ( atype )+ )
scontext ::= 4.3.1 9.5
|
( ( simpleclass ( , simpleclass )* )? )
simpleclass ::= 4.3.1 9.5
simpletype ::= 4.2.1 4.2.2 4.2.3 9.5
tycon ( tyvar )*
constrs ::= 4.2.1 9.5
constr ( | constr )*
constr ::= 4.2.1 9.5
con ( ( ! )? atype )*
|
( btype | ! atype ) conop ( btype | ! atype )
|
con { ( fielddecl ( , fielddecl )* )? }
newconstr ::= 4.2.3 9.5
|
con { var :: type }
fielddecl ::= 4.2.1 9.5
vars :: ( type | ! atype )
deriving ::= 4.2.1 9.5
deriving ( dclass | ( ( dclass ( , dclass )* )? ) )
dclass ::= 4.2.1 9.5
qtycls
inst ::= 4.3.2 9.5
|
( gtycon ( tyvar )* )
|
( tyvar ( , tyvar )+ )
|
( tyvar )?
|
( tyvar -> tyvar )
funlhs ::= 4.4.3 9.5
var apat ( apat )*
|
|
( funlhs ) apat ( apat )*
rhs ::= 4.4.3 9.5
= exp ( where decls )?
|
gdrhs ( where decls )?
gdrhs ::= 4.4.3 9.5
gd = exp ( gdrhs )?
gd ::= 3.13 4.4.3 9.5
exp ::= 3 3.3 3.4 3.6 3.7 3.12 3.13 3.14 3.16 9.5
exp_i :: ( context => )? type
|
exp_i a ::=
|
|
exp_10 ::=
\ ( apat )+ -> exp
|
let decls in exp
|
if exp then exp else exp
|
case exp of { alts }
|
do { stmts }
|
fexp ::= 3 3.3 9.5
( fexp )? aexp
aexp ::= 3 3.2 3.5 3.7 3.8 3.9 3.10 3.11 3.15.1 3.15.2 3.15.3 9.1 9.5
|
|
|
( exp )
|
( exp ( , exp )+ )
|
[ exp ( , exp )* ]
|
[ exp ( , exp )? .. ( exp )? ]
|
[ exp | qual ( , qual )* ]
|
( exp_i a qop )
|
( qop exp_i a )
|
qcon { ( fbind ( , fbind )* )? }
|
aexp { fbind ( , fbind )* }
qual ::= 3.11 9.5
pat <- exp
|
let decls
|
alts ::= 3.13 9.5
( alt ( ; alt )* )?
alt ::= 3.13 9.5
pat -> exp ( where decls )?
|
pat gdpat ( where decls )?
|
gdpat ::= 3.13 9.5
gd -> exp ( gdpat )?
stmts ::= 3.14 9.5
( stmt )* exp ( ; )?
stmt ::= 3.14 9.5
exp ;
|
pat <- exp ;
|
let decls ;
|
;
fbind ::= 3.15.2 9.5
pat ::= 3.13 3.17.1 9.5
|
pat_i b ::=
|
- ( integer | float )
|
pat_10 ::=
|
gcon ( apat )+
apat ::= 3.17.1 9.5
var ( @ apat )?
|
|
qcon { ( fpat ( , fpat )* )? }
|
|
_
|
( pat )
|
( pat ( , pat )+ )
|
[ pat ( , pat )* ]
|
~ apat
fpat ::= 3.17.1 9.5
gcon ::= 3.2 3.7 3.9 9.5
( )
|
[ ]
|
( , ( , )* )
|
var ::= 3.2 9.5
|
( varsym )
qvar ::= 3.2 9.5
|
( qvarsym )
con ::= 3.2 9.5
|
( consym )
qcon ::= 3.2 3.7 3.8 9.5
|
( gconsym )
varop ::= 3.2 9.5
|
` varid `
qvarop ::= 3.2 9.5
|
` qvarid `
conop ::= 3.2 9.5
|
` conid `
qconop ::= 3.2 3.7 9.5
|
` qconid `
op ::= 3.2 4.4.2 9.5
varop | conop
qop ::= 3.2 3.4 3.7 9.5
qvarop | qconop
gconsym ::= 3.2 3.7 9.5
: | qconsym


Notes:
a) Shift-reduce conflicts are resolved based on operator precedence and associativity. Unary minus has precedence 6. When an operator is generating a function (one of the arguments is not supplied) then it must have such precedence and associativity so that it would be executed as the last one if the missing argument would be supplied.
b) Shift-reduce conflicts are resolved based on operator precedence and associativity. Negating a literal has precedence 6.

This DHTML application was created based on data in Haskel 98 Report by Peter Hercek. Enjoy.

Copyright 2002, 2003, 2007 Peter Hercek, All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You can receive a copy of the GNU General Public License here.

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~

~