mattd8752 Posted March 10, 2007 Share Posted March 10, 2007 I was thinking of making a PHP based programming language. I am stumped almost right away. I am thinking of having it work something like this: (y) = 1 (x) = (y) (x) = (x) + 1 SHOW {X is... (x). X + 1 is {(x)+1}} I could parse all of that easily, but how would I make it read info going as deep as the user wants into the code. I would want the SHOW command to output: X is 2. X + 1 is 3. I am rather confused as to where I should start. I want code to be able to run inside of scripts by putting the script to be parsed in curly braces. I would want variables to also be replaced, in brackets. Where should I start? My idea is to parse the variable name and do: $a_$varname = $value; Then, it would be naming the variables a_their name. I have no problem with that, but I am not even sure what functions to use for running code INSIDE of code. I am not a super regex user, I do know how it works, and if you EXPLAIN it to me, I can figure it out. Thanks, Matt Please, just give me an idea of where I could get started. Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/ Share on other sites More sharing options...
fert Posted March 10, 2007 Share Posted March 10, 2007 You would need to use recursion. Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-203995 Share on other sites More sharing options...
mattd8752 Posted March 10, 2007 Author Share Posted March 10, 2007 Sorry, but what is recursion? Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204006 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 You do not know what recursion is and you are trying to make your own language? Wow dude. google.com recursive functions. Read up on it, that is a major key to save time with a lot of codes. Just you are lucky that programming languages like PHP provide array functions for you. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204021 Share on other sites More sharing options...
mattd8752 Posted March 10, 2007 Author Share Posted March 10, 2007 From what I understand you are reffering to while. If this is true, how would I read this code. I can do loops, I just dont know how to read the data. Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204057 Share on other sites More sharing options...
fert Posted March 10, 2007 Share Posted March 10, 2007 From what I understand you are reffering to while No I'm not, recursion is slightly similar to loops, but different function parse($code) { $lines=explode(";",$code); for($count=0;$count<num($lines);$count++) { if(preg_match("code within code",$lines[$count],$matches)) { parse($resulting_code); } } } [code] that's recursion [/code] Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204072 Share on other sites More sharing options...
JBS103 Posted March 10, 2007 Share Posted March 10, 2007 As fert has shown, recursion is simply a defined function being used within its own definition. I'm sure there is a lengthy amount on wikipedia if you need to understand more, however, most of that information is probably way more than you need. Try a few simple examples on your own and you will see how it works very quickly. Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204078 Share on other sites More sharing options...
mattd8752 Posted March 10, 2007 Author Share Posted March 10, 2007 Okay, so recursion is rather calling the function again, making it move back and repeat? Anyway, I'm not concerned about splitting the code, however I'm not sure how I would parse it. I know how to separate it, and run the code through the parser, but I am rather confused on how I would get the name of the variable and the value out of: .a. = (value) I decided to wrap variable in dots normal words in brackets. Code in curly braces. Anyway, how would I read this, and parse it. Would a simple explode do the trick? Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204213 Share on other sites More sharing options...
mattd8752 Posted March 10, 2007 Author Share Posted March 10, 2007 Bump Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204223 Share on other sites More sharing options...
mattd8752 Posted March 10, 2007 Author Share Posted March 10, 2007 Bump Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204327 Share on other sites More sharing options...
mattd8752 Posted March 10, 2007 Author Share Posted March 10, 2007 Bump Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204424 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 Bumping won't help you get the answer. Especially how frequently you do it. Good luck with trying to get help. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204425 Share on other sites More sharing options...
mattd8752 Posted March 10, 2007 Author Share Posted March 10, 2007 They've been 2 hours apart at minimum, and the post has been close to falling off the page both times. Back to topic though. Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204428 Share on other sites More sharing options...
ShogunWarrior Posted March 10, 2007 Share Posted March 10, 2007 Ok, firstly either don't wrap the variable names at all or use a single character. (I quite like PHP's use of $) The dots aren't a good choice and they and using two is overkill. What you do is when you find the variable character such as $ you set some sort of flag to tell your parser you are reading a variable name, then you keep reading characters until you find a non-variable character such as a space. So, $somevar = (that); will start at $, gobble up somevar, stop and then you can record the data on the right side of the equals. Parsing is not extremely difficult but still if you look at any interpreter such as Zend I am willing to bet there is a hefty amount of code behind code parsing! Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204431 Share on other sites More sharing options...
mattd8752 Posted March 10, 2007 Author Share Posted March 10, 2007 Wow, that just cleared it up so much more . Thanks Quote Link to comment https://forums.phpfreaks.com/topic/42062-solved-how-would-i/#findComment-204434 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.