From: ········@yahoo.com
Subject: Non-Lisp like DSL implemented in Common Lisp
Date: 
Message-ID: <1123613040.148725.279240@g49g2000cwa.googlegroups.com>
Dear Lispers,

I come to you with a question about how to "implement" languages
(general purpose or domain specifc) in Common Lisp.  All the examples I
have seen so far (or read of), essentially create new languages by
extending the Common Lisp language, as if creating new macros and
functions.  So essentially the newly created language resembles Lisp in
its syntax, i.e., full of parentheses.  What comes to memory right now
is, of course, Common Lisp itself, aswell as the initial bootstrap of
the T system, and Rainer Joswig's recent examples.

What I am curious is how to go a bit further and create a language that
has nothing to do, syntatically speaking, with Lisp.  This would
involve lexical and sytactical considerations that I, in my limited
experience, have not read so far.  Now, truly, I do not have in my mind
nothing as complex as creating a full-blown interpreter for a general
purpose language, so I would tend to be more interested in using Common
Lisp to give the semantics for a DSL (or "little language") or even a
simple scripting language with the above syntatical characteristics.

I used "implement" above in a definitively naive way: while the most
obvious goal would be to create a interpreter for such language,
acutally, the same reasoning could be used to create any tool at all,
such as a compiler, pretty-printer, or to perform a more complex
analysis, of course.

So, if anybody on this great group has any practical example of this, I
kindly ask you, if it is public, to give me a pointer to the work.
Also, general considerations those who have never done this is also
very much welcome.  I am particularly interested on how the following
items were dealt (or would be dealt with) in Common Lisp: (i) lexical
and grammatical aspects; (ii) how to define the actual semantics of the
language; (iii) how to report errors to the end user on the *correct*
domain and not just dumping an internal lisp compiler backtrace.

Thanks a lot,
JMR

From: ········@gmail.com
Subject: Re: Non-Lisp like DSL implemented in Common Lisp
Date: 
Message-ID: <1123614515.750343.314190@g47g2000cwa.googlegroups.com>
········@yahoo.com wrote:
> Dear Lispers,
>
>
> So, if anybody on this great group has any practical example of this, I
> kindly ask you, if it is public, to give me a pointer to the work.
> Also, general considerations those who have never done this is also
> very much welcome.  I am particularly interested on how the following
> items were dealt (or would be dealt with) in Common Lisp: (i) lexical
> and grammatical aspects; (ii) how to define the actual semantics of the
> language; (iii) how to report errors to the end user on the *correct*
> domain and not just dumping an internal lisp compiler backtrace.

does the loop macro count?  And I think all the lisp macchiens
compilers were written in lisp, they had C and I think ADA83 , possibly
others.

marc


> 
> Thanks a lot,
> JMR
From: Joe Marshall
Subject: Re: Non-Lisp like DSL implemented in Common Lisp
Date: 
Message-ID: <3bpikiy1.fsf@ccs.neu.edu>
········@yahoo.com writes:

> Dear Lispers,
>
> I come to you with a question about how to "implement" languages
> (general purpose or domain specifc) in Common Lisp.  All the examples I
> have seen so far (or read of), essentially create new languages by
> extending the Common Lisp language, as if creating new macros and
> functions.  So essentially the newly created language resembles Lisp in
> its syntax, i.e., full of parentheses.  What comes to memory right now
> is, of course, Common Lisp itself, aswell as the initial bootstrap of
> the T system, and Rainer Joswig's recent examples.

Yes.  That's the point.

> What I am curious is how to go a bit further and create a language that
> has nothing to do, syntatically speaking, with Lisp.  This would
> involve lexical and sytactical considerations that I, in my limited
> experience, have not read so far.  Now, truly, I do not have in my mind
> nothing as complex as creating a full-blown interpreter for a general
> purpose language, so I would tend to be more interested in using Common
> Lisp to give the semantics for a DSL (or "little language") or even a
> simple scripting language with the above syntatical characteristics.

This is simply a matter of parsing.  There are several parser
generators for Lisp, or you could hack up a LEX/YACC parser to emit
parenthesized output.  The parser emits an abstract syntax tree (AST).
The easiest way to deal with this is to have each node in the AST
correspond to a lisp function or macro.  Then you simply run the AST
through the lisp compiler.


But there is little advantage in doing this.  It is unlikely that your
custom syntax will be as flexible as the underlying lisp.  You won't
have macros.  Anyone wishing to extend your language would have to
learn *two* syntaxes.  And you go through a hell of a lot of work in
order to reach this syntactic dead-end.

> I used "implement" above in a definitively naive way: while the most
> obvious goal would be to create a interpreter for such language,
> acutally, the same reasoning could be used to create any tool at all,
> such as a compiler, pretty-printer, or to perform a more complex
> analysis, of course.
>
> So, if anybody on this great group has any practical example of this, I
> kindly ask you, if it is public, to give me a pointer to the work.
> Also, general considerations those who have never done this is also
> very much welcome.  I am particularly interested on how the following
> items were dealt (or would be dealt with) in Common Lisp: (i) lexical
> and grammatical aspects; (ii) how to define the actual semantics of the
> language; (iii) how to report errors to the end user on the *correct*
> domain and not just dumping an internal lisp compiler backtrace.

Your best bet is to look at the Language support in PLT Scheme.  There
is an example of Algol 60 and Java built on the underlying Scheme
system.
From: Pascal Bourguignon
Subject: Re: Non-Lisp like DSL implemented in Common Lisp
Date: 
Message-ID: <87d5omoq9s.fsf@thalassa.informatimago.com>
········@yahoo.com writes:
> What I am curious is how to go a bit further and create a language that
> has nothing to do, syntatically speaking, with Lisp.  This would
> involve lexical and sytactical considerations that I, in my limited
> experience, have not read so far.  Now, truly, I do not have in my mind
> nothing as complex as creating a full-blown interpreter for a general
> purpose language, so I would tend to be more interested in using Common
> Lisp to give the semantics for a DSL (or "little language") or even a
> simple scripting language with the above syntatical characteristics.

There are a lot of examples. 

A Fortran -> Lisp compiler:
http://www.nhplace.com/kent/Papers/Fortran-to-Lisp.html
sources of f2cl in clocc.

A Quick, Dirty and Ugly BASIC:
http://www.informatimago.com/develop/lisp/small-cl-pgms/index.html

A R4RS scheme:
http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/scheme/impl/pseudo/0.html


Also PAIP contains prolog interpreters and compilers; fetch the sources from:
http://www.norvig.com/paip.html


You might want to use Zebu or lalr to implement the parser.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Wanna go outside.
Oh, no! Help! I got outside!
Let me back inside!
From: Eric Lavigne
Subject: Re: Non-Lisp like DSL implemented in Common Lisp
Date: 
Message-ID: <1123643781.100971.184430@g47g2000cwa.googlegroups.com>
>> What I am curious is how to go a bit further and create a language that
>> has nothing to do, syntatically speaking, with Lisp.  This would
>> involve lexical and sytactical considerations...

>Also PAIP contains prolog interpreters and compilers; fetch the sources from:
>http://www.norvig.com/paip.html

As I recall, the prolog interpreter in PAIP uses Lisp syntax.
From: Robert Dodier
Subject: Re: Non-Lisp like DSL implemented in Common Lisp
Date: 
Message-ID: <1123652707.133888.153890@g49g2000cwa.googlegroups.com>
········@yahoo.com wrote:

> So, if anybody on this great group has any practical example of this, I
> kindly ask you, if it is public, to give me a pointer to the work.

The example that comes to mind is the language of the
Maxima (GPL'd DOE-Macsyma, http://maxima.sf.net) algebra system.
It is an Algol-like language which is parsed to Lisp expressions
of the form ((op) arg_1 ... arg_n). This is the primary Maxima
object type; every Maxima construct, including arithmetic
expressions, function calls, function definitions, if-then-else,
for loops, code blocks, etc., is parsed into the same kind of object.
The evaluator inspects the car of such an expression
and determines what to do with it.

Maxima is essentially a large collection of functions
which operate on expressions of the above form.
One could work directly in Lisp, but frankly that would
be needlessly painful. Maxima and Lisp are well-integrated,
so one can switch easily between the two if one so desires.

There is more that can be said, but I'll let that be enough for now.

For what it's worth,
Robert Dodier
From: Paolo Amoroso
Subject: Re: Non-Lisp like DSL implemented in Common Lisp
Date: 
Message-ID: <873bpiowub.fsf@plato.moon.paoloamoroso.it>
········@yahoo.com writes:

> What I am curious is how to go a bit further and create a language that
> has nothing to do, syntatically speaking, with Lisp.  This would
[...]
> So, if anybody on this great group has any practical example of this, I

You may check these:

  CGOL: Algol-like language that compiles into Common Lisp
  ftp://ftp.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/syntax/cgol/0.html

  GLISP: Alternate syntaxes for Common Lisp
  ftp://ftp.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/syntax/glisp/0.html

  INFIX: Infix reader macro for Common Lisp
  ftp://ftp.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/syntax/infix/0.html

  PARCIL: A Parser for C syntax In Lisp
  ftp://ftp.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/syntax/parcil/0.html


Paolo
-- 
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film
Recommended Common Lisp libraries/tools:
- ASDF/ASDF-INSTALL: system building/installation
- CL-PPCRE: regular expressions
- UFFI: Foreign Function Interface