Pablo Menendez
Pablo Menendez

Reputation: 33

How to make this grammar LL(1)

I want to know if it would be possible to transform this grammar to LL(1). This is the grammar:

A -> B
   | C

B -> a 
   | a ';'

C -> a D
   | a D ';'

D -> ';' a
   | D ';' a

Upvotes: 0

Views: 486

Answers (2)

Pablo Menendez
Pablo Menendez

Reputation: 33

This is the same grammar but simpler: A -> a | a ';' | a ';' A

It still not LL(1). But removing left factor now it is LL(1): A -> a B B -> ε | ';' C C -> ε | A

Upvotes: 0

Scott Hunter
Scott Hunter

Reputation: 49896

Since this language is regular ( a; | a(;a)+;? ), then yes, it would be possible.

Not sure if I'm using the right syntax, but the language is basically a; (using A->B) or any string that starts with an a, followed one or more ;a pairs, optionally adding another ; on the end.

Upvotes: 1

Related Questions