News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sankuru Blog:
Adding support for if/while/do while, to a simple compiler & virtual machine in PHP
January 04, 2012 @ 11:40:22

Improving on his last post about creating a bytecode compiler in PHP, the Sankuru blog has a new post in the series looking at extending the basic compiler to add support for if/while and do while logic.

In order to obtain a turing-complete programming language, that is, a language in which we can implement and execute any arbitrary algorithm, that is, that other turing-complete machines can execute too, we now need to add a way of (conditionally) branching, that is, the IF statement, and at least one way of repeating statements, that is the WHILE or the DO WHILE statements.

He includes a simple TL-based script as an end goal for the compiler to be able to execute and shows how to add rules for it to the lexer/parser. Rules for the "if" are relatively simple, but there's a hitch in dealing with embedded "while" statements he had to work around. The post ends with the bytecode results for the sample program and the resulting output from the compiled versions execution.

0 comments voice your opinion now!
bytecode compiler virtual machine while if whiledo logic


blog comments powered by Disqus

Similar Posts

PHPMaster.com: From Zero to Cloud: Setting up an EC2 Sandbox, Part 3

7PHP.com: Win (TWO) Free Tickets To Hear Rob Allen Introduce Zend Framework 2 (Nomad PHP)

Alex Netkachov's Blog: Installing Debian Web-server with Apache, PHP, and MySQL on virtual machine

PHPMaster.com: Learning Loops

LoLoCoJr Blog: Rewriting a (large) PHP application in Rails, part 2


Community Events





Don't see your event here?
Let us know!


opinion introduction deployment series community language framework api zendserver interview podcast release unittest voicesoftheelephpant bugfix library laravel symfony package install

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework