i am a newbie in prolog, i want to read a file which actually contains CLASS Definition - using Prolog DCG Rule. But i am stuck in between now..
My input text (linessample.txt)
class component {
attributes
Real V, I, R;
constraints
V = I * R;
constructors component(V1, I1, R1) {
V = V1; I = I1; R = R1;
}
}
I want to read the above sample text using DCG Rule in prolog... I have written one sample code.. but i am not getting the first word "class" in the output
Code
:- use_module(library(pio)).
%classrule(Z) -->class,letter(X),letters(L),{name(Z,[X|L])}.
classrule(Z) -->"class ",classname(X),"{",{name(Z,X)}.
classname([X|L])-->letter(X),letters(L).
letters([X|L])-->letter(X),!,letters(L).
class-->"class".
letters([])-->[].
letter(X)-->[X], {alpha(X)}.
alpha(X) :- X > 64, X < 91.
alpha(X) :- X > 96, X < 123.
how to run this
phrase_from_file(classrule(Z),'linesample.txt').