[Haskell-cafe] Expression parsing problem

leledumbo leledumbo_cool at yahoo.co.id
Tue May 19 04:06:33 EDT 2009


> Indeed, the grammar does not admit "1*2/3" as a sentence ...

Huh? Why not? "1 * 2 / 3" should match factor "*" factor "/" factor.
Remember that { } is repetition, so it should be able to handle such term.

> expression ::= term | term "+" expression
> term ::= factor | factor "*" term
> factor ::= constant | variable | "(" expression ")" 

Oh, left recursion. Well, it should be easy to transform:

expression ::= term | moreTerm
term ::= factor | moreFactor
moreTerm ::= term "+" expression
factor ::= constant | variable | "(" expression ")" 
moreFactor := factor "*" term

correct?
-- 
View this message in context: http://www.nabble.com/Expression-parsing-problem-tp23610457p23611617.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list