Dear Internals
At the moment I'm very inspired by functional programming languages
such as SML and especially scala. I would like to create and
alternative PHP syntax, just for fun nothing serious, inspired by
these languages. I've managed to compile PHP with debug stuff turned
on and found some files called zend_language_scanner.l,
zend_language_parser.y and did succed with creating an alias for
"function" called "def". I now wanted to change the function
definition into something more scala looking:
def max($x, $y) = {
if ($x > $y) return $x else return $y
}
but got completely stuck.
I realised all of a sudden that I really don't understand anything
about what is going on in these files. Not even enough to ask good
questions. What should I do/read/study/buy/etc... ????
Thx in advance from a very confused dude that is in way over his head
Rune Kaagaard
Denmark
Dear Internals
At the moment I'm very inspired by functional programming languages
such as SML and especially scala. I would like to create and
alternative PHP syntax, just for fun nothing serious, inspired by
these languages. I've managed to compile PHP with debug stuff turned
on and found some files called zend_language_scanner.l,
zend_language_parser.y and did succed with creating an alias for
"function" called "def". I now wanted to change the function
definition into something more scala looking:def max($x, $y) = {
if ($x > $y) return $x else return $y
}but got completely stuck.
I realised all of a sudden that I really don't understand anything
about what is going on in these files. Not even enough to ask good
questions. What should I do/read/study/buy/etc... ????Thx in advance from a very confused dude that is in way over his head
Well, in case of php-5.3+ there is partial support for functional
paradigm.
try this:
<?php
$max = function($x, $y) {
if ($x > $y)
return $x;
else
return $y;
};
echo $max(5, 1);
echo $max(4, 99);
?>
Dear Internals
Ok... So i figured out that the way to make a scala style multi line
function declaration was simply to do this:
zend_language_parser.y
unticked_function_declaration_statement:
function is_reference T_STRING
{
zend_do_begin_function_declaration(&$1, &$3, 0, $2.op_type, NULL
TSRMLS_CC); }
'(' parameter_list ')' '=' '{' inner_statement_list '}' {
zend_do_end_function_declaration(&$1 TSRMLS_CC); }
;
PHP
def new_function() = {
echo "It works!\n";
}
But I have been stuck the last couple of hours trying to make support
for a one line function declaration without the '{}'. Example:
def double($x) = return 2 * $x;
I cant seem to find out what token to use for a new line? Any thoughts?
Thx a lot from confused guy
Rune Kaagaard
Denmark
Dear internals
I'm slowly getting to know more about bison and language parsing. A
new world for me. But progress is still slow. I have made an example
of the syntax I am looking to achieve at
http://code.google.com/p/php-alternative-syntax/ . If any of you c
gurus could help me with the best method to attack the problem I would
be very grateful!
Cheers
Rune Kaagaard
Denmark
Hello,
one problem that immediately pops out is that you have a parsing
ambiguity between an argument list and a concatenation of strings as a
single argument.
You should start by producing a BFN version of your desired grammar.
Such errors should then be more apparent.
Best,
Dear internals
I'm slowly getting to know more about bison and language parsing. A
new world for me. But progress is still slow. I have made an example
of the syntax I am looking to achieve at
http://code.google.com/p/php-alternative-syntax/ . If any of you c
gurus could help me with the best method to attack the problem I would
be very grateful!Cheers
Rune Kaagaard
Denmark--
--
Etienne Kneuss
http://www.colder.ch
Hello,
Hello,
one problem that immediately pops out is that you have a parsing
ambiguity between an argument list and a concatenation of strings as a
single argument.You should start by producing a BFN version of your desired grammar.
Such errors should then be more apparent.
*BNF
Also, the scala parser is quite complicated and some of its features
end up being quite tricky grammar-wise, porting scala-like grammars to
PHP would most likely require you to do major rewrites of the grammar,
I'd rather advise you to start with very small grammar changes.
Best,
Best,
Dear internals
I'm slowly getting to know more about bison and language parsing. A
new world for me. But progress is still slow. I have made an example
of the syntax I am looking to achieve at
http://code.google.com/p/php-alternative-syntax/ . If any of you c
gurus could help me with the best method to attack the problem I would
be very grateful!Cheers
Rune Kaagaard
Denmark--
--
Etienne Kneuss
http://www.colder.ch
--
Etienne Kneuss
http://www.colder.ch
Dear Etienne
Wauw did not know Backus–Naur Form before. That looks like a great
first step. Thx for showing me that!
Cheers
Rune Kaagaard
Denmark
Hello,
Hello,
one problem that immediately pops out is that you have a parsing
ambiguity between an argument list and a concatenation of strings as a
single argument.You should start by producing a BFN version of your desired grammar.
Such errors should then be more apparent.*BNF
Also, the scala parser is quite complicated and some of its features
end up being quite tricky grammar-wise, porting scala-like grammars to
PHP would most likely require you to do major rewrites of the grammar,
I'd rather advise you to start with very small grammar changes.Best,
Best,
Dear internals
I'm slowly getting to know more about bison and language parsing. A
new world for me. But progress is still slow. I have made an example
of the syntax I am looking to achieve at
http://code.google.com/p/php-alternative-syntax/ . If any of you c
gurus could help me with the best method to attack the problem I would
be very grateful!Cheers
Rune Kaagaard
Denmark--
--
Etienne Kneuss
http://www.colder.ch--
Etienne Kneuss
http://www.colder.ch
Dear Etienne
Wauw did not know Backus–Naur Form before. That looks like a great
first step. Thx for showing me that!
Cheers
Rune Kaagaard
Denmark
Dear Internals
So I'm making good progress and found out that making simple syntax
changes is quite easy. What I currently got working can be seen here:
http://code.google.com/p/php-alternative-syntax/source/browse/trunk/scripts/kitchensink.php.
However, making functionality changes still baffles me. I changed the
"return" keyword to "<-", and I would like to automatically add a
return on the last line of a function. So that the following PHP code:
<?php
function foo() {
$x = 2;
$x * 2;
}
?>
would return an int with a value of 4.
How should I attack this problem?
Thx a lot!
Rune Kaagaard
Denmark
Hello,
Dear Internals
So I'm making good progress and found out that making simple syntax
changes is quite easy. What I currently got working can be seen here:
http://code.google.com/p/php-alternative-syntax/source/browse/trunk/scripts/kitchensink.php.However, making functionality changes still baffles me. I changed the
"return" keyword to "<-", and I would like to automatically add a
return on the last line of a function. So that the following PHP code:<?php
function foo() {
$x = 2;
$x * 2;
}
?>would return an int with a value of 4.
How should I attack this problem?
This will be tricky to implement as you've to check if the last
statement of the function represents a value or not as Scala does, and
a lot of statements in PHP have no values: switch/while/for/if...
So function a() {
if(true) .. else ..;
}
would have to implicitely return null, since if() is not a value.
Thx a lot!
Rune Kaagaard
Denmark--
--
Etienne Kneuss
http://www.colder.ch