Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end From: Hans Aberg Newsgroups: comp.compilers Subject: Re: I have managed to parse and evaluate using an AST. I got stuck in statements and block Date: Fri, 20 Feb 2015 15:47:38 +0100 Organization: A noiseless patient Spider Lines: 23 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <15-02-030@comp.compilers> References: <15-02-027@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: miucha.iecc.com 1424531057 19728 2001:470:1f07:1126:0:676f:7373:6970 (21 Feb 2015 15:04:17 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sat, 21 Feb 2015 15:04:17 +0000 (UTC) Keywords: interpreter Posted-Date: 21 Feb 2015 10:04:16 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1532 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 . 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 , 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.