I’m reading a file containing context free grammar and tokenizing each line and generating a list of the form
L = ['S', =, a, 'S', b, ;, 'S', =, c;].
In the list ‘;’ means new line. This list may extend based on the grammar in the file.
Now i wanted to partition the list for every ‘;’ encountered.
For example, consider the following rule
getRule(List, First, Rest):-
I should be able to get the first grammar line ‘S’, =, a, ‘S’, b, as first and the remaining list as Rest each time recursively.
Here is the whole thing (how to split your List into Rules) :
Using the getRule you asked for :
Callable with
Returns
And the main one :
returns
You can obviously hardcode ; if you want !
Please ask if you need any explanation about the code.
I added the modification discussed in comments and remove spoilers since you read it.
Here is the other thing you asked for :
Here is my guess but I can’t run a prolog interpreter now so it’s untested :