little expression parser

69 views
Skip to first unread message

Chris Anders

unread,
Feb 24, 2015, 1:45:32 PM2/24/15
to eto-...@googlegroups.com
letter ::= 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y'
numeric
::= '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
number
::= [ '-' ] (numeric)+ [',' (numeric)+]

operator ::= "+" | "-" | "*" | "/"
expression
::= number operator | expression


but i can only match like this: 5+
or: 9*

what do I wrong?

Curtis Wensley

unread,
Feb 26, 2015, 1:36:05 AM2/26/15
to eto-...@googlegroups.com
Your top expression effectively only matches "number operator | number operator ..."

so you never tell your grammar that you can match "number operator number"

What you could possibly do is:

expression ::= number operator expression | number

This should allow you to match: 5 * 3 / 2

Cheers!
Curtis.
Reply all
Reply to author
Forward
0 new messages