haskell - Parsec: Predictive parsing -


i have few skills haskell , need how implement predictive parsing (ll*) parsec.

i have context free grammar:

<a> ::= identifier | identifier '(' <args> ')' 

based on http://research.microsoft.com/en-us/um/people/daan/download/parsec/parsec.pdf (chapter predictive parsers) wrote code:

term =  do{ x <- m_identifier     ; try( char '(' )     ; b <- argsparser     ; char ')'     ; return (fnccall x b)     } <|> { x <- m_identifier     ; return (varid x)     } 

i expected code try match '(' , if not parser continue , match identifier. code works matching identifier '(' args ')'.

with calling on identifier "a" throws:

parse error @ (line 1, column 2): unexpected end of input expecting letter or digit or "(" 

all alternative part should under try, think:

term =  try( do{ x <- m_identifier     ; char '('     ; b <- argsparser     ; char ')'     ; return (fnccall x b)     } ) <|> { x <- m_identifier     ; return (varid x)     } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -