From: Joel Reymont
Subject: Writing a Pascal translator
Date: 
Message-ID: <1120548432.818923.318260@o13g2000cwo.googlegroups.com>
Folks,

I need to write a translator from a Pascal-like language. Are there
resources on how to do this in Common Lisp? Most permutations of the
lisp, interpreter, compiler, translator search return results about
writing translators, etc. _from_ Lisp.

I'm do not know of any tools like Lex and Yacc for Lisp. Is starting
with a big case for elements of the language and drilling down from
there my best option?

    Thanks, Joel

From: Rainer Joswig
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <BEF00E3D.FABB%joswig@lisp.de>
Am 05.07.2005 9:27 Uhr schrieb "Joel Reymont" unter <······@gmail.com> in
························@o13g2000cwo.googlegroups.com:

> Folks,
> 
> I need to write a translator from a Pascal-like language. Are there
> resources on how to do this in Common Lisp? Most permutations of the
> lisp, interpreter, compiler, translator search return results about
> writing translators, etc. _from_ Lisp.
> 
> I'm do not know of any tools like Lex and Yacc for Lisp. Is starting
> with a big case for elements of the language and drilling down from
> there my best option?
> 
>     Thanks, Joel
> 

This will likely not be of much help, but anyway. Genera ha(s|d)
a full infrastructure for this including C, Pascal and Fortran
compilers written in Lisp.
From: Joel Reymont
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <1120551695.564695.194080@z14g2000cwz.googlegroups.com>
The language I want to translate is EasyLanguage used by Omega
Research's TradeStation product. It's a Pascal-like language used to
design trading systems.

I did a search in this group as well as google and I actually found an
example of a Basic translator and a tokenizer in Lisp. Maybe it's just
me but the code looked quite hairy :D.
From: Mike
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <2Vuye.24198$B_3.17207@fe05.lga>
On 2005-07-05, Joel Reymont <······@gmail.com> wrote:
> The language I want to translate is EasyLanguage used by Omega
> Research's TradeStation product. It's a Pascal-like language used to
> design trading systems.
>
> I did a search in this group as well as google and I actually found an
> example of a Basic translator and a tokenizer in Lisp. Maybe it's just
> me but the code looked quite hairy :D.
>

What do you want to translate it to?

Mike
From: Joe Marshall
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <d5pxl1kn.fsf@comcast.net>
"Joel Reymont" <······@gmail.com> writes:

> Folks,
>
> I need to write a translator from a Pascal-like language. Are there
> resources on how to do this in Common Lisp? Most permutations of the
> lisp, interpreter, compiler, translator search return results about
> writing translators, etc. _from_ Lisp.
>
> I'm do not know of any tools like Lex and Yacc for Lisp. Is starting
> with a big case for elements of the language and drilling down from
> there my best option?

Depending on your ultimate goals, you might try getting a non-lisp
parser to emit a fully-parenthesized syntax tree and then just reading
that into lisp.  (For example, I adapted Edward Willink's fog parser to
translate C++ to S-expressions.  
   http://home.comcast.net/~prunesquallor/fog.zip
)

It isn't a single-tool solution, but it can get your project moving
past the icky parsing point.

-- 
~jrm
From: Pascal Bourguignon
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <874qb9wmdh.fsf@thalassa.informatimago.com>
"Joel Reymont" <······@gmail.com> writes:
> I need to write a translator from a Pascal-like language. Are there
> resources on how to do this in Common Lisp? Most permutations of the
> lisp, interpreter, compiler, translator search return results about
> writing translators, etc. _from_ Lisp.
>
> I'm do not know of any tools like Lex and Yacc for Lisp. Is starting
> with a big case for elements of the language and drilling down from
> there my best option?

There are several parser generators: zebu, cl-yacc, lalr, etc

For the scanner, either you use the basic regexp provided either by
these packages or your common lisp implementation, or you implement it
by hand. AFAIK, there's nothing as fancy as lex or flex, but this
should not be a problem when you've got a "simple" language.


If it's really Pascal-like, then it should be parseable easily with a
recursive decend parser, so you'd not even need a parser generator: a
couple of macros should be able to generate the recursive parsing
functions directly from the grammar rules.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The rule for today:
Touch my tail, I shred your hand.
New rule tomorrow.
From: ·······@gmail.com
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <1120593864.447532.197950@g49g2000cwa.googlegroups.com>
Joel Reymont wrote:
> Folks,
>
> I need to write a translator from a Pascal-like language. Are there
> resources on how to do this in Common Lisp? Most permutations of the
> lisp, interpreter, compiler, translator search return results about
> writing translators, etc. _from_ Lisp.
>
> I'm do not know of any tools like Lex and Yacc for Lisp. Is starting
> with a big case for elements of the language and drilling down from
> there my best option?
Henry Baker's "Pragmatic Parsing in Common Lisp". ACM Lisp Pointers 4,
2 (Apr-Jun 1991), 3-15.
Author's Summary: "If you have Common Lisp, you shouldn't need to hack
Unix 'lex' and 'yacc'."

http://home.pipeline.com/~hbaker1/Prag-Parse.html or
http://home.pipeline.com/~hbaker1/Prag-Parse.ps.gz
From: Edi Weitz
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <umzp1modz.fsf@agharta.de>
On 5 Jul 2005 00:27:12 -0700, "Joel Reymont" <······@gmail.com> wrote:

> I need to write a translator from a Pascal-like language. Are there
> resources on how to do this in Common Lisp?

Huh?  I thought you were doing your stuff in Erlang now?  Just
curious...

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Eric Lavigne
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <1120568227.537205.250790@g14g2000cwa.googlegroups.com>
>Huh?  I thought you were doing your stuff in Erlang now?  Just
>curious...
>
>Cheers,
>Edi.

Erlang will be assimilated.
Resistance is futile.

http://common-lisp.net/project/erlisp/
From: Joel Reymont
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <1120572269.046869.99800@g49g2000cwa.googlegroups.com>
Mike, I would translate it into Lisp for now.

Edi, that was a different project. A poker server (cluster) project
that I finished. Erlang is not particularly high-performance, though,
and would not be suitable for writing neural networks or financial
models that analyze large volumes of data. This is why I'm back to
Lisp.

Pascal, I'll need to look into recursive descent parsers.
From: Paul Tarvydas
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <WN2dnfiCm9LiUlffRVn-vw@rogers.com>
Joel Reymont wrote:

> Pascal, I'll need to look into recursive descent parsers.

I suspect that you find fewer scanner/parser lib's written in lisp because
lisp already comes with a built-in scanner library (sufficient for scanning
lisp) and "parsing" is covered by the plethora of list operations found in
lisp.

The lisp "reader" is a scanner (aka "tokenizer").  It eats text and creates
lisp tokens - symbols.  

The compiler's "symbol table" is subsumed by lisp's intern function.

If you can live with lisp's syntax conventions, then you (almost) don't need
to do anything - you let the reader slurp text and hand you a list of
symbols.

If you can't live with lisp's syntactic conventions, e.g. in Pascal "a=b+c"
needs to be converted to 5 tokens whereas the lisp reader would convert
this to a single symbol, then you have to write some code (i.e. a
"scanner") that will convert a string of characters into tokens.

Depending on your problem, you might want to add extra info to your tokens,
like line numbers, file name, etc.  In this case, you need to create a
simple struct or class that will hold all the info that makes up a "token".

Lexing and parsing are actually the easiest parts of compiler-writing.

Recursive descent parsing is just the fancy name for the "obvious" solution
to parsing - you just create a bunch of functions that call each other and
try to decide what the sequence of tokens mean, stuff like: 

