views:

39

answers:

1

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

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?

A: 

I'm sure this is an oversight in your code cleanup for posting, but you have an extra { that's not closed.

Erik Giberti
You are right. When formatting the code for the post i did something wrong. But that issnt the fault in the real code.
VDVLeon
Have you tried die() within parseRecursive() to ensure that the bug isn't deeper in? Perhaps dumping out your parameters to ensure you are getting what you expect?
Erik Giberti
when i put die() in parseRecursive is get the die output.
VDVLeon
You are never hitting a condition that will stop then, you're in the infinite loop as e4c5 said yesterday
Erik Giberti