"Like, I mean, you know, when I do it it's done!" - N. M.
Raw input:
Formatted:
...
Notation polonaise: [just traverse the tree, right to left, top to bottom, and print branches and leafs]
L'arbre de décomposition:
Eh?
2018-09-05
- After skimming through the first three chapters of Ullman's dragon book (1000 pages about compilers *-*) and reading the first chapter of my college's LM ("Logique Mathématique") course, using what stick in my mind, I decided to write a "parser" for mathematical logic expressions (in addition to a few tricks...)
- For some reason, a 200-line parser I wrote in JavaScript, didn't work correctly.
- I almost gave in to Despair... but then Miss Minaj inspired me, "...don't say you can't, say you can, say you can-can..." (Handstand - Nicki Minaj)
- THEN, I actually reread the effing book and even checked a compiler's source code: @MellowCobra/JS-Pascal-Interpreter. (See what I'm doing? I'm acknowledging people's works. I'm a good boy -- I rip off nobody.)
- Don't expect this thing to work: Tested on Google Chrome 69 (on desktop, so it will probably look like shit on mobile devices); complied using Google's Closure Compiler so that it may work on older versions.
- I used no library to draw the graph: Using my zero knowledge of SVG, I wrote a script that draws the abstract parse tree directly to SVG (after examining and experimenting with a simple parse tree I found on Wikimedia Commons)
- I'M WELL AWARE OF SOME PROBLEMS IN IT AND HAVE IDEAS ON HOW TO FIX THEM
* When drawing complex expressions, nodes end up on top of one another. Fix: Treat nodes as physical objects and apply physics on them; or, start with a large distance between nodes, and reduce it after each depth level...
* It doesn't properly respect priorities: the "NOT" operator has higher priority than the rest, yet it's being treated as the AND/OR operators. Fix: add extra parenthesis: For example, !A+B becomes (!A)+B and !(A+B)*C becomes (!(A+B))*C