How can I understand this binary expression grammar?

237 views Asked by At

I don't understand this binary expression grammar

expr -> expr '+' term
      | expr '-' term
      | term

term -> term '*' factor
      | term '/' factor
      | factor

factor -> '(' expr ')'
        | NUM 
1

There are 1 answers

0
599644 On

In plain english:

An expr can be one of the following:

  • another expr followed by the character + followed by a term
  • another expr followed by the character - followed by a term
  • a term

A term can be one of the following:

  • another term followed by the character * followed by a factor
  • another term followed by the character / followed by a factor
  • a factor

A factor can be one of the following:

  • a character ( followed by and expr followed by a character )
  • a number