Skip to content

Instantly share code, notes, and snippets.

@egonelbre
Created August 4, 2012 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egonelbre/3259101 to your computer and use it in GitHub Desktop.
Save egonelbre/3259101 to your computer and use it in GitHub Desktop.
terenary operator
// testing place
http://egonelbre.com/js/bigram/
// test input
a = c ? t + 4 : f + 3 ? a : b
// replace the tokens on the right side with these:
// version: C ?( T ): F
tokens = {
"=" : [7],
"?" : [6.5, next], ":" : [6.5, "<"],
"==" : [6],
"+" : [5], "-" : [5],
"*" : [4], "/" : [4],
"!" : [1, prefix], "~" : [1, prefix],
"^" : [1],
" " : [-1],
"(" : [0, next], ")" : [0, "<"]
};
// version C ? ( T : F )
tokens = {
"=" : [7],
"?" : [6.5], ":" : [6.5],
"==" : [6],
"+" : [5], "-" : [5],
"*" : [4], "/" : [4],
"!" : [1, prefix], "~" : [1, prefix],
"^" : [1],
" " : [-1],
"(" : [0, next], ")" : [0, "<"]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment