timrach / algebra-parser

Parse algebraic expressions and equations as string and convert them to algebra.js representation
0 stars 0 forks source link

Handle named functions #2

Open ivanistheone opened 9 years ago

ivanistheone commented 9 years ago

I was wondering how sin(x) would get parsed --- sin * x ? Would be cool to "recognize" some identifiers as being function calls, e.g. IDENTIFIER followed by (should be interpreted as function name, and then parse its arguments).

BTW, have you seen the KaTeX parser and lexer? https://github.com/Khan/KaTeX/blob/master/src/Parser.js https://github.com/Khan/KaTeX/blob/master/src/Lexer.js

timrach commented 9 years ago

I use Dijkstra's shunting yard algorithm to parse the expressions which also supports function calls. As the algebra.js library does not allow such calls, i cut that out of the parsing method. But it is easy to add function recognition if/when the library adds evaluation support.

I like the KaTeX parser and lexer. Fortunately algebra is context free and doesn't need such a beast of a parser :)