[raj@tinman hw3]$ more dlg.pl
%
terminal(dollar).
terminal(name).
terminal(lparen).
terminal(rparen).
terminal(implies).
terminal(period).
terminal(comma).
terminal(notop).
terminal(comparison).
terminal(number).
terminal(string).
terminal(variable).
terminal(nil).
%
nonterminal(ddb).
nonterminal(idbrules).
nonterminal(idbrule).
nonterminal(idbbody).
nonterminal(literal).
nonterminal(predicate).
nonterminal(arglist).
nonterminal(arg).
%
start(ddb).
%
p(ddb,[idbrules,dollar]).
p(idbrules,[idbrule]).
p(idbrules,[idbrule,idbrules]).
p(idbrule,[name,lparen,arglist,rparen,implies,idbbody,period]).
p(idbbody,[literal]).
p(idbbody,[literal,comma,idbbody]).
p(literal,[notop,predicate]).
p(literal,[predicate]).
p(predicate,[name,lparen,arglist,rparen]).
p(predicate,[arg,comparison,arg]).
p(arglist,[arg]).
p(arglist,[arg,comma,arglist]).
p(arg,[number]).
p(arg,[string]).
p(arg,[variable]).

1 ?- ['dlg.pl'].
% dlg.pl compiled 0.00 sec, 7,136 bytes
true.

2 ?- ['td.pl'].
% td.pl compiled 0.00 sec, 26,200 bytes
true.

3 ?- first(ddb,L).
L = [name] .

4 ?- first(idbrules,L).
L = [name] .

5 ?- first(idbrule,L).
L = [name] .

6 ?- first(idbbody,L).
L = [name, notop, number, string, variable] .

7 ?- first(literal,L).
L = [notop, name, number, string, variable] .

8 ?- first(predicate,L).
L = [number, string, variable, name] .

9 ?- first(arglist,L).
L = [number, string, variable] .

10 ?- first(arg,L).
L = [number, string, variable] .


3 ?- follow(ddb,L).
L = [$].

4 ?- follow(idbrules,L).
L = [dollar].

5 ?- follow(idbrule,L).
L = [dollar, name].

6 ?- follow(idbbody,L).
L = [period].

7 ?- follow(literal,L).
L = [comma, period].

8 ?- follow(predicate,L).
L = [comma, period].

9 ?- follow(arglist,L).
L = [rparen].

10 ?- follow(arg,L).
L = [comma, comparison, period, rparen].


3 ?- predictiveParsingTable(M).
----------------------------------------
Predictive Parsing Table
----------------------------------------
M[arg,number] = [arg, [number]]
M[arg,string] = [arg, [string]]
M[arg,variable] = [arg, [variable]]
M[arglist,number] = [arglist, [arg]]
M[arglist,string] = [arglist, [arg]]
M[arglist,variable] = [arglist, [arg]]
M[arglist,number] = [arglist, [arg, comma, arglist]]
M[arglist,string] = [arglist, [arg, comma, arglist]]
M[arglist,variable] = [arglist, [arg, comma, arglist]]
M[ddb,name] = [ddb, [idbrules, dollar]]
M[idbbody,notop] = [idbbody, [literal]]
M[idbbody,name] = [idbbody, [literal]]
M[idbbody,number] = [idbbody, [literal]]
M[idbbody,string] = [idbbody, [literal]]
M[idbbody,variable] = [idbbody, [literal]]
M[idbbody,notop] = [idbbody, [literal, comma, idbbody]]
M[idbbody,name] = [idbbody, [literal, comma, idbbody]]
M[idbbody,number] = [idbbody, [literal, comma, idbbody]]
M[idbbody,string] = [idbbody, [literal, comma, idbbody]]
M[idbbody,variable] = [idbbody, [literal, comma, idbbody]]
M[idbrule,name] = [idbrule, [name, lparen, arglist, rparen, implies, idbbody, period]]
M[idbrules,name] = [idbrules, [idbrule]]
M[idbrules,name] = [idbrules, [idbrule, idbrules]]
M[literal,notop] = [literal, [notop, predicate]]
M[literal,number] = [literal, [predicate]]
M[literal,string] = [literal, [predicate]]
M[literal,variable] = [literal, [predicate]]
M[literal,name] = [literal, [predicate]]
M[predicate,number] = [predicate, [arg, comparison, arg]]
M[predicate,string] = [predicate, [arg, comparison, arg]]
M[predicate,variable] = [predicate, [arg, comparison, arg]]
M[predicate,name] = [predicate, [name, lparen, arglist, rparen]]