PHP code example of nemorize / fexpr

1. Go to this page and download the library: Download nemorize/fexpr library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nemorize / fexpr example snippets


$ast = (new \Nemorize\Fexpr\Parser())->parse('id = 123 && status = "active"');
// json_encode($ast): [
//     {
//         "operation": {
//             "type": "join",
//             "literal": "&&"
//         },
//         "item": {
//             "left": {
//                 "type": "identifier",
//                 "literal": "id"
//             },
//             "operation": {
//                 "type": "sign",
//                 "literal": "=",
//             },
//             "right": {
//                 "type": "number",
//                 "literal": "123"
//             }
//         }
//     },
//     {
//         "operation": {
//             "type": "join",
//             "literal": "&&"
//         },
//         "item": {
//             "left": {
//                 "type": "identifier",
//                 "literal": "status"
//             },
//             "operation": {
//                 "type": "sign",
//                 "literal": "=",
//             },
//             "right": {
//                 "type": "string",
//                 "literal": "active"
//             }
//         }
//     }
// ]

$scanner = new \Nemorize\Fexpr\Scanner();
foreach ($scanner->scan('id > 123') as $token) {
    var_dump($token);
}