Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #1532

Re: I have managed to parse and evaluate using an AST. I got stuck in statements and block

From Hans Aberg <haberg-news@telia.com>
Newsgroups comp.compilers
Subject Re: I have managed to parse and evaluate using an AST. I got stuck in statements and block
Date 2015-02-20 15:47 +0100
Organization A noiseless patient Spider
Message-ID <15-02-030@comp.compilers> (permalink)
References <15-02-027@comp.compilers>

Show all headers | View raw


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.

Back to comp.compilers | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

I have managed to parse and evaluate using an AST. I got stuck in statements and block mehmet.coskun@gmail.com - 2015-02-18 11:20 -0800
  Re: I have managed to parse and evaluate using an AST. I got stuck in statements and block Christian Gollwitzer <auriocus@gmx.de> - 2015-02-19 10:22 +0100
  Re: I have managed to parse and evaluate using an AST. I got stuck in statements and block BartC <bc@freeuk.com> - 2015-02-19 21:51 +0000
    Re: I have managed to parse and evaluate using an AST. I got stuck in statements and block BartC <bc@freeuk.com> - 2015-02-21 20:52 +0000
      Re: I have managed to parse and evaluate using an AST. I got stuck in statements and block mehmet.coskun@gmail.com - 2015-03-05 18:53 -0500
  Re: I have managed to parse and evaluate using an AST. I got stuck in statements and block Hans Aberg <haberg-news@telia.com> - 2015-02-20 15:47 +0100

csiph-web