(case (next-token)
  ('identifier (accept-token)
               (case (next-token)
                 ('lpar (parse-function-call))
                 ('= (parse-assignment))
 ...

Yacc is just a notation that builds a parser that uses a state table instead
of a bunch of functions.  (Yacc also comes with a bunch of theoretical
baggage, if you're into that sort of stuff).

Most people get into trouble writing compilers when they lump all of the
functionality of a compiler into a single wadge of code.  If you chop up a
compiler into a separate scanner, a separate parser, a separate semantic
pass, etc, then the problem becomes manageable.

People tend to get into the wadge-of-code mentality because they use
languages that make it appear to be expensive to call functions and they
use languages that have no concept of closures (which are closely related
to "continuations" in compiler-ese).

In lisp, you can already, naturally, say things like "parse this expression,
and when you hit the end of the expression, call this function" - using
closures.  This is what Yacc brings to C - it will trigger a lump of C code
only when a certain parse has been completed.  [Ironically, Yacc, by
itself, can't parse the C language :-].

A lot of compilering is done using tree manipulation.  The parser builds a
tree, then the successive passes walk the tree and do interesting things to
the tree.  Some compiler tools use functional programming to perform
tree-to-tree transformations as a way of organizing and "keeping simple"
the job of compilering.

Lisp already has tree manipulation built into it (i.e. lists) and it lets
you program in a functional manner when you wish to do so.

When I write a large-ish compiler, I tend to do it in S/SL (a very, very
simple compiler notation) just to keep reminding myself to keep aspects of
the compiler separated.  I've knocked together an S/SL-to-lisp tool for my
own use and have been known to hand it to a few people when asked nicely
(with the usual cavaets about lack of documentation, etc).

Depending on the target language, just rolling up your sleeves and writing
some lisp code for a few days might be all that you need.

pt
From: Joel Reymont
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <1120590088.329523.312150@g49g2000cwa.googlegroups.com>
Paul,

Thank you for your insightful post!

     Joel
From: Pascal Bourguignon
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <87r7ec3h48.fsf@thalassa.informatimago.com>
Paul Tarvydas <········@allstream.net> writes:

> If you can't live with lisp's syntactic conventions, e.g. in Pascal "a=b+c"
> needs to be converted to 5 tokens whereas the lisp reader would convert
> this to a single symbol, then you have to write some code (i.e. a
> "scanner") that will convert a string of characters into tokens.

Not even.  You can assign the "treminating macro char" syntax type to
= and +, and then the lisp reader will parse 5 tokens.

[22]> (progn (defparameter *prt* (copy-readtable))
       (set-macro-character #\= (lambda (stream char) '=) nil *prt*)
       (set-macro-character #\+ (lambda (stream char) '+) nil *prt*)
       (let ((*readtable* *prt*)) (read-from-string "(a=b+c)")))
(A |=| B |+| C) ;
7
[23]> (length *)
5


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

The world will now reboot.  don't bother saving your artefacts.
From: Mike
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <aHwye.12002$302.2329@fe04.lga>
On 2005-07-05, Joel Reymont <······@gmail.com> wrote:
> Mike, I would translate it into Lisp for now.
>
> Edi, that was a different project. A poker server (cluster) project
> that I finished. Erlang is not particularly high-performance, though,
> and would not be suitable for writing neural networks or financial
> models that analyze large volumes of data. This is why I'm back to
> Lisp.
>
> Pascal, I'll need to look into recursive descent parsers.
>

I wrote a yacc/lex interface for EasyLanguage when I was taking
out-of-the-box indicators from tradestation to run in linux directly.
I'm learning lisp now and don't know how I would do the translation
from lisp into lisp.

Good luck. I'm interested in what you come up with.

Mike
From: GP lisper
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <1120588203.d3f076763777432c06156b0ea84b3d6d@teranews>
On Tue, 05 Jul 2005 14:20:54 GMT, <·····@mikee.ath.cx> wrote:
> On 2005-07-05, Joel Reymont <······@gmail.com> wrote:
>> Mike, I would translate it into Lisp for now.
>>
>> Edi, that was a different project. A poker server (cluster) project
>> that I finished. Erlang is not particularly high-performance, though,
>> and would not be suitable for writing neural networks or financial
>> models that analyze large volumes of data. This is why I'm back to
>> Lisp.
>
> I wrote a yacc/lex interface for EasyLanguage when I was taking
> out-of-the-box indicators from tradestation to run in linux directly.

Tradestation is a W32 program.  You needed a sockets interface too?
Or did you have tradestation running in WINE?  There is also a DLL
backdoor into tradestation.


-- 
The LOOP construct is really neat, it's got a lot of knobs to turn!
Don't push the yellow one on the bottom.
From: Joel Reymont
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <1120590207.867097.149140@o13g2000cwo.googlegroups.com>
GP, I'm just translating EasyLanguage so that it does not need to be
rewritten manually. The intent is to be able to use all that large body
of EL code outside of TradeStation.
From: Rene de Visser
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <daebhu$9ri$1@news.sap-ag.de>
"Joel Reymont" <······@gmail.com> wrote in message there my best option?
>
>     Thanks, Joel
>
You might want to use ANTLR.

There is a common lisp version.

I just can't remember where it is, but maybe someone else remembers.

It comes with an example of translating JAVA to Commom Lisp.

There is probably already a grammer similar to what you want on the main
ANTLR site.

Rene.
From: George Neuner
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <2mkoc1djqkllf30a53sdqmsp14ff7j9vu6@4ax.com>
On Tue, 5 Jul 2005 18:12:36 +0200, "Rene de Visser"
<··············@hotmail.de> wrote:

>"Joel Reymont" <······@gmail.com> wrote in message there my best option?
>>
>>     Thanks, Joel
>>
>You might want to use ANTLR.
>
>There is a common lisp version.
>
>I just can't remember where it is, but maybe someone else remembers.
>
>It comes with an example of translating JAVA to Commom Lisp.
>
>There is probably already a grammer similar to what you want on the main
>ANTLR site.

Rene,

It would be great if you could remember - I can't find any reference
to a version written in or targeting Lisp on the ANTLR web site.  

Googling finds an "ANTLR-mode" package for Emacs Lisp - but at a
glance it seems to provide only syntax highlighting for ANTLR files,
not the generator software itself.

The regex libs and YACC-alikes for Lisp are nice but I'd love to have
a Lisp version of ANTLR.  ANTLR uses predicated LL(k) grammars which
are straightforward to embed functions into, and it generates
recursive decent parsers which are much easier to debug than LR state
machines.


George
--
for email reply remove "/" from address
From: Ivan Boldyrev
Subject: Re: Writing a Pascal translator
Date: 
Message-ID: <dg12q2-i2q.ln1@ibhome.cgitftp.uiggm.nsc.ru>
On 9161 day of my life Joel Reymont wrote:
> I'm do not know of any tools like Lex and Yacc for Lisp.

http://www.cliki.net/Text

-- 
Ivan Boldyrev

                                                  Is 'morning' a gerund?