Making your own language

The very first release of PHP was actually little more than a collection of Perl scripts, and, although it was fairly limited by not being a full-blown language in its own right, it was powerful enough to gain quite a following. Things have come full circle now, as PHP is able to be a host to your own mini-language, and this is what we'll be looking at here.

If you've any experience with the back end of PHP, you should be aware that it is made up of four parts: lexical analyser, parser, the Zend Engine, and PHP itself. Of these four, the first two are very closely interrelated and are not noticeable from a user perspective, but they form the key to the whole system. The Zend Engine can be thought of as the executor of the code and also the manager of the system, and the PHP core itself is where all the functions lie. To write our own language, we need to have everything but our own version of the Zend Engine, and this is no easy task: a fair amount of theory is involved, although I have done my best to simplify the system for the sake of learning, and you should really not be attempting this example unless you have a fairly complete grasp of the other topics that have been covered.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Why make your own language? >>

Previous chapter: Games conclusion

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.