<?php
class CompactTokenizer {
var $index, $tokens;
function CompactTokenizer($file){
global $index,$tokens;
$tokens = preg_split("/\n|(\[|\]|@)/",
file_get_contents($file),
-1,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
$index = 0;
}
function getToken(){
global $tokens,$index;
$token = $index<count($tokens)?$tokens[$index]:false;
return $token;
}
function nextToken(){
global $tokens,$index;
do {
$index=$index+1;
$token = $this->getToken();
if($token==false)break;
$token=trim($token);
} while (strlen($token)==0);
return $token;
}
function skip($sym){
if($this->getToken()==$sym)
return $this->nextToken();
die("skip:$sym expected but ".$this->getToken()." found. index=$index");
}
}
?>