Alright, so I'm not learning a new language, I'm writing my own. This project struck me as the perfect goal to advance me to the next level of programming; parse the very data I pound out of my keyboard each day. I will be writing a parsing engine in PHP that can parse PHP code. Thats right, a PHP script that can successfully parse PHP in the same way PHP would. PHP in my opinion is perfect for building web applications and I <3 webbers, so all systems g0!
Basically, my goal is to make a PHP interpreter completely from scratch and, of course, only using source that my hands physically type written directly from memory. I "technically" started coding it three days ago, but thats besides the point. So far I must seem like a spaz, but I really want to emphasize
from scratch. Deep breath.
Heres what it does so far:- It takes the block of PHP code and goes char by char over the entire chunk storing the lines of code and extracting out the functions. (This also does a quick check to see if the line is a variable update, if, comment, function call or function declaration.)
- Parses all the declared functions and adds them to the avail functions list
- Then, starts to parse all the executable code
- Any variables that are bumped into are set via an equals sign.
- The remainder is parsed for data.
- If it finds anything, it will go char by char through the data, this time, being more finicky about the syntax.
- If it detects a function call, it will attempt it via calling a new instance of itself and waiting for returning data
- More to code...
An example of what it can parse: $test = "this is a test";
$name = "da404lewzer";
echo $test . '<br />';
echo "My name is: $name " . "<br />" . '<br />';
echo ohBaby("My name is:" . $name);
echo ohBaby2($test);
function ohBaby($meh){
return "w00t $meh<br />";
}
function ohBaby2($meh){
$meh = "w00t $meh<br />";
return $meh . "oh yea, this works too!";
}
This outputs:this is a test
My name is: da404lewzer
w00t My name is:
w00t
oh yea, this works too!
End of outputAs you can see in the output, the variables passed to the functions do not correctly parse as of tonight.
PHP outputs:this is a test
My name is: da404lewzer
w00t My name is:da404lewzer
w00t this is a test
oh yea, this works too!
END of PHPPHP however, will always do a better job than I can :P
So far the project has been fun and frustrating. Wow, you can actually get both! My next step is creating conditional checking and type guessing. Fun. Well, its only 9pm so I think I'm gonna grab me a DP, launch notepad2 and get coding.
Tags: compiler, parsing engine, php, programming language
Current Location: bed
Current Mood:
anxious
Current Music: Barenaked Ladies - If I had $1000000