Hi all. I am building a template parser. The template parser works like this:
- Tokenize (make for each part of the template code a token)
- Parse
- Use my ParserHelper class. You can add rules for this system, and then it checks the token list for a valid grammar.
- Add / change some tokens for extra functionality
- Compile (translate to php (for fast transforming to html))
The parser helper is a class with this structure:
- protected function parseRecursive(&$offset, $ruleName)
- protected function tryOption(&$offset, vdParserHelperRuleOption& $option)
- protected function tryItem(&$offset, vdParserHelperRuleOptionItem& $item, $count)
Offset stands for the token offset (so offset=0 means the first token to parse, etc.)
My parser helper rules have this structure:
- Rule
- Options
- Items
- Options
For the people how knows what a context free grammer is:
rule -> < option1 > | < option2 > | ... | < optionN >
with optionX is labda (empty option) or a list of:
- a 'rule link' (a link to an other rule (can be recursion)) or
- a 'token'
So the function parseRecursive calls tryOption, tryOption calls tryItem and tryItem can call parseRecursive agian.
The error is in the function tryItem:
...
// Try item
if($item->getType()==vdParserHelperRuleOptionItem::RuleLink){
///// The next line !!!!!!!!!!!!!
if(!$this->parseRecursive($currentOffset, $item->getData())){
///// The previous line !!!!!!!!!
return $item->isOptional();
}
}else if($item->getType()==vdParserHelperRuleOptionItem::Type){
...
}
...
When I remove (replace it for if(true){ or so) the line between 'the' comments the php code is executed. But when I dont remove that line php dont execute my code and outputs nothing and I get no error at all. When I look in the apache log file I get this error:
[notice] child pid 11957 exit signal Segmentation fault (11)
Is this a fault in php, or can php not handle in-direct recursion? Or is it something else?