For Programmers: Free Programming Magazines  


Home > Archive > Compilers > October 2007 > Prolog and evaluating expressions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Prolog and evaluating expressions
James Sison

2007-10-04, 10:10 pm

I'm trying to write this prolog interpreter but i encountered a
problem. Let's say i'm evaluating a rule and i found a possible
solution. How will i store my current position in the parse tree of
the rule if i'm going back to it when i backtrack? I'm thinking of
using a stack but then, i have no idea how to use it for this
application. Do you guys have any opinions on the matter?
Nils M Holm

2007-10-05, 7:14 pm

James Sison <the_evil_trembles@yahoo.com> wrote:
> I'm trying to write this prolog interpreter but i encountered a
> problem. Let's say i'm evaluating a rule and i found a possible
> solution. How will i store my current position in the parse tree of
> the rule if i'm going back to it when i backtrack? I'm thinking of
> using a stack but then, i have no idea how to use it for this
> application. Do you guys have any opinions on the matter?


Using a stack or, more generally, recursion is a natural solution to
this problem. It might be best to study one of the tiny Prolog
interpreters that you can find on the Web. In case you are not opposed
to Scheme/LISP, here is a very tiny one:

http://www.t3x.org/sketchy/prog/prolog.html

--
Nils M Holm <nmh@t3x.org> -- http://t3x.org/nmh/

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com