Skip to content

Add exponentation, sqrt, sin, cos, tan operators #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions resources/gensql/query/base.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ scalar-expr ::= scalar-expr-0
<scalar-expr-3> ::= scalar-expr-4 | expr-binop
<scalar-expr-4> ::= scalar-expr-5 | expr-addition | expr-subtraction
<scalar-expr-5> ::= scalar-expr-6 | expr-multiplication | expr-division
<scalar-expr-6> ::= scalar-expr-7 | expr-function-call
<scalar-expr-6> ::= scalar-expr-7 | expr-exponentiation
<scalar-expr-7> ::= scalar-expr-8 | expr-function-call

expr-disjunction ::= scalar-expr-0 ws #'(?i)OR' ws scalar-expr-1
expr-conjunction ::= scalar-expr-1 ws #'(?i)AND' ws scalar-expr-2
Expand All @@ -140,9 +141,15 @@ expr-subtraction ::= scalar-expr-4 ws? '-' ws? scalar-expr-5
expr-multiplication ::= scalar-expr-5 ws? '*' ws? scalar-expr-6
expr-division ::= scalar-expr-5 ws? '/' ws? scalar-expr-6

expr-exponentiation ::= scalar-expr-6 ws? '^' ws? scalar-expr-7

(* currently only log - will likely add more later *)
<expr-function-call> ::= expr-function-call-log
<expr-function-call> ::= expr-function-call-log | expr-function-call-sqrt | expr-function-call-sin | expr-function-call-cos | expr-function-call-tan
expr-function-call-log ::= 'log(' ws? scalar-expr-6 ws? ')'
expr-function-call-sqrt ::= 'sqrt(' ws? scalar-expr-6 ws? ')'
expr-function-call-sin ::= 'sin(' ws? scalar-expr-6 ws? ')'
expr-function-call-cos ::= 'cos(' ws? scalar-expr-6 ws? ')'
expr-function-call-tan ::= 'tan(' ws? scalar-expr-6 ws? ')'

scalar-expr-group ::= '(' ws? scalar-expr ws? ')'

Expand Down
2 changes: 1 addition & 1 deletion resources/gensql/query/permissive.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<scalar-expr-0> ::= scalar-expr-1 | expr-disjunction | probability-expr | mutual-info-expr
<scalar-expr-7> ::= scalar-expr-group | identifier | value
<scalar-expr-8> ::= scalar-expr-group | identifier | value

(* model-expr *)

Expand Down
2 changes: 1 addition & 1 deletion resources/gensql/query/strict.bnf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<scalar-expr-7> ::= scalar-expr-group
<scalar-expr-8> ::= scalar-expr-group
| identifier
| value
| probability-expr
Expand Down
6 changes: 5 additions & 1 deletion src/gensql/query/scalar.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
[:expr-subtraction left _ right] `(~'- ~(plan left) ~(plan right))
[:expr-multiplication left _ right] `(~'* ~(plan left) ~(plan right))
[:expr-division left _ right] `(~'/ ~(plan left) ~(plan right))
[:expr-exponentiation left _ right] `(~'pow ~(plan left) ~(plan right))

[:expr-function-call-log _log child _] `(~'log ~(plan child))
[:expr-function-call-sqrt _sqrt child _] `(~'sqrt ~(plan child))

[:expr-binop left [:binop [:is _]] right] `(~'= ~(plan left) ~(plan right))
[:expr-binop left [:binop [:is-not & _]] right] `(~'not= ~(plan left) ~(plan right))
Expand Down Expand Up @@ -299,7 +301,9 @@
'- (nil-safe (auto-unbox -))
'* (nil-safe (auto-unbox *))
'/ (nil-safe (auto-unbox /))
'log (nil-safe (auto-unbox math/log))}
'pow (nil-safe (auto-unbox math/pow))
'log (nil-safe (auto-unbox math/log))
'sqrt (nil-safe (auto-unbox math/sqrt))}
'gensql {'safe-get safe-get
'prob prob
'pdf pdf
Expand Down