I am doing a academic work that I need to use parser and lexer generator for php.
I searched on the internet and I found this
The problem is create the grammar and plex file.
For example:
<?php
class blah {
/*!lex2php
%input $this->data
%counter $this->N
%token $this->token
%value $this->value
%line $this->line
variable = @/?:([a-zA-Z0-9_]+)/?@
*/
/*!lex2php
variable {$a = 1;}
*/
}
?>
Someone can explain me that code please?
The first comment block is used for declarations. All the % declaration are mostly for internal use, and not very relevant at this stage.
The
variable = @/?:([a-zA-Z0-9_]+)/?@is interesting though. It defines a nonterminal symbolvariable, defined by the regex@/?:([a-zA-Z0-9_]+)/?@.If you generate your lexer using this plex file and feed it something like this:
The tokenstream would be as follows: