[Haskell-cafe] Expression parsing problem
Malcolm Wallace
malcolm.wallace at cs.york.ac.uk
Tue May 19 03:54:54 EDT 2009
> The grammar:
> expression = "get" | [ "+" | "-" ] term { ( "+" | "-" ) term }
> term = factor { ( "*" | "/" ) factor }
> factor = IDENTIFIER | VALUE | "(" expression ")"
>
> I can't make term parse, for instance "1 * 2 / 3"
Indeed, the grammar does not admit "1*2/3" as a sentence of that
language although it will admit "(1*2)/3" or "1*(2/3)".
If you wish to allow sequences of infix operators without bracketting,
then examples of the standard grammar for this can be found by
searching the web for "expression term factor", e.g. http://en.wikipedia.org/wiki/Syntax_diagram
suggests:
expression ::= term | term "+" expression
term ::= factor | factor "*" term
factor ::= constant | variable | "(" expression ")"
Regards,
Malcolm
More information about the Haskell-Cafe
mailing list