Maybe you could get come inspiration from the BASIC interpreter written in Haskell:<div><br></div><div><a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/vintage-basic">http://hackage.haskell.org/cgi-bin/hackage-scripts/package/vintage-basic</a></div>
<div><br></div><div><br><br><div class="gmail_quote">On Tue, Apr 21, 2009 at 2:14 AM,  <span dir="ltr">&lt;<a href="mailto:ajb@spamcop.net">ajb@spamcop.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
G&#39;day all.<div class="im"><br>
<br>
Quoting Giuliano Vilela &lt;<a href="mailto:giulianoxt@gmail.com" target="_blank">giulianoxt@gmail.com</a>&gt;:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- Keeping the whole AST in memory for the evalution phase seems<br>
overkill. Is there a better way?<br>
</blockquote>
<br></div>
In this day and age, it&#39;s not considered overkill to keep an entire<br>
program in memory in a tree form.  Perl 5 does that, for example.<br>
<br>
However, Pascal is simple enough that it can be translated from<br>
within the parser.  Quite a few influential Pascal compilers,<br>
including the simplest ones such as Pascal-P and Pascal-S, and some<br>
not-so-simple ones such as Turbo Pascal, did not even generate an AST,<br>
but compiled straight to P-code or assembly code from within the parser.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- The evalution, I think, would be a set of nice pure mutually<br>
recursive functions that do some pattern matching on the program AST.<br>
I would pass the current stack and heap for those functions to use and<br>
modify. Is the State monad a good fit for this task? Wouldn&#39;t the code<br>
become &quot;too imperative&quot;?<br>
</blockquote>
<br></div>
Interpretation of an imperative language is imperative.  I wouldn&#39;t<br>
worry about it.<br>
<br>
You will probably end up using a few monad transformers, because you<br>
need to need at least I/O and a heap, and quite possibly a symbol<br>
table as well.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Obviously, to evaluate writeln I need to be in the IO monad. Here, my<br>
whole scheme went down. Do I really have to mix my own state (stack,<br>
heap) within the IO monad along my evaluation functions?<br>
</blockquote>
<br></div>
You really need to learn about monad transformers.  Try this for<br>
starters:<br>
<br>
    <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.17.268" target="_blank">http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.17.268</a><br>
<br>
Good luck, and let us know how you go.<br>
<br>
Cheers,<br>
Andrew Bromage<div><div></div><div class="h5"><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>