83 views
Rewrite the following SDT:

A->A {a} B | AB {b} | 0

B->B {c} A | BA {d} | 1

so that the underlying grammar becomes non-left-recursive. Here a, b, c and d are actions, and 0 and 1 are terminals

is my solution correct?

A→ 0A’

A’→ {a} BA’ | B {b} A’ | ε

B→ 1B’

B’→ {c} AB’ | A {d} B’ | ε
| 83 views
0
what 2nd bracket thing actually representing here

Is it printing statement or nonterminal?
0
they're actions(semantic). it's mentioned in the question
0
action means it can be printf statement, +,-, or any arithmetic or logical operations

right?
0
yes!
0
yes, u r correct. position of actions cannot be changed
0

where u got action always done at last?

See here also printing done in middle https://gateoverflow.in/194481/sdt-compiler

0

@srestha that's not my question

when semantic action is performed in the middle and semantic action is done on a left-recursive variable then how to you eliminate left-recursion?

+2
Suppose

$E\rightarrow E+T|T$

then

$E\rightarrow TE'$

$E'\rightarrow +TE'|\epsilon$

So, actions are in place

right?
0
yeah.. got it now 👍