Prolog - Pequeña duda Prolog

 
Vista:

Pequeña duda Prolog

Publicado por Geiger (1 intervención) el 30/10/2006 18:43:28
Tengo una pequeña duda sobre este programa en Prolog pero llevo una semana y no hay manera :S. Os adjunto lo que m piden a ver si alguno tiene idea.

Implement a top-down parser (in Prolog) for the following grammar:
E → T E1
E1 → + T E1 | ε
T → F T1
T1 → * F T1 | ε
F → (E) | a | b | c | d

The grammar rules may be replaced by Prolog facts, e.g.

rule(n(e1),[t(+),n(t),n(e1)]).

replaces the second rule in the grammar, n(e) represents that symbol e is non-terminal and
t(+) represents + is a terminal symbol.
You are required to implement a predicate find(Input,Stack) where Input is the input string
to be parsed and Stack contains the current string still to be parsed (initially n(e) where e
is the main non-terminal). The parser must succeed if the Input string is in the
language, and fails otherwise. The basic action of your predicate is to replace a non-terminal
on the top of the parse stack by the right hand side of the rule defining that non-terminal.
If a terminal symbol lies on top of the stack and matches the element W in front of the
input (first argument of the find predicate), then parsing proceeds by popping W and the
symbol on top of the stack, and considering the next element of the input string. Thus, a
string is accepted when the stack and the current string are empty. Sample calls to your
program are for instance:

?- find([t(+),t(a),t(b)],[n(e)]).
No
?- find([t(a),t(+),t(b)],[n(e)]).
Yes
?-find([t('('),t(a),t(+),t(b),t(')'),t(*),t(c)],[n(e)]).
Yes

Gracias a todos =)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Pequeña duda Prolog

Publicado por David (1 intervención) el 19/02/2012 19:30:59
Buenos dias,
hace tiempo de este post pero espero que te acuerdes ^ ^

Resulta que me han propuesto exactamente el mismo problema, no se de donde lo habran sacado, pero es clavado, y igual que tu llevo dias intentando-lo.

Al final sacaste el programa?

Muchas gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar