[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

simple lisp language design

snrh4x0r

12/22/2015 10:16:00 PM

I'm trying to design a simple language that name is smile which is similar to lisp. I have written its lexer. Nevertheless, I don't have any idea to write its parser. It is really hard for me. I need help about it.

As simple input, if I have `( + 9 10 )` It gives as output about my lexer

Tokens:
Operator_(
Operator_+
VALUE_INT_9
VALUE_INT_10
Operator_)
Identifiers:

I don't have any idea about writing parser. I saw there some parser generators but they look really professional solutions. Don't they? Can someone help me?
Some simple parser rules:

http://i.stack.imgur.com...


Simple output should be for parser as input `(+ 9 10)`

START-> INPUT -> EXP
-> EXPI
-> (+ EXPI EXPI)
-> (+ EXPI Id)
-> (+ Id Id)
8 Answers

Kaz Kylheku

12/22/2015 10:33:00 PM

0

On 2015-12-22, snrh4x0r@gmail.com <snrh4x0r@gmail.com> wrote:
> I'm trying to design a simple language that name is smile which is
> similar to lisp. I have written its lexer. Nevertheless, I don't have
> any idea to write its parser. It is really hard for me. I need help
> about it.
>
> As simple input, if I have `( + 9 10 )` It gives as output about my
> lexer
>
> Tokens:
> Operator_(

You're wrong right off the bat with the terminology, which could point
to incorrect thinking.

Parentheses aren't operators in Lisp. They are, effectively,
punctuation.

> Operator_+

+ is a token which converts to a symbol, in anything that can be
reasonably called a member of the Lisp family of languages.

The role of of a symbol as "operator", or any other role, is determined
by what *binding* that symbol has, in some environment. That is all
semantics, nothing to do with parsing.

> VALUE_INT_9
> VALUE_INT_10
> Operator_)
> Identifiers:
>
> I don't have any idea about writing parser.

That predicament is convenient, because it goes perfectly
hand-in-hand with not really needing one.

Common Lisp is parsed entirely by character dispatch tables, and
some supporting routines. As in, in an nutshell, when we see this
character, or this pair of characters, call this function.

In Lip's read table there is an entry for the ( character. It
dispatches a function which keeps reading objects (via a recursive call
to the reader), while peeking at the next character in the stream. If
the lookahead character in the stream is a closing ) then it returns the
list of objects it has scanned so far.

And that's basically how the whole nested structure is read, like

(a b c (d e (f g) . h))

Ah, except for specially handling that dot! I lied! The function also
peeks whether there is a consing dot, and handles that case.

snrh4x0r

12/22/2015 10:56:00 PM

0

Can someone share some example code related to the rules in java?

Kaz Kylheku

12/22/2015 11:02:00 PM

0

On 2015-12-22, snrh4x0r@gmail.com <snrh4x0r@gmail.com> wrote:
> Can someone share some example code related to the rules in java?

Yeah that, whatsisname, Doo Hickey guy probably can.

Pascal J. Bourguignon

12/23/2015 12:45:00 AM

0

snrh4x0r@gmail.com writes:

> Can someone share some example code related to the rules in java?

ja-what?

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Richard Fateman

12/23/2015 1:58:00 AM

0

This is the kind of thing that you would learn in a course,
or from a textbook for a course, on programming languages
and compilers. What text do you have available?
If you do not have one, why not find a text, instead of asking
people to type the text into the newsgroup piece by piece?

Also, if your language is simple and similar to lisp,
I suggest you write an interpreter, in lisp, for it.

The output for the lex/parse could be the lisp program to execute.
And so you have the rest of the language (the semantics) free.




On 12/22/2015 2:15 PM, snrh4x0r@gmail.com wrote:
> I'm trying to design a simple language that name is smile which is similar to lisp.

Barry Margolin

12/23/2015 4:51:00 PM

0

In article <20151222142500.445@kylheku.com>,
Kaz Kylheku <kaz@kylheku.com> wrote:

> On 2015-12-22, snrh4x0r@gmail.com <snrh4x0r@gmail.com> wrote:
> > I'm trying to design a simple language that name is smile which is
> > similar to lisp. I have written its lexer. Nevertheless, I don't have
> > any idea to write its parser. It is really hard for me. I need help
> > about it.
> >
> > As simple input, if I have `( + 9 10 )` It gives as output about my
> > lexer
> >
> > Tokens:
> > Operator_(
>
> You're wrong right off the bat with the terminology, which could point
> to incorrect thinking.

He's not implementing Lisp, he's implementing a language whose syntax is
similar to Lisp. There's no reason why he couldn't treat parentheses and
built-in functions like + as operators in his parser, just like you
might in a C-like language.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

M. Strobel

12/23/2015 5:14:00 PM

0

On 23.12.2015 02:57, Richard Fateman wrote:
> This is the kind of thing that you would learn in a course,

I guess he is attending a course, and the programming assignment woke him up



/Str.

Pascal J. Bourguignon

12/23/2015 11:48:00 PM

0

"M. Strobel" <strobel@example.com> writes:

> On 23.12.2015 02:57, Richard Fateman wrote:
>> This is the kind of thing that you would learn in a course,
>
> I guess he is attending a course, and the programming assignment woke him up

Hence my answer ;-)


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk