# Hacking language syntax

- Thread: https://externals.io/message/47087
- Original archive: https://news-web.php.net/php.internals/47087
- Started by Vsevolod Velichko on 2010-03-05T00:31:23+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #47087 — Vsevolod Velichko — 2010-03-05T00:31:23+00:00

URL: https://externals.io/message/47087#47087

Hello, Internals!

I wish to add some syntax to PHP (at first, I want to modify `while`
loop, to implement Dijkstra loop) and I've found some old thread about
modifying core, but I have no idea, how to do it by extension.
I suppose that it possible, since Facebook, as I know, introduced some
constructions in its HipHop. But HipHop is rather complex and aimed to
do incredibly more things, rather than add one construction, so it's
rather hard to study.
I'll be glad if someone tell me what to look at for implementing new
constructions as an extension.

P.s. Please, cc me on reply.

-- 
Best wishes and have a nice day,
Vsevolod Velichko

---

## #47088 — Derick Rethans — 2010-03-05T01:21:11+00:00

URL: https://externals.io/message/47087#47088 · In reply to: #47087

> I wish to add some syntax to PHP (at first, I want to modify `while` 
> loop, to implement Dijkstra loop) and I've found some old thread about 
> modifying core, but I have no idea, how to do it by extension. I 
> suppose that it possible, since Facebook, as I know, introduced some 
> constructions in its HipHop. But HipHop is rather complex and aimed to 
> do incredibly more things, rather than add one construction, so it's 
> rather hard to study. I'll be glad if someone tell me what to look at 
> for implementing new constructions as an extension.

You can't. You need to modify the current engine to add new language 
constructs.

Derick

-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug

---

## #47092 — Rune Kaagaard — 2010-03-06T09:48:43+00:00

URL: https://externals.io/message/47087#47092

The files you want to change in PHP core are the lexer
(http://code.google.com/p/php-alternative-syntax/source/browse/trunk/php-5.3.0/Zend/zend_language_scanner.l)
and the scanner
(http://code.google.com/p/php-alternative-syntax/source/browse/trunk/php-5.3.0/Zend/zend_language_parser.y)
and then recompile.

Unfortunately this approach makes your PHP code incompatible with all
other PHP installations. Furthermore the learning code is _very_ steep
because the files are pretty messy and hardly commented (IMO), which
makes everything but the simplest of changes pretty hard. I walked
down the same road you are now contemplating with
http://code.google.com/p/php-alternative-syntax/ but soon abandoned
the idea :) I collected some information about opcodes and the Zend
core here: http://code.google.com/p/php-alternative-syntax/source/browse/#svn/trunk/documentation
they might be useful for you.

At the moment - being interested in language design - I'm
contemplating building a meta language that compiles down to PHP
instead which would keep things compatible. If you are interested it
is called "snow" and looks like http://pastebin.com/9h1d3RpN .

Cheers
Rune
