dcg Questions
1
Solved
I wanna learn something more about Definite Clause Grammar in Prolog and I'm searching some book and tutorial online.
I've already saw something on "Learn Prolog Now", "The art of Prolog" a...
2
Solved
I'm trying to learn more about DCGs in Prolog and while reading through different sources, I noticed that in some cases phrase wasn't being used ?
From the Learn Prolog Now website, it presents th...
2
let's say I had the following context free grammar.
S -> A
A -> mAn
A -> o
How would this look in prolog? This is what I tried but it doesn't work. The second line seems to be the issue...
Ecospecies asked 30/11, 2015 at 19:26
4
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 cod...
Nila asked 12/5, 2015 at 22:29
2
What does the --> operator do in Prolog and what is the difference between it and :-?
I'm using SWI Prolog.
3
Solved
I am a newbie in Prolog, and I am trying to understand how a grammar can be translated into a normal definite clause from a DCG.
I understood that DCG notation is just syntactic sugar for normal de...
3
List is the list of values in leaf nodes of a binary tree and I am trying to figure out how to output just that. This is giving me all the nodes but I need just the leaves.
lea(nil,[]).
lea(t(X,L...
Afire asked 31/3, 2015 at 10:13
4
Can I get a recursive Prolog predicate having two arguments, called reverse, which returns the inverse of a list:
Sample query and expected result:
?- reverse([a,b,c], L).
L = [c,b,a].
A recur...
Monti asked 22/6, 2011 at 15:47
2
Solved
I want to parse a logical expression using DCG in Prolog.
The logical terms are represented as lists e.g. ['x','&&','y'] for x ∧ y the result should be the parse tree and(X,Y) (were X and ...
3
Solved
Taking an example from the Introduction to Latin Wikiversity, consider the sentence:
the sailor gives the girl money
We can handle this in Prolog with a DCG fairly elegantly with this pile of ru...
4
Solved
Is there a way to check if a string is a substring of another string in Prolog? I tried converting the string to a list of chars and subsequently checking if the first set is a subset of the second...
Dow asked 27/11, 2013 at 18:40
3
Solved
Consider the following extension to context-free grammars that permits rules to have in the left-hand side, one (or more) terminal on the right side of the non-terminal. That is, rules of the form:...
Bespread asked 22/8, 2012 at 11:20
3
Solved
I'm blocking on a predicate to code in Prolog. I need to code that two predicates:
If I call : u([a,b,c,d,e,f], X). it will give X=[a,b], X=[b,c], X=[c,d] ...
If I call : v([a,b,c,d,e,f], X). it ...
1
Solved
I'm working with Prolog arithmetic and have a program that generates an abstract syntax tree, such as plus(num(1),num(2)) which simply is 1+2. This is done by using DCG. In this example plus(num(1)...
Scribe asked 13/11, 2013 at 16:53
2
Solved
I want to create a DCG that languages like this get accepted:
c
bbbcbbb
bbacbba
abacaba
aababacaababa
As you can see this means that there is a specific order of a and b, then one c and then ag...
Purl asked 11/2, 2014 at 13:36
3
Solved
I am trying to understand the use of DCGs better. In order to do this, I tried to translate some exercises in the LearnPrologNow book to DCG notation. However, I am failing miserably.
What I tried...
3
Solved
This question refers to the material in chapter 3 of the book:
Programming in Prolog, Clocksin and Mellish, Ed 5
In page 72 of this book, a program using difference list is displayed:
partsOf(X,...
Ostracod asked 21/1, 2014 at 18:29
2
Solved
I'm new to prolog, so this's quite a challenge to me.
I'm supposed to implement a simple C like language in Prolog.
the ultimate goal is to be able to execute something like this:
?- run([begin,a,...
Deane asked 17/12, 2013 at 10:28
1
Solved
I want to make an arithmetic solver in Prolog that can have +,-,*,^ operations on numbers >= 2. It should also be possible to have a variable x in there. The input should be a prefix expression in ...
Freehand asked 11/11, 2013 at 21:38
1
Solved
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...
2
I often end up writing code in Prolog which involves some arithmetic calculation (or state information important throughout the program), by means of first obtaining the value stored in a predicate...
Sully asked 25/9, 2013 at 12:33
1
Solved
I'm new to Prolog, and I'm trying to write a small program that will give a random sentence from a DCG.
My previous way of thinking was to use findall/3 to make a list of all possible sentences, a...
4
Solved
As part of a project I need to write a parser that can read a file and parse into facts I can use in my program.
The file structure looks as follows:
property = { el1 , el2 , ... }.
What I wa...
Cotquean asked 24/12, 2012 at 16:50
2
Solved
I was reading the answer to this question,
p(X) :- read(A), q(A,X-[]).
q(end,X-X) :- !.
q(A,[A|X]-Y) :- read(B), q(B,X-Y).
The code above uses the syntax List-List. I somewhat understand what...
Thunell asked 16/3, 2013 at 23:38
1
Solved
Using the development version of SWI Prolog (Win x64),
I wrote a DCG predicate for a deterministic lexer (hosted on github) (thus all external predicates leave no choice points):
read_token(parser...
Zephyr asked 15/3, 2013 at 13:16
© 2022 - 2024 — McMap. All rights reserved.