deb
deb

Reputation: 21

Failing to generate the grammar

I have to check the syntax for a simple boolean expression such as (X = 100 and Y < 100), I wrote the grammar and tried to check if this was correct so I am using this online tool http://smlweb.cpsc.ucalgary.ca/start.html. it is saying the grammar is wrong.

can someone point out the issue here ? thanks in advance.

boolean       -> bool_term | boolean OR bool_term  
bool_term     -> bool_factor | bool_term AND bool_factor
bool_factor   -> bool_primary | NOT bool_primary
bool_primary  -> predicate | ( boolean )  
predicate     -> expr comp_op expr 
expr          -> string | number.
comp_op       -> = |  > 

Upvotes: 0

Views: 53

Answers (1)

Andrei Moiseev
Andrei Moiseev

Reputation: 4084

It is mostly about the stupid syntax of the service. For example, characters = and > are unsupported and there is no way to escape them.

This grammar works:

BOOLEAN       -> BOOLTERM | BOOLEAN or BOOLTERM  .
BOOLTERM      -> BOOLFACTOR | BOOLTERM and BOOLFACTOR .
BOOLFACTOR    -> BOOLPRIMARY | not BOOLPRIMARY .
BOOLPRIMARY   -> PREDICATE | ( BOOLEAN )  .
PREDICATE     -> EXPR COMPOP EXPR .
EXPR          -> string | number .
COMPOP        -> eq | gt .

Upvotes: 1

Related Questions