119k views
4 votes
Consider the following grammar

assign → id := expr

id → A | B | C

expr → expr + term | term

term → term * factor | factor

factor → id | - id

Now consider the sentence of the grammar:

A := A + B * - C

Produce a leftmost derivation of this sentence

User Rebatoma
by
7.8k points

1 Answer

1 vote

Final answer:

A leftmost derivation is a process of rewriting the given sentence starting from the leftmost non-terminal symbol.

Step-by-step explanation:

A leftmost derivation is a process of rewriting the given sentence starting from the leftmost non-terminal symbol. Here is the leftmost derivation of the sentence "A := A + B * - C" using the given grammar:

  1. assign → id := expr
  2. id := expr → A := expr
  3. expr → expr + term → A := A + term
  4. term → term * factor → A := A + B * factor
  5. factor → - id → A := A + B * - C

Now, the sentence has been derived using the leftmost derivation. Each step in the derivation applies a production rule from the grammar and replaces a non-terminal symbol with its corresponding expansion.

User Prakhar Jhudele
by
8.6k points