I am trying to parse with prolog:
I need to run a code which recieves a text in the command and parse it depending of the input.
Command cal returns calendar(Month, Year) where month ∈ [1-12] and year ∈ [1-9999]. If there is no month given, it returns the year, if both are not specified return current month and year. Example.
Option1
?- read_sentence(X). |: cal 1 2000 X = calendar(1,2000). Option2
?- read_sentence(X). |: cal 2000 X = calendar(2000).` Option3
?- read_sentence(X). |: cal X = calendar(1,2016). So far I am able to read the sentence, and print it, but I have no idea how to parse or even where to begin.
read_sentence(X) :- get0(C), read_sentence(X, L,C), name(X, L). read_sentence(_, [], X) :- member(X, `.\n\t`), !. read_sentence(X, [C|L], C) :- get0(C1), read_sentence(X, L, C1). Which does:
?- read_sentence(X). |: Hello there X = 'Hello there'.
read_sentence; what should be the result of parsing?cal 1 200The code has to recognize that it has "cal" "number between 1-12" and "number between 1 and 9999" Output:calendar(1,200)