Jump to content

writing own simple langauge using php


ilikeopensource

Recommended Posts

Hello,
i need help in finding a solution for my web app problem.

i am developing a internal web application for my company .. i would like my users to input mathematical formulas and some instructions...the server should then interpret these formulas and display the results in a specified format. i do not want my users to learn PHP, PERL or some other programing language ...

i came across JavaCC .. is there a way to use JavaCC with PHP5 ? ... or is there an equivalent of JavaCC in php ? ....

or is there a common parser/interpreter which will allow the user to input simple commands and get a PHP script out of it..so that my server can run it and produce results ?? ...

for example say the user input is SUM(A1 - A3) meaning add A1+A2+A3
the corresponding Php code should be

function SUM($A){
for($i=0;$i<count($A);i++){
$RESULT  +=  $A[$i];
}
return $RESULT;
}

well thats just a simple example ... i dont want to reinvent the wheel .. i would be happy if some could point me to useful resources ....
thanks
Link to comment
https://forums.phpfreaks.com/topic/31510-writing-own-simple-langauge-using-php/
Share on other sites

There are out of the box XML parsers.  You'll still spend some cycles converting your pseudo syntax to valid XML, but the transformation from XML to php should be rather painless. 

From someone who's taken compiler classes in college you want to stay away from parsing your own language from scratch, that is unless you have a fondness for state machines and headaches.
I like the idea of making some kind of parser!!!

but, you should be specific about wich kind of formulas they intend to do...

for example, I worked with a school gestion software. the teachers put their formulas like ($t1 + $t2*3)/2 and php just had to run eval... no need for parsers...

what's the complexity of your formulas?


for example, It´s not that hard to do an simple lisp parser...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.