[phc-general] Changes in Abstract Grammar
Paul Biggar
paul.biggar at gmail.com
Mon Oct 18 22:15:28 IST 2010
Hi Peter,
On Mon, Oct 18, 2010 at 11:23 AM, Peter <peter5001 at gmx.de> wrote:
> 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).
Yes, this is designed to be very easy with phc. I'm not sure what
these properties look like, but even if they were in comments you
could do that pretty easily.
> so i sketched the following code transformation chain:
Yes, this is exactly right. You're using some old terminology so I
guess you've read a tech report or something. Make sure you're using
svn trunk, and have a look at the manual in doc/manual/. But to be a
little more concrete:
> 1] PHP Script (with extensions to the grammar, i.e. properties)
> ... transformation into an AST using phc ...
Add the changes to the parser and lexer (bison and flex) in
src/generated_src/php_parser.ypp and and php_scanner.lex. The lexer is
a bit hairy, so you'd be better off if it only required parser
changes.
> 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 ...
This is really just the one step.
In src/phc.cpp, add a transformation pass at the start of the pass
list to convert it into normal AST. This will be a subclass of
AST::Transform, and there are many examples of this in
src/process_ast/.
> 4] PHP Script (regular grammar, i.e. accessor methods & private fields)
Yes, and you can print the code out as PHP very easily using
--dump=ast or --pretty-print
> 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".
I think I've fixed the permission denied errors in trunk. Make sure
you're using trunk. When you're doing ./configure, look out for this
section:
checking for gengetopt... /opt/local/bin/gengetopt
checking for gperf... /opt/local/bin/gperf
checking for flex... /opt/local/bin/flex
checking for bison... /usr/bin/bison
checking for valgrind... /Users/pbiggar/bin/valgrind
checking for dot... /opt/local/bin/dot
checking for gc... /opt/local/bin/gc
checking for maketea... config/phc_missing maketea
if any of it says phc_missing, you need that tool. I expect you don't
have maketea, which is available at http://maketea.googlecode.com.
You'll need a recent ghc (haskell compiler) to compile it.
> 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:
We've had a few contributions from people who don't know C++. We don't
use a very large amount of the weird C++ stuff, and we wrote it in
quite a Java style (we even garbage collect the compiler).
> 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?
Yes, absolutely. I hope there's enough information here, and feel free
to ask whatever else you need to know.
All the best,
Paul
--
Paul Biggar
paul.biggar at gmail.com
More information about the phc-general
mailing list