I need to construct a parser for an expression which is allowed to have only 2 operators (AND & OR) and such that both operators cannot be presenet in a enclosing paranthesis.
Eg1:
(A AND B OR C) --> invalid
(A AND (B OR C)) --> valid
Eg2:
(A AND (B OR C) OR D) --> invalid
((A AND (B OR C)) OR D) --> valid
(A AND ((B OR C) OR D)) --> valid
Please note: I'm very new to this. I had tried to attempt this using LL(1) parser by following a few online tutorials. Here is what I've achieved so far.
E -> F E'
E' -> OR F E'
E' -> ''
F -> G F'
F' -> AND G F'
F' -> ''
G -> ( E )
G -> id
The above grammar rules checks whether I have only the valid operators & parenthesis but doesn't not identify the ambiguity problem. I'm not expecting a solution here but I just wanna know if I'm on the right track. Because in one of the tutorial the tutor had mentioned that LL(1)
parser will not work if there is more than one lookup for a terminal symbol. I know that I haven't encountered such a situation yet but will I (particularly when generating the rules for resolving the ambiguity)???
Edit1
E -> F E'
E' -> OR F E'
E' -> AND F E'
E' -> ''
F -> ( E )
F -> id
Edit2: Solution
E -> F E'
E' -> and F G
E' -> or F H
E' -> ''
G -> and F G
G -> ''
H -> or F H
H -> ''
F -> ( E )
F -> id