Exemplo n.º 1
0
 function __construct()
 {
     $tokens = ['{', '}', ',', ':', 'true', 'false', 'null', '[', ']', 'number' => '[-]?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][+-]?[0-9]+)?', 'string' => '"([^"\\\\]|[\\\\](["\\\\/bfnrt]|u[0-9a-z]{4}))*"', 'sp' => '\\s+'];
     $rules = ['Value' => [[[['|', 'string', 'number', 'Object', 'Array', 'true', 'false', 'null']], true]], 'Object' => [[['{', ['?', "string", ":", "Value", ['*', ',', "string", ":", "Value"]], '}'], true]], 'Array' => [[['[', ['?', 'Value', ['*', ',', 'Value']], ']'], true]]];
     $lexer = new phpcc\Lexer($tokens);
     $parser = new phpcc\Parser();
     $parser->setLexer($lexer);
     $parser->init($rules);
     $parser->setSkipTokens(['sp']);
     $this->parser = $parser;
 }
Exemplo n.º 2
0
 function __construct()
 {
     $tokens = ['+', '-', '*', '/', '(', ')', 'pi', 'e', 'd' => '[1-9][0-9]*', 'f' => '[0-9]+\\.[0-9]+', 'sp' => '\\s+', 'var' => '[A-Z]+', 'func' => '[a-z]+'];
     $rules = ['Exp' => [[['L1Exp'], false]], 'L1Exp' => [[['L1Exp', '+', 'L2Exp'], true, 'Add'], [['L1Exp', '-', 'L2Exp'], true, 'Minus'], [['L2Exp'], false]], 'L2Exp' => [[['L2Exp', '*', 'L3Exp'], true, 'Multiply'], [['L2Exp', '/', 'L3Exp'], true, 'Divide'], [['L3Exp'], false]], 'L3Exp' => [[['-', 'L3Exp'], true, 'Reverse'], [['Term'], false]], 'Func' => [[['func', 'L3Exp'], true]], 'Term' => [[['Func'], false], [['Number'], false], [['(', 'Exp', ')'], false], [['Number', 'Const'], true, 'Multiply'], [['Number', 'Func'], true, 'Multiply']], 'Number' => [[[['|', 'Scala', 'Const']], false]], 'Scala' => [[[['|', 'd', 'f']], true]], 'Const' => [[[['|', 'pi', 'e']], true]]];
     $lexer = new phpcc\Lexer($tokens);
     $parser = new phpcc\Parser();
     $parser->setLexer($lexer);
     $parser->init($rules);
     $parser->setSkipTokens(['sp']);
     $this->parser = $parser;
 }
Exemplo n.º 3
0
 function __construct()
 {
     $tokens = ['sp' => '[ \\t]', 'comment' => '#.*', 'd' => '[0-9]+', 'f' => '[0-9]+\\.[0-9]+', 'nl' => '[\\n]+', '=', '+', '-', '*', '/', '%', '(', ')', '{', '}', '[', ']', ',', '==', '!=', '>', '<', '>=', '<=', '!', '~', 'name' => '[a-zA-Z_][a-zA-Z0-9_]*', 'qname' => '`[a-zA-Z_][a-zA-Z0-9_]*', 'func'];
     $rules = ['Exps' => [[[['+', 'Exp']], true]], 'Exp' => [[['Exp1', 'nl'], false], [['nl'], false]], 'Block' => [[['{', 'Exps', '}'], true]], 'Func' => [[['func', 'name', 'ArgList', 'Block'], true]], 'ArgList' => [[['(', ['?', 'Arg', ['*', ',', 'Arg']], ')'], true]], 'Arg' => [[['name'], false], [['qname'], false]], 'Call' => [[['name', '(', ['?', 'Exp2', ['*', ',', 'Exp2']], ')'], true]], 'Exp1' => [[['Exp2'], false]], 'Exp2' => [[['Exp3'], false], [['name', '=', 'Exp2'], true, 'Set'], [['Func'], false], [['Block'], false]], 'Exp3' => [[['Exp3', '==', 'Exp4'], true, 'Eq'], [['Exp3', '!=', 'Exp4'], true, 'Ne'], [['Exp3', '<=', 'Exp4'], true, 'Le'], [['Exp3', '>=', 'Exp4'], true, 'Ge'], [['Exp3', '<', 'Exp4'], true, 'Lt'], [['Exp3', '>', 'Exp4'], true, 'Gt'], [['Exp4'], false]], 'Exp4' => [[['Exp4', '+', 'Exp5'], true, 'Plus'], [['Exp4', '-', 'Exp5'], true, 'Minus'], [['Exp5'], false]], 'Exp5' => [[['Exp5', '*', 'Exp6'], true, 'Multiply'], [['Exp5', '/', 'Exp6'], true, 'Divide'], [['Exp5', '%', 'Exp6'], true, 'Mod'], [['Exp6'], false]], 'Exp6' => [[['-', 'Exp6'], true, 'Reverse'], [['!', 'Exp6'], true, 'Not'], [['~', 'Exp6'], true, 'Deqoute'], [['Value'], false], [['Call'], false], [['(', 'Exp2', ')'], false]], 'Value' => [[['Var'], false], [['Scala'], false]], 'Scala' => [[['d'], true], [['f'], true]], 'Var' => [[['name'], true]]];
     $lexer = new phpcc\Lexer($tokens);
     $parser = new phpcc\Parser();
     $parser->setLexer($lexer);
     $parser->init($rules);
     $parser->setSkipTokens(['sp', 'comment']);
     $this->parser = $parser;
     $this->setProcessors();
     $this->setDefaultVars();
 }