{201({2}} #### 4 * {201({2}} #### startrule: { ($abscb,$self) = @arg } startrule: bin_op /^\Z/ { $item[1] } bin_op: logical_op # Lowest precendance the comparitive operators... logical_op: { treeify(@{$item[1]}); } equality_op: { treeify(@{$item[1]}); } comp_op: { treeify(@{$item[1]}); } add_op: { treeify(@{$item[1]}); } # Highest precendance. prod_op : { treeify(@{$item[1]}); } SUM : '+' | '-' PROD : '*' | '/' | '%' COMP : />=?|<=?|le|ge|lt|gt/ EQUALITY : /!=|==?|eq|ne/ LOGICAL : 'AND' | 'OR' | '&&' | '||' arg_list: list_bin_op(s?) bin_op { [@{$item[1]},$item[2]] } # Functions, parenthesized equations, abstractions numbers and strings are all basically atomic. term: function | abstraction | '(' bin_op ')' { $item[2] } | number | /\$[1-9]/ { [ 'arg', substr($item[1],1,1) ] } | string | 'NULL' | abstraction: '{' number '(' arg_list ')' '}' { $abscb->($item[2],$item[4]) } | '{' number '}' { $abscb->($item[2]) } | # There is probably a prettier way to do these, but this works if: /if/i '(' list_bin_op(2) bin_op ')' { [$item[1],@{$item[3]},$item[4]] } concat: /concat/i '(' list_bin_op(s) bin_op ')' { [$item[1],@{$item[3]},$item[4]] } left: /left/i '(' list_bin_op bin_op ')' { [@item[1,3,4]] } right: /right/i '(' list_bin_op bin_op ')' { [@item[1,3,4]] } ifnull: /ifnull/i '(' list_bin_op bin_op ')' { [@item[1,3,4]] } now: /now/i '(' ')' { [$item[1],''] } # if you don't return two items, they seem to get flattened somewhere, making it the string NOW length_func: /length/i '(' bin_op ')' { [@item[1,3]] } interval: /interval/i /\d+/ /MONTH|DAY|WEEK|YEAR/ { [@item[1,2,3]] } last_day: /last_day/i '(' bin_op ')' { [@item[1,3]] } date_format: /date_format/i '(' list_bin_op bin_op ')' { [@item[1,3,4]] } # just the list of all the functions function: if | concat | left | right | ifnull | now | length_func | interval | last_day | date_format number: /[+-]?(?:\d+\.?\d*|\.\d+)/ { $item[1] } list_bin_op: bin_op ',' { $item[1] } string: { if(!$item[1][0] && ($item[1][1] eq '"' || $item[1][1] eq "'")) { [$item[0],$item[1][2]]; } else { undef; } }