I have this grammar in EBNF for a sub-language with arithmetic & logical expressions, variables assignment and printing.
start ::= (print | assign)*
print ::= print expr ;
assign ::= ID = expr ;
expr ::= andExpr (|| andExpr)*
andExpr ::= relExpr (&& relExpr)*
relExpr ::= addExpr ( == addExpr | != addExpr | <= addExpr | >= addExpr | < addExpr | > addExpr)?
addExpr ::= mulExpr (+ mulExpr | - mulExpr)*
mulExpr ::= unExpr (* hunExpri | / hunExpr)*
unExpr ::= + unExpr | - unExpr | ! unExpr | primary
primary ::= ( expr ) | ID | NUM | true | false
unfortunately I just can't figure out what these two rules:
unExpr ::= + unExpr
unExpr ::= - unExpr
actually do, or why I should need them, since I seem to be able to derive every phrase of the language without applying them. Any idea?
thanks a lot :-)
If you are planning no expressions like:
a=-1
(where "a" is an ID and "1" is a NUM) in your language than you don't need those two rules. Otherwise you have to implement them.