I looked at the solution to the problem in javascript, namely, parsed the string into its compound names, operators and brackets when I saw this expression:
return accept(")") ? _|_ : e;
What is that _|_? Is the node function used _? I was looking for documentation but not found.
When I try to use it myself, this happens:
> 5
5
> true ? _|_ : 0
ReferenceError: _ is not defined
at eval:1:1
at eval
at n.<anonymous>
As an explanation, the variable was _not defined anywhere in the code.
This was run on node v8.1.3, but also works fine on the Chrome JS built-in browser.
Here is the code:
function tokenise(string) {
const tokens = string.match( /[a-z]+|\(|\)|[!#$%&*+\-\/<=>@^_.,;]+/gi ) || [];
const accept = s => s===tokens[0] && tokens.shift() ;
const unaccept = s => s!==tokens[0] && tokens.shift() ;
const singles = (e) => ( e = unaccept(")") ) ? [ e, ...brackets() ] : [] ;
const brackets = (e) => accept("(") ? ( e = brackets(), accept(")") || _|_ , [ e, ...brackets() ] ) : singles() ;
try { let e = brackets(); return accept(")") ? _|_ : e ; }
catch(_) { return null; }
}
source
share