University of Alabama
For the language as defined, the middle section of the program,
labeled ``SEMANTIC ALGEBRA'', is not necessary.
If we had extended the language to include
(set var exp), then
we would need it.
However, I will explain it here anyway.
These two rules use Prolog's database to represent the store of the
The access rule says that if there is a rule ``store(Var, Val)'' then
For example, if there is a rules in the database
access(x,Result). would result in
Result = 5.
The update rule is a little more complicated.
Let us examine the second goal first.
assert predicate places its argument into Prolog's
database. In the
update rule, if
executed, then the rule
store(x,3) is placed in the database.
The first goal handles the case where the rule that will be inserted
by the second goal already exists.
retractall predicate removes its argument from the
For example, if
update(x,5) is entered, then any
predicate with a first argument of
x would be removed.
The first thing to do is finish the code for building the AST. You can test this separately. Here is an example execution.
$ swipl Welcome to SWI-Prolog (Multi-threaded, Version 5.2.0) Copyright (c) 1990-2003 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word). ?- ['MP3.pl']. % MP3.pl compiled 0.01 sec, 6,356 bytes Yes ?- num(Result,,). Result = 0 Yes ?- literal(Result, ['#t'],). Result = bool(sc_true) Yes ?- prim(Result,[+],). Result = + Yes ?- literal(Result, , ). Result = num(0) Yes ?- exp(Result, , ). Result = literal(num(5)) Yes ?- exp(Result, ['(', if, '#t', 5, 6, ')'], ). Result = if(literal(bool(sc_true)), literal(num(5)), literal(num(6))) Yes ?-The second thing to do is to finish the code for evaluating the AST. Here is an example execution.
?- exp(P,['(', if, '#t', 5, 6, ')'], ), prog_eval(exp(P), Result). P = if(literal(bool(sc_true)), literal(num(5)), literal(num(6))) Result = 5 Yes ?-
This document was generated using the LaTeX2HTML translator Version 2K.1beta (1.61)
Copyright © 1993, 1994, 1995, 1996,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -split 0 -nonav mp3notes.tex
The translation was initiated by on 2004-04-22