Skip to content

Commit

Permalink
updates to increase compiling speed
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed Dec 15, 2014
1 parent 84a1cf0 commit 7afc813
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Lempar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct($s, $m = array())

public function __toString()
{
return $this->_string;
return $this->string;
}

public function offsetExists($offset)
Expand Down Expand Up @@ -471,7 +471,7 @@ public function yy_accept()
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sAccept!\n", $this->yyTracePrompt);
} while ($this->yyidx >= 0) {
$stack = $this->yy_pop_parser_stack();
$this->yy_pop_parser_stack();
}
%%
}
Expand Down
6 changes: 3 additions & 3 deletions LexerGenerator/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct($s, $m = array())

public function __toString()
{
return $this->_string;
return $this->string;
}

public function offsetExists($offset)
Expand Down Expand Up @@ -280,7 +280,7 @@ public function doLongestMatch($rules, $statename, $ruleindex)
foreach ($yy_yymore_patterns[' . $this->token . '] as $index => $rule) {
if (preg_match(\'/\' . $rule . \'/' . $this->patternFlags . '\',
' . $this->input . ', $yymatches, null, ' . $this->counter . ')) {
$yymatches = array_filter($yymatches, \'strlen\'); // remove empty sub-patterns
$yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
if ($match) {
if (strlen($yymatches[0]) > strlen($match[0][0])) {
$match = array($yymatches, $index); // matches, token
Expand Down Expand Up @@ -356,7 +356,7 @@ public function doFirstMatch($rules, $statename, $ruleindex)
$this->counter .
')) {
$yysubmatches = $yymatches;
$yymatches = array_filter($yymatches, \'strlen\'); // remove empty sub-patterns
$yymatches = preg_grep("/(.|\s)+/", $yysubmatches);
if (!count($yymatches)) {
throw new Exception(\'Error: lexing failed because a rule matched\' .
\' an empty string. Input "\' . substr(' . $this->input . ',
Expand Down
31 changes: 17 additions & 14 deletions ParserGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,24 +412,27 @@ private function handle_D_option($z)
*/

/* The main program. Parse the command line and do it... */
public function main()
public function main($filename = null)
{
$lem = new PHP_ParserGenerator_Data;
if (!isset($filename)) {
$this->OptInit($_SERVER['argv']);
if ($this->version) {
echo "Lemon version 1.0/PHP_ParserGenerator port version 0.1.5\n";
exit(0);
}
if ($this->OptNArgs($_SERVER['argv']) != 1) {
echo "Exactly one filename argument is required.\n";
exit(1);
}

$this->OptInit($_SERVER['argv']);
if ($this->version) {
echo "Lemon version 1.0/PHP_ParserGenerator port version 0.1.5\n";
exit(0);
}
if ($this->OptNArgs($_SERVER['argv']) != 1) {
echo "Exactly one filename argument is required.\n";
exit(1);
/* Initialize the machine */
$lem->argv0 = $_SERVER['argv'][0];
$lem->filename = $this->OptArg(0, $_SERVER['argv']);
} else {
$lem->filename = $filename;
}
$lem->errorcnt = 0;

/* Initialize the machine */
$lem->argv0 = $_SERVER['argv'][0];
$lem->filename = $this->OptArg(0, $_SERVER['argv']);
$a = pathinfo($lem->filename);
if (isset($a['extension'])) {
$ext = '.' . $a['extension'];
Expand Down Expand Up @@ -539,7 +542,7 @@ public function main()
if ($lem->nconflict) {
printf("%d parsing conflicts.\n", $lem->nconflict);
}
exit($lem->errorcnt + $lem->nconflict);
//exit($lem->errorcnt + $lem->nconflict);

return ($lem->errorcnt + $lem->nconflict);
}
Expand Down
9 changes: 5 additions & 4 deletions ParserGenerator/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ private function tplt_print($out, $str, $strln, &$lineno)
$lineno++;
fwrite($out, $str);
$lineno += count(explode("\n", $str)) - 1;
$this->tplt_linedir($out, $lineno + 2, $this->outname);
//$this->tplt_linedir($out, $lineno + 2, $this->outname);
$lineno += 2;
}
/**#@-*/
Expand Down Expand Up @@ -1640,6 +1640,7 @@ public function ReportTable($mhflag)
$this->tplt_print($out, $this->extracode, $this->extracodeln, $lineno);

fclose($in);
fwrite($out, "\n");
fclose($out);
}

Expand All @@ -1654,11 +1655,11 @@ public function emit_code($out, PHP_ParserGenerator_Rule $rp, &$lineno)
/* Generate code to do the reduce action */
if ($rp->code) {
$this->tplt_linedir($out, $rp->line, $this->filename);
fwrite($out, " function yy_r$rp->index(){" . $rp->code);
fwrite($out, " function yy_r$rp->index()".'{' . $rp->code);
$linecnt += count(explode("\n", $rp->code)) - 1;
$lineno += 3 + $linecnt;
fwrite($out, " }\n");
$this->tplt_linedir($out, $lineno, $this->outname);
//$this->tplt_linedir($out, $lineno, $this->outname);
} /* End if( rp->code ) */
}

Expand Down Expand Up @@ -1844,7 +1845,7 @@ public function emit_destructor_code($out, PHP_ParserGenerator_Symbol $sp, &$lin
}
$lineno += 3 + $linecnt;
fwrite($out, "}\n");
$this->tplt_linedir($out, $lineno, $this->outname);
//$this->tplt_linedir($out, $lineno, $this->outname);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion ParserGenerator/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public function Parse(PHP_ParserGenerator_Data $gp)
$lineno = 1;
for ($cp = 0, $c = $filebuf[0]; $cp < strlen($filebuf); $cp++) {
$c = $filebuf[$cp];
if ($c == "\n") $lineno++; /* Keep track of the line number */
$lineno = substr_count(substr($filebuf, 0, $cp), "\n")+1;
//if ($c == "\n") $lineno++; /* Keep track of the line number */
if (trim($c) === '') {
continue;
} /* Skip all white space */
Expand Down

0 comments on commit 7afc813

Please sign in to comment.