Related articles |
---|
I have managed to parse and evaluate using an AST. I got stuck in stat mehmet.coskun@gmail.com (2015-02-18) |
Re: I have managed to parse and evaluate using an AST. I got stuck in auriocus@gmx.de (Christian Gollwitzer) (2015-02-19) |
Re: I have managed to parse and evaluate using an AST. I got stuck in bc@freeuk.com (BartC) (2015-02-19) |
Re: I have managed to parse and evaluate using an AST. I got stuck in haberg-news@telia.com (Hans Aberg) (2015-02-20) |
Re: I have managed to parse and evaluate using an AST. I got stuck in bc@freeuk.com (BartC) (2015-02-21) |
Re: I have managed to parse and evaluate using an AST. I got stuck in mehmet.coskun@gmail.com (2015-03-05) |
From: | Hans Aberg <haberg-news@telia.com> |
Newsgroups: | comp.compilers |
Date: | Fri, 20 Feb 2015 15:47:38 +0100 |
Organization: | A noiseless patient Spider |
References: | 15-02-027 |
Keywords: | interpreter |
Posted-Date: | 21 Feb 2015 10:04:16 EST |
On 2015/02/18 20:20, mehmet.coskun@gmail.com wrote:
> I am writing a simple interpreter.
> ...I got stuck in implementing statements, code block, if and while statements.
As already pointed out, it easier to use parser generating tools like
Flex and Bison <https://gnu.org/software/bison/>. The latter has a
complete calculator example in for example C++ - easy to start with, and
then modify.
There is no clear distinction between a compiler or an interpreter, as
one can choose the point of execution; an interpreter might decide to
generate compiler code, and then execute it. This is possible with LLVM
<http://clang.llvm.org>, which has examples on how to get started.
As for code blocks and assignments/definitions, one needs a stacked name
look-up table: the lexer checks the name if it is defined on the table,
and if so, returns its correct grammatical type. If there is an inner
block (environment), one pushes a new level on the name table stack,
which is popped when the environment ends. Definitions always creates
names in the current level, whereas assignments write into existing
variables.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.