Skip to main content
Tweeted twitter.com/#!/StackCompSci/status/541228553023787008
edited tags
Link
Raphael
  • 72.9k
  • 30
  • 181
  • 393
Source Link
Xpl0
  • 167
  • 2
  • 9

Context-free grammars and priority

This grammar is supposed to give priority to multiplication:

  • E -> E + T | T.
  • T -> T * F | F.
  • F -> x.

A derivation for "x + x * x" would be (unless I'm wrong):

E => E + T => T + T => F + T => x + T => x + T * F => x + F * F => x + x * F => x + x * x.

So how is multiplication given priority over addition? It appears that the addition is produced first.