[phc-general] Changes in Abstract Grammar
logytech at gmail.com
Mon Oct 18 21:08:12 IST 2010
Nice project. I haven't worked with the AST part of phc, but I think
what you trying to accomplish quite doable. You can start by checking
the phc grammar if you haven't already:
http://www.phpcompiler.org/doc/latest/grammar.html#grammar . Also, if
you want to know more about the challenges of creating the parser, you
can check the techreport from Edsko de Vries, one of the designers of
phc: http://www.cs.tcd.ie/~devriese/pub/phc-frontend.pdf .
On Mon, Oct 18, 2010 at 4:23 PM, Peter <peter5001 at gmx.de> wrote:
> i am a web developer using php on a regular basis. but i must admit that
> i do not know much about the inner working of compilers. i think phc is
> a great project and i hope this is the right place for my question ;-)
I hope so too. (;
> i would like to add some experimental constructs to the grammar of php
> (something like properties in c# or vala). so i wondered if this would
> be possible with phc.
> my idea is to use phc to transform a php script with an extended grammar
> of php into a php script with regular grammar, by replacing non-regular
> constructs with generated code (i.e. by replacing c#/vala-like
> properties with java-bean-like accessor methods and private fields).
> so i sketched the following code transformation chain:
> 1] PHP Script (with extensions to the grammar, i.e. properties)
> ... transformation into an AST using phc ...
> 2] PHC-AST (with extensions to the grammar, i.e. properties)
> ... replacement of non-regular constructs with regular code using the
> Tree_transorm API ...
> 3] PHC-AST (regular grammar, i.e. accessor methods & private fields)
> ... transformation into regular php script ...
> 4] PHP Script (regular grammar, i.e. accessor methods & private fields)
That sounds about right. If you extend the grammar, then phc will be
able to parse it. All you got do next is to create a pass that
transforms these new features into regular php constructs by using AST
> i had a look at the source code of phc but as i started to experiment
> with some code in "/generated_src" i couldn't compile phc anymore.
> touching these files yields to an "permission denied error".
Have you installed maketea before messing with these files? You can
check more about maketea on the phc manual:
> as you can see i dont know much about c++, makefiles and stuff like
> that. but i would like to learn more about these things if my idea above
> could be realized at all. so here is the actual question:
This could be a hassle, since phc is mostly written in C++.
> would it be possible to extend the syntax/grammar of phc
> (/generated_src/php_scanner.lex & /generated_src/ast.tea ???) in order
> to make such transformations (properties -> accessor methods)?
> if yes, could you give me some hints? how would you do this?
I believe you can, but I can't be much of a helper. I haven't worked
with yacc/bison (I don't even know if phc use them at all) neither
with maketea. However I think you're in the right path, you'll need to
modify these files in order to augment phc with those features. Maybe
checking the php_parser.ypp as well?
> any help is much appreciated!
> thank you very much!
> sorry for my bad english,
More information about the phc-general