From: CHEN Guang on
Hi Peter,
In PythoidC, I handled C header files (and other C files for INCLUDE) with Python regular expression (RE).
First, I use the following RE to break C header files or C files into pieces
sepRE=_re.compile(r'\; | \{ | \} | // | /\* | \*/ | \r?\n',_re.VERBOSE)
Then, I carefully designed a loop testing each of the seperaters between adjacent pieces
for sep in sepRE.finditer(f0c):
...
if sg==';':
cItems.append(f0c[span0:ss1].strip())
span0 = ss1
...
to reassemble several (may be one) consequent pieces into items (a function, a struct, a constant ...)
At last I classify the items with some REs like
structRE=_re.compile(r'^(struct\s+([0-9A-Za-z_]+)\s*\{.+\}.*\;)$',_re.IGNORECASE|_re.DOTALL)
and arranged the items into Python objects with setattr(...)
You can download and read the source code of PythoidC at http://pythoidc.sf.net or http://pythoidc.googlecode.com
If you feel PHP not good enough, I'd like to suggest Python ( www.python.org ). Python is really an excellent language, with Python you can program softwares for almost any porpose (except for hardware drivers and some software with very high requirement of speed, now PythoidC is just the extension for Python in such areas ).
Welcome to join the Python mailing list http://mail.python.org/mailman/listinfo/python-list to discuss Python techniques, there are many warm-hearted friends willingly to answer almost any questions.
By the way, I work in China Medical University, Shenyang, northeast China. Will you tell me something about youself?
Best Regards,
ChenGuang

2010-04-09 22:24:27£¬"Peter West" <peterjwest3(a)googlemail.com> £º


Hi Chen,


My project uses a tree structured linked list to break down PHP into chunks, It was necessary because PHP has a lot of syntaxes for strings. Some parts of the language like one line comments and heredocs were quite a lot of trouble. How have you handled the pre-processor? I briefly considered modifying my project for C but the pre-processor's features would be difficult to handle. I'll try to find you an example.


What other features would you like to add? In PHP I'm trying to add some useful syntaxes such as calling an index of an array without assigning the array to a variable e.g. $object->getArray()[0]. Another is instantiating an object and using it in the same statement e.g. ($object new Class)->method(). Unfortunately PHP is not a very good language and there are only a few things I can change about it.


Peter.




2010/4/9 CHEN Guang <dr.cg(a)126.com>

Dear Peter,
I am the developer of PythoidC (braceless and semicolonless C language). I am so glad to see your message, just like a message from Voyager 2 spacecraft, telling me that I am nolonger alone in the universe!
My plan is to release new versions of PythoidC from time to time, adding new applications and more examples.
My hope is that our ideal (braceless and semicolonless) will be shared by more people in the world, thus lead to the simplification of all computer languages (Java, Perl ...)
Let's talk often.
ChenGuang




 | 
Pages: 1
Prev: getopt question
Next: ANN: obfuscate 0.2.2