I’ve been searching for this for a while though I never get a great answer.
I’m looking for a tutorial or code which parses a defined syntax like a new language. Preferably using strtok or tokenizer.
I need to write a simple language which I will parse later.
Thanks for any help.
edit
The language is quite simple. Basically variable assignment and loops as well as conditional checks. Nothing fancy.
edit
I guess from the answer I got, the title should not be so. Something along the lines of “how to create a language in php” would be better. Thanks.
Basically, “making a language” involves several steps. First, you need a “lexer” which splits your input into substrings belonging to different symbol classes (like “identifier”, “number”, “operator” etc). Second, you write down a grammar of your language, usually using some kind of BNF. Then you
eat the bananause a program called “parser generator” which turns your grammar into actual parser code and finally you combine lexer and parser to get an actual complier.Normally, this kind of things is being done with C or Java, I’ve never heard of working compliers written in php. Still, you can use php tokenizer for the first part (the lexer) – assuming your language has syntax similar to php – and try http://pear.php.net/package/PHP_ParserGenerator to generate the parser.
Sorry if this sounds a bit complicated, but so it is.