Skip to content

Instantly share code, notes, and snippets.

@amieres
Last active August 29, 2015 14:01
Show Gist options
  • Save amieres/d6bc0164a48240805952 to your computer and use it in GitHub Desktop.
Save amieres/d6bc0164a48240805952 to your computer and use it in GitHub Desktop.
wexpr = () => P(() => expr(0) && EOS() );
expr = (L) => P(() => mexpr() && expr2(L) );
expr2 = (L) => P(() => L < 4 && C("+") && expr(4) && expr2(L) )
|| P(() => L < 4 && C("-") && expr(4) && expr2(L) )
|| P(() => L < 5 && C("*") && expr(5) && expr2(L) )
|| P(() => L < 5 && C("/") && expr(5) && expr2(L) )
|| P(() => L < 2 && C("<=") && expr(2) && expr2(L) )
|| P(() => L < 2 && C(">=") && expr(2) && expr2(L) )
|| P(() => L < 2 && C("<>") && expr(2) && expr2(L) )
|| P(() => L < 2 && C("=") && expr(2) && expr2(L) )
|| P(() => L < 2 && C("<") && expr(2) && expr2(L) )
|| P(() => L < 2 && C(">") && expr(2) && expr2(L) )
|| P(() => L < 1 && W("AND") && expr(1) && expr2(L) )
|| P(() => L < 1 && W("OR") && expr(1) && expr2(L) )
|| P(() => NIL() );
mexpr = () => P(() => C("-") && expr(9) )
|| P(() => C("+") && expr(9) )
|| P(() => W("NOT") && expr(9) )
|| P(() => C("(") && expr(0) && C(")") )
|| P(() => W("CASE") && whexp() && W("END") )
|| P(() => NUMBER() )
|| P(() => ID() && id2() );
whexp = () => P(() => W("WHEN") && expr(0) && W("THEN") && expr(0) && whexp2() );
whexp2 = () => P(() => whexp() )
|| P(() => W("ELSE") && expr(0) )
|| P(() => NIL() );
id2 = () => P(() => C("(") && list() && C(")") )
|| P(() => NIL() );
list = () => P(() => expr(0) && list2() )
|| P(() => NIL() );
list2 = () => P(() => C(",") && expr(0) && list2() )
|| P(() => NIL() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment