dcg Questions
2
Solved
I would like to use DCGs as a generator. As of now, the syntax is
s-->a,b.
a-->[].
a-->a,c.
c-->[t1].
c-->[t2].
b-->[t3].
b-->[t4].
I would like to generate all s where the ...
Christman asked 9/1, 2013 at 15:27
3
Solved
I am trying to compare the lists. Given function(List1,List2) and List1 has length N and List 2 has length M and N>M.
I want to check if any permutation of List2 happens to be the first M characte...
2
Solved
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) ...
Celluloid asked 30/10, 2012 at 0:33
1
Solved
Assume I have the following DCG rule:
factor(X) --> "(", expr(X), ")".
Normally this would be translated to:
factor(X, A, B) :-
[40|C] = A, expr(X, C, D), [41|B] = D.
Wo...
Butterfat asked 27/10, 2012 at 12:54
3
Solved
I'm parsing a fairly simple file format consisting of a series of lines, each line having some space separated fields, that looks like this:
l 0x9823 1
s 0x1111 3
l 0x1111 12
⋮
I'm using SWI-Pro...
Censure asked 17/10, 2012 at 17:19
2
In grammar rules (dcg), there are several predefined constructs: (',')//2 meaning concatenation, ('|')//2 meaning alternation etc. One construct which is supported by several but not all Prolog sys...
Pipeline asked 6/10, 2012 at 9:35
2
Solved
I came up w/ the following code to replace all occurences of Find w/ Replace in Request & put the answer in Result. This is using a DCG, so they are all lists of character codes. The predicate ...
2
Solved
I am trying to do Regular Expression matching. I have all the functions written out, but they are not working as they should. From what I can tell, it has a problem when I try to compare a list.
Fo...
Instructive asked 25/9, 2012 at 2:27
3
I am trying my hands on SWI-Prolog in win xp. I am trying to understand how to split a sentence in Prolog into separate atoms.
Ex : Say I have a sentence like this :
"this is a string"
Is there ...
Amherst asked 20/10, 2010 at 10:36
2
Solved
In the following tutorial: http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/7_3.html
There is the part:
test_parser :- repeat,
write('?? '),
read_line(X),
( c(F,X,[]) | q(F,X,[]) ),
nl...
7
What are the uses of SML in the real word?
Are its practical uses similar to that of Prolog?
1
I need some help in prolog, which is pretty new to me. I have to design a small arithmetic computer. The expression to be evaluated will be represented as a list for example:
?-evaluate([2,+,4,*,...
4
Solved
Does anyone know of any examples of code written in prolog to implement a DSL to generate perl code?
2
Solved
I'm trying to modify a list by search and replace, was wondering how do I search through a list with the search term as a list as well?
Lets say I have a list [1,2,3,4] I want to single out the 2 ...
2
Solved
I am new to Prolog and noticed that ' and " give different behavior, but am curious as to why. Specifically, when loading a file, ?- ['test1.pl']. works, while ?- ["test1.pl"]. doesn't.
Prohibit asked 25/11, 2011 at 4:1
2
Solved
I'm looking for a way to build an Expression Tree in Prolog. I already did some experiments and came up with the following working code (that will only handle constants and the plus expression):
c...
Archenemy asked 19/10, 2011 at 21:25
2
Solved
I've been trying to parse a file containing lines of integers using phrase_from_file with the grammar rules
line --> I,line,{integer(I)}.
line --> ['\n'].
thusly: phrase_from_file(line,'in...
Somme asked 26/7, 2011 at 9:6
2
Solved
From what I understand, in Prolog you capture features while parsing like so:
foo(feature(X)) --> [X], bar.
Is this common when designing DCGs ?
foo(featureA(X), featureB(Y)) --> [X], [...
2
I'm very impressed by Prolog's DCG and how quickly I can produce all the possible structures that fit a particular grammar.
But I'd like to combine this search with other constraints. For example,...
3
Solved
I found this nice snippet for parsing lisp in Prolog (from here):
ws --> [W], { code_type(W, space) }, ws.
ws --> [].
parse(String, Expr) :- phrase(expressions(Expr), String).
expressions(...
Culbertson asked 15/6, 2011 at 13:37
2
Solved
I am having trouble parsing sequences that begin with capital letters into variables using Prolog's DCG notation. For instance, if I have the string
f a X y Z X
and a DCG that parses this string...
1
Solved
The project is about translating semi-natural language to SQL tables. The code:
label(S) --> label_h(C), {atom_codes(A, C), string_to_atom(S, A)}, !.
label_h([C|D]) --> letter(C), letters_o...
2
Solved
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'...
1
Solved
I am trying to make a predicate in order to validate if a given input represents a formula.
I am allowed to use only to propositional atoms like p, q, r, s, t, etc.
The formulas which I have to te...
Cozart asked 16/10, 2010 at 7:46
3
Solved
I have the following simple expression parser:
expr(+(T,E))-->term(T),"+",expr(E).
expr(T)-->term(T).
term(*(F,T))-->factor(F),"*",term(T).
term(F)-->factor(F).
factor(N)-->nat(N)...
© 2022 - 2024 — McMap. All rights reserved.