mirror of https://github.com/vitalif/lime
666 lines
14 KiB
Plaintext
666 lines
14 KiB
Plaintext
<?php
|
|
/*
|
|
*** DON'T EDIT THIS FILE! ***
|
|
*
|
|
* This file was automatically generated by the Lime parser generator.
|
|
* The real source code you should be looking at is in one or more
|
|
* grammar files in the Lime format.
|
|
*
|
|
* THE ONLY REASON TO LOOK AT THIS FILE is to see where in the grammar
|
|
* file that your error happened, because there are enough comments to
|
|
* help you debug your grammar.
|
|
|
|
* If you ignore this warning, you're shooting yourself in the brain,
|
|
* not the foot.
|
|
*/
|
|
class calc extends lime_parser {
|
|
public $qi = 0;
|
|
public $i = array(
|
|
array(
|
|
'exp' => 's 1',
|
|
'var' => 's 31',
|
|
'num' => 's 3',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24',
|
|
'stmt' => 's 34',
|
|
"'start'" => "a 'start'"
|
|
),
|
|
array(
|
|
"'+'" => 's 2',
|
|
"'-'" => 's 7',
|
|
"'*'" => 's 9',
|
|
"'/'" => 's 11',
|
|
"'^'" => 's 13',
|
|
"'%'" => 's 15',
|
|
'#' => 'r 0'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 30',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 'r 2',
|
|
"'-'" => 'r 2',
|
|
"'*'" => 'r 2',
|
|
"'/'" => 'r 2',
|
|
"'^'" => 'r 2',
|
|
"'%'" => 'r 2',
|
|
"')'" => 'r 2',
|
|
"','" => 'r 2',
|
|
'#' => 'r 2'
|
|
),
|
|
array(
|
|
"'('" => 's 5',
|
|
"'+'" => 'r 3',
|
|
"'-'" => 'r 3',
|
|
"'*'" => 'r 3',
|
|
"'/'" => 'r 3',
|
|
"'^'" => 'r 3',
|
|
"'%'" => 'r 3',
|
|
"')'" => 'r 3',
|
|
"','" => 'r 3',
|
|
'#' => 'r 3'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 6',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'param_list' => 's 25',
|
|
'error' => 's 24',
|
|
'non_empty_param_list' => 's 27',
|
|
"')'" => 'r 15'
|
|
),
|
|
array(
|
|
"'+'" => 's 2',
|
|
"'-'" => 's 7',
|
|
"'*'" => 's 9',
|
|
"'/'" => 's 11',
|
|
"'^'" => 's 13',
|
|
"'%'" => 's 15',
|
|
"','" => 'r 17',
|
|
"')'" => 'r 17'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 8',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 'r 5',
|
|
"'-'" => 'r 5',
|
|
"'*'" => 's 9',
|
|
"'/'" => 's 11',
|
|
"'^'" => 's 13',
|
|
"'%'" => 's 15',
|
|
"')'" => 'r 5',
|
|
"','" => 'r 5',
|
|
'#' => 'r 5'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 10',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 'r 6',
|
|
"'-'" => 'r 6',
|
|
"'*'" => 'r 6',
|
|
"'/'" => 'r 6',
|
|
"'^'" => 's 13',
|
|
"'%'" => 'r 6',
|
|
"')'" => 'r 6',
|
|
"','" => 'r 6',
|
|
'#' => 'r 6'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 12',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 'r 7',
|
|
"'-'" => 'r 7',
|
|
"'*'" => 'r 7',
|
|
"'/'" => 'r 7',
|
|
"'^'" => 's 13',
|
|
"'%'" => 'r 7',
|
|
"')'" => 'r 7',
|
|
"','" => 'r 7',
|
|
'#' => 'r 7'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 14',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 'r 8',
|
|
"'-'" => 'r 8',
|
|
"'*'" => 'r 8',
|
|
"'/'" => 'r 8',
|
|
"'^'" => 's 13',
|
|
"'%'" => 'r 8',
|
|
"')'" => 'r 8',
|
|
"','" => 'r 8',
|
|
'#' => 'r 8'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 16',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 'r 9',
|
|
"'-'" => 'r 9',
|
|
"'*'" => 'r 9',
|
|
"'/'" => 'r 9',
|
|
"'^'" => 's 13',
|
|
"'%'" => 'r 9',
|
|
"')'" => 'r 9',
|
|
"','" => 'r 9',
|
|
'#' => 'r 9'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 18',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 'r 10',
|
|
"'-'" => 'r 10',
|
|
"'*'" => 'r 10',
|
|
"'/'" => 'r 10',
|
|
"'^'" => 'r 10',
|
|
"'%'" => 'r 10',
|
|
"')'" => 'r 10',
|
|
"','" => 'r 10',
|
|
'#' => 'r 10'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 20',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 'r 11',
|
|
"'-'" => 'r 11',
|
|
"'*'" => 'r 11',
|
|
"'/'" => 'r 11',
|
|
"'^'" => 'r 11',
|
|
"'%'" => 'r 11',
|
|
"')'" => 'r 11',
|
|
"','" => 'r 11',
|
|
'#' => 'r 11'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 22',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 's 2',
|
|
"'-'" => 's 7',
|
|
"'*'" => 's 9',
|
|
"'/'" => 's 11',
|
|
"'^'" => 's 13',
|
|
"'%'" => 's 15',
|
|
"')'" => 's 23'
|
|
),
|
|
array(
|
|
"'%'" => 'r 12',
|
|
"'^'" => 'r 12',
|
|
"'/'" => 'r 12',
|
|
"'*'" => 'r 12',
|
|
"'-'" => 'r 12',
|
|
"'+'" => 'r 12',
|
|
"')'" => 'r 12',
|
|
"','" => 'r 12',
|
|
'#' => 'r 12'
|
|
),
|
|
array(
|
|
"'%'" => 'r 14',
|
|
"'^'" => 'r 14',
|
|
"'/'" => 'r 14',
|
|
"'*'" => 'r 14',
|
|
"'-'" => 'r 14',
|
|
"'+'" => 'r 14',
|
|
"')'" => 'r 14',
|
|
"','" => 'r 14',
|
|
'#' => 'r 14'
|
|
),
|
|
array(
|
|
"')'" => 's 26'
|
|
),
|
|
array(
|
|
"'%'" => 'r 13',
|
|
"'^'" => 'r 13',
|
|
"'/'" => 'r 13',
|
|
"'*'" => 'r 13',
|
|
"'-'" => 'r 13',
|
|
"'+'" => 'r 13',
|
|
"')'" => 'r 13',
|
|
"','" => 'r 13',
|
|
'#' => 'r 13'
|
|
),
|
|
array(
|
|
"','" => 's 28',
|
|
"')'" => 'r 16'
|
|
),
|
|
array(
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
'exp' => 's 29',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 's 2',
|
|
"'-'" => 's 7',
|
|
"'*'" => 's 9',
|
|
"'/'" => 's 11',
|
|
"'^'" => 's 13',
|
|
"'%'" => 's 15',
|
|
"','" => 'r 18',
|
|
"')'" => 'r 18'
|
|
),
|
|
array(
|
|
"'+'" => 'r 4',
|
|
"'-'" => 'r 4',
|
|
"'*'" => 's 9',
|
|
"'/'" => 's 11',
|
|
"'^'" => 's 13',
|
|
"'%'" => 's 15',
|
|
"')'" => 'r 4',
|
|
"','" => 'r 4',
|
|
'#' => 'r 4'
|
|
),
|
|
array(
|
|
"'='" => 's 32',
|
|
"'('" => 's 5',
|
|
"'+'" => 'r 3',
|
|
"'-'" => 'r 3',
|
|
"'*'" => 'r 3',
|
|
"'/'" => 'r 3',
|
|
"'^'" => 'r 3',
|
|
"'%'" => 'r 3',
|
|
'#' => 'r 3'
|
|
),
|
|
array(
|
|
'exp' => 's 33',
|
|
'num' => 's 3',
|
|
'var' => 's 4',
|
|
"'+'" => 's 17',
|
|
"'-'" => 's 19',
|
|
"'('" => 's 21',
|
|
'error' => 's 24'
|
|
),
|
|
array(
|
|
"'+'" => 's 2',
|
|
"'-'" => 's 7',
|
|
"'*'" => 's 9',
|
|
"'/'" => 's 11',
|
|
"'^'" => 's 13',
|
|
"'%'" => 's 15',
|
|
'#' => 'r 1'
|
|
),
|
|
array(
|
|
'#' => 'r 19'
|
|
)
|
|
);
|
|
public $d = array(
|
|
"'+'" => 'plus operator (+)',
|
|
"'-'" => 'minus operator (-)',
|
|
"'*'" => 'multiplication operator (*)',
|
|
"'/'" => 'division operator (/)',
|
|
"'%'" => 'modulo operator (%)',
|
|
"'^'" => 'exponentiation operator (^)'
|
|
);
|
|
public $errors = array();
|
|
function reduce_0_stmt_1($tokens, &$result) {
|
|
// (0) stmt := exp
|
|
$result = reset($tokens);
|
|
|
|
echo ' -> ';
|
|
echo $tokens[0][0] . ' = ' . $tokens[0][1];
|
|
echo "\n";
|
|
}
|
|
|
|
function reduce_1_stmt_2($tokens, &$result) {
|
|
// (1) stmt := var '=' exp
|
|
$result = reset($tokens);
|
|
$v = &$tokens[0];
|
|
$e = &$tokens[2];
|
|
|
|
echo $v . ' = ' . $e . "\n";
|
|
set_variable($v, $e);
|
|
}
|
|
|
|
function reduce_2_exp_1($tokens, &$result) {
|
|
// (2) exp := num
|
|
$result = reset($tokens);
|
|
|
|
$result = array($tokens[0], $tokens[0]);
|
|
}
|
|
|
|
function reduce_3_exp_2($tokens, &$result) {
|
|
// (3) exp := var
|
|
$result = reset($tokens);
|
|
|
|
$result = array($tokens[0], get_variable($tokens[0]));
|
|
}
|
|
|
|
function reduce_4_exp_3($tokens, &$result) {
|
|
// (4) exp := exp '+' exp
|
|
$result = reset($tokens);
|
|
|
|
$result = array(
|
|
'(' . $tokens[0][0] . ' + ' . $tokens[2][0] . ')',
|
|
nan_or($tokens[0][1], $tokens[2][1], $tokens[0][1] + $tokens[2][1])
|
|
);
|
|
}
|
|
|
|
function reduce_5_exp_4($tokens, &$result) {
|
|
// (5) exp := exp '-' exp
|
|
$result = reset($tokens);
|
|
|
|
$result = array(
|
|
'(' . $tokens[0][0] . ' - ' . $tokens[2][0] . ')',
|
|
nan_or($tokens[0][1], $tokens[2][1], $tokens[0][1] - $tokens[2][1])
|
|
);
|
|
}
|
|
|
|
function reduce_6_exp_5($tokens, &$result) {
|
|
// (6) exp := exp '*' exp
|
|
$result = reset($tokens);
|
|
|
|
$result = array(
|
|
'(' . $tokens[0][0] . ' * ' . $tokens[2][0] . ')',
|
|
nan_or($tokens[0][1], $tokens[2][1], $tokens[0][1] * $tokens[2][1])
|
|
);
|
|
}
|
|
|
|
function reduce_7_exp_6($tokens, &$result) {
|
|
// (7) exp := exp '/' exp
|
|
$result = reset($tokens);
|
|
|
|
$result = array(
|
|
'(' . $tokens[0][0] . ' / ' . $tokens[2][0] . ')',
|
|
nan_or($tokens[0][1], $tokens[2][1], $tokens[0][1] / $tokens[2][1])
|
|
);
|
|
}
|
|
|
|
function reduce_8_exp_7($tokens, &$result) {
|
|
// (8) exp := exp '^' exp
|
|
$result = reset($tokens);
|
|
|
|
$result = array(
|
|
'(' . $tokens[0][0] . ' ^ ' . $tokens[2][0] . ')',
|
|
nan_or($tokens[0][1], $tokens[2][1], pow($tokens[0][1], $tokens[2][1]))
|
|
);
|
|
}
|
|
|
|
function reduce_9_exp_8($tokens, &$result) {
|
|
// (9) exp := exp '%' exp
|
|
$result = reset($tokens);
|
|
|
|
$result = array(
|
|
'(' . $tokens[0][0] . ' % ' . $tokens[2][0] . ')',
|
|
nan_or($tokens[0][1], $tokens[2][1], $tokens[0][1] % $tokens[2][1])
|
|
);
|
|
}
|
|
|
|
function reduce_10_exp_9($tokens, &$result) {
|
|
// (10) exp := '+' exp
|
|
$result = reset($tokens);
|
|
|
|
$result = array(
|
|
'(+ ' . $tokens[1][0] . ')',
|
|
nan_or($tokens[0][1], $tokens[2][1], +($tokens[1][1]))
|
|
);
|
|
}
|
|
|
|
function reduce_11_exp_10($tokens, &$result) {
|
|
// (11) exp := '-' exp
|
|
$result = reset($tokens);
|
|
|
|
$result = array(
|
|
'(- ' . $tokens[1][0] . ')',
|
|
nan_or($tokens[0][1], $tokens[2][1], -($tokens[1][1]))
|
|
);
|
|
}
|
|
|
|
function reduce_12_exp_11($tokens, &$result) {
|
|
// (12) exp := '(' exp ')'
|
|
$result = $tokens[1];
|
|
}
|
|
|
|
function reduce_13_exp_12($tokens, &$result) {
|
|
// (13) exp := var '(' param_list ')'
|
|
$result = reset($tokens);
|
|
|
|
$result = array(
|
|
// little bits of voodoo to make this happen
|
|
'(' . $tokens[0] . '(' .
|
|
implode(', ', array_map(function ($a) {
|
|
return $a[0];
|
|
}, $tokens[2])) .
|
|
'))',
|
|
call_user_func_array($tokens[0], array_map(function ($a) {
|
|
return $a[1];
|
|
}, $tokens[2]))
|
|
);
|
|
}
|
|
|
|
function reduce_14_exp_13($tokens, &$result) {
|
|
// (14) exp := error
|
|
$result = reset($tokens);
|
|
|
|
printf("Error\n");
|
|
$result = array('NaN', NaN);
|
|
}
|
|
|
|
function reduce_15_param_list_1($tokens, &$result) {
|
|
// (15) param_list :=
|
|
$result = reset($tokens);
|
|
|
|
$result = array();
|
|
}
|
|
|
|
function reduce_16_param_list_2($tokens, &$result) {
|
|
// (16) param_list := non_empty_param_list
|
|
$result = reset($tokens);
|
|
}
|
|
|
|
function reduce_17_non_empty_param_list_1($tokens, &$result) {
|
|
// (17) non_empty_param_list := exp
|
|
$result = reset($tokens);
|
|
|
|
$result = array($tokens[0]);
|
|
}
|
|
|
|
function reduce_18_non_empty_param_list_2($tokens, &$result) {
|
|
// (18) non_empty_param_list := non_empty_param_list ',' exp
|
|
$result = reset($tokens);
|
|
|
|
$tokens[0][] = $tokens[2];
|
|
$result = $tokens[0];
|
|
}
|
|
|
|
function reduce_19_start_1($tokens, &$result) {
|
|
// (19) 'start' := stmt
|
|
$result = reset($tokens);
|
|
}
|
|
|
|
public $method = array(
|
|
'reduce_0_stmt_1',
|
|
'reduce_1_stmt_2',
|
|
'reduce_2_exp_1',
|
|
'reduce_3_exp_2',
|
|
'reduce_4_exp_3',
|
|
'reduce_5_exp_4',
|
|
'reduce_6_exp_5',
|
|
'reduce_7_exp_6',
|
|
'reduce_8_exp_7',
|
|
'reduce_9_exp_8',
|
|
'reduce_10_exp_9',
|
|
'reduce_11_exp_10',
|
|
'reduce_12_exp_11',
|
|
'reduce_13_exp_12',
|
|
'reduce_14_exp_13',
|
|
'reduce_15_param_list_1',
|
|
'reduce_16_param_list_2',
|
|
'reduce_17_non_empty_param_list_1',
|
|
'reduce_18_non_empty_param_list_2',
|
|
'reduce_19_start_1'
|
|
);
|
|
public $a = array(
|
|
array(
|
|
'symbol' => 'stmt',
|
|
'len' => 1,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'stmt',
|
|
'len' => 3,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 1,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 1,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 3,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 3,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 3,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 3,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 3,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 3,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 2,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 2,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 3,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 4,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'exp',
|
|
'len' => 1,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'param_list',
|
|
'len' => 0,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'param_list',
|
|
'len' => 1,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'non_empty_param_list',
|
|
'len' => 1,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => 'non_empty_param_list',
|
|
'len' => 3,
|
|
'replace' => true
|
|
),
|
|
array(
|
|
'symbol' => "'start'",
|
|
'len' => 1,
|
|
'replace' => true
|
|
)
|
|
);
|
|
}
|
|
|
|
// Time: 0.093108177185059 seconds
|
|
// Memory: 2768108 bytes
|