Hi everybody ! I'm wondering about formal languages. I have a kind of parser : It reads à xml-like serialized tree structure and turn it into a multidimmensionnal array.
My point is on the similarities between the algorithm being used and the differents kinds of automatons ( state machines turing machines stack ... ).
So the question is : which is the automaton I implictly use here, and to which formal languages family does it fit ? And what's about recursion ?
What i mean by " automaton i use implicitly " is "which is the minimal automaton to do the same job".
Here is the complete source :
$words; // an array of XML tag '<tag>', '</tag>' and simple text content
$tree = array( 'type' => 'root', 'sub' => array() );
$pTree = array(&$tree);
$deep = 0;
foreach ( $words as $elem ) {
if ( preg_match($openTag, $elem) ) { // $elem is an open tag
$pTree[$deep++]['sub'][] = array( // we add an element to the multidim array
'type' => 'block',
'content' => $elem,
'sub' => array()
);
$size = sizeof($pTree[$deep - 1]['sub']);
$pTree[$deep] = &$pTree[$deep - 1]['sub'][$size - 1]; // down one level in the tree
} elseif ( preg_match($closeTag, $elem) ) { // it is a close tag
$deep--; // up in the tree
} else { // simple element
$pTree[$deep]['sub'][] = array(
'type' => 'simple',
'content' => $elem
);
}
}