dcg

prolog convert numbers into roman numerals

限于喜欢 提交于 2019-11-30 09:13:41
问题 i have this code that converts integers into roman numerals i need to add a function that compares an integer with a roman numeral input and show if it's try or false, for example: roman(v,5). true toroman(0). toroman(N) :- N < 4, put("I"), M is N - 1, toroman(M). toroman(N) :- N = 4, put("I"), put("V"). toroman(N) :- N = 5, put("V"). toroman(N) :- N < 9, put("V"), M is N - 5, toroman(M). toroman(N) :- N = 9, put("I"), put("X"). toroman(N) :- N < 40, put("X"), M is N - 10, toroman(M). toroman

Prolog - Parsing

自闭症网瘾萝莉.ら 提交于 2019-11-30 04:55:27
问题 I'm new to the language prolog and have been given an assignment regarding parsing in prolog. I need some help in solving the problem. In the assingment we have the grammar: Expr ::= + Expr Expr | * Expr Expr | Num | Xer Xer ::= x | ^ x Num Num ::= 2 | 3 | .... a Integer (bigger than 1) ... The token ^ is the same as in math. 5^5 equals 25 . Parse needs to work both ways: a call with an instantiated list to generate an Ast, while a call with an instantiated Ast should generate similar prefix

How is this context free grammar using difference lists in Prolog functioning?

廉价感情. 提交于 2019-11-30 04:09:10
问题 I'm reading this tutorial on context free grammars in Prolog, and they mention at the bottom of the page implementing a context free grammar in Prolog using difference lists, with the following code block included: s(X,Z):- np(X,Y), vp(Y,Z). np(X,Z):- det(X,Y), n(Y,Z). vp(X,Z):- v(X,Y), np(Y,Z). vp(X,Z):- v(X,Z). det([the|W],W). det([a|W],W). n([woman|W],W). n([man|W],W). v([shoots|W],W). It mentions: Consider these rules carefully. For example, the s rule says: I know that the pair of lists

RegEx Parser written in Prolog

╄→尐↘猪︶ㄣ 提交于 2019-11-29 19:15:30
问题 I've been banging my head against the wall on this homework problem for a few hours now. We have to parse a regular expression with Prolog. For the most part, the predicates I have work, but there's a few regular expression and string combos which cause them to run out of stack space in SWI-Prolog. Here's a sample with two of the Regex string combinations, one that works and one that doesn't: star(star(char(a))), [] star(star(char(a))), [a] The first one works and the second one runs out of

Prolog List Plateau

陌路散爱 提交于 2019-11-29 15:03:11
Just got introduced to prolog, trying to get through some simple exercises, but I've been getting kind of stuck on this one. I'm trying to write a program that outputs all the sublists of the input list, where each sublist has length > 1 and it cannot be extended to a larger sublist. It will also output the starting position in the list of the sublist. So a sample output would be | ?- plateau([a,a,b,2,2,2,a+1,a+1,s(1,2)], I, Len). I = 1, Len = 2 ? ; I = 4, Len = 3 ? ; I = 7, Len = 2 ? ; no I'm still pretty confused by the whole declarative thing, and having a lot of trouble switching out of

prolog convert numbers into roman numerals

杀马特。学长 韩版系。学妹 提交于 2019-11-29 14:00:19
i have this code that converts integers into roman numerals i need to add a function that compares an integer with a roman numeral input and show if it's try or false, for example: roman(v,5). true toroman(0). toroman(N) :- N < 4, put("I"), M is N - 1, toroman(M). toroman(N) :- N = 4, put("I"), put("V"). toroman(N) :- N = 5, put("V"). toroman(N) :- N < 9, put("V"), M is N - 5, toroman(M). toroman(N) :- N = 9, put("I"), put("X"). toroman(N) :- N < 40, put("X"), M is N - 10, toroman(M). toroman(N) :- N < 50, put("X"), put("L"), M is N - 40, toroman(M). toroman(N) :- N < 90, put("L"), M is N - 50

Sentence parsing and matching in Prolog

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 12:58:50
I'm trying to create a sentence parser in Prolog. I want the sentence to be parsed into three separate lists that will be matched with a suggested outcome. For example, here's the code I have come up with so far... This is the vocabulary which will be used to parse certain words: det(the). det(a). det(an). noun(cat). noun(boy). noun(girl). noun(grandfather). noun(person). noun(mat). noun(party). noun(book). noun(problem). noun(father). noun(student). noun(golf). noun(conversation). noun(challenge). noun(person). noun(problem). noun(sat). verb(thrives). verb(loves). verb(likes). prep(on). prep

Prolog List Plateau

喜你入骨 提交于 2019-11-28 08:40:58
问题 Just got introduced to prolog, trying to get through some simple exercises, but I've been getting kind of stuck on this one. I'm trying to write a program that outputs all the sublists of the input list, where each sublist has length > 1 and it cannot be extended to a larger sublist. It will also output the starting position in the list of the sublist. So a sample output would be | ?- plateau([a,a,b,2,2,2,a+1,a+1,s(1,2)], I, Len). I = 1, Len = 2 ? ; I = 4, Len = 3 ? ; I = 7, Len = 2 ? ; no I

Sentence parsing and matching in Prolog

依然范特西╮ 提交于 2019-11-28 06:52:17
问题 I'm trying to create a sentence parser in Prolog. I want the sentence to be parsed into three separate lists that will be matched with a suggested outcome. For example, here's the code I have come up with so far... This is the vocabulary which will be used to parse certain words: det(the). det(a). det(an). noun(cat). noun(boy). noun(girl). noun(grandfather). noun(person). noun(mat). noun(party). noun(book). noun(problem). noun(father). noun(student). noun(golf). noun(conversation). noun

Remove Ambiguity in abstract syntax in other to write DCG parser Prolog

大城市里の小女人 提交于 2019-11-28 04:27:35
问题 P => Program K => Block S => Single-command C => Commands E => Expression B => Boolean-expr I => Identifier N > Numeral P ::= K. K ::= begin C end C ::= C1 ; C2 | S S ::= I := E | if (B) then S | if (B) then S1 else S2 | while (B) do S | repeat C until (B) | K | print E E ::= − E | E1 + E2 | E1 − E2 | E1 E2 | E1 div E2 | E1 mod E2 | (E) | I | N B ::= E1 = E2 | E1 > E2 | E1 < E2 | E1 != E2 | not B | B1 and B2 | B1 or B2 | (B) I am supposed to remove ambiguities in E and B so that I can write a