4 ms·
I'm reading "Programming: Principles and Practice Using C++" and one of the first programs illustrated is actually a calculator. Being new to parsers in general
by varlock 11y ago
I'm reading "Programming: Principles and Practice Using C++" and one of the first programs illustrated is actually a calculator.
Being new to parsers in general, I love to see how two different approaches work: in the book the author implements the code by creating a formal (BNF-like) grammar first whereas in this articles the author draws diagrams first.
- rednab 11y agoIn case you didn't know yet, a BNF grammar always is a graph. So the diagram is just a different way of depicting the same thing. For example, the (E)BNF¹ for the graph in the article is: expr = term { ("+" | "-") term } where the accolades indicate zero-or-more repetition. This actually is important because if your grammar can be written down as a graph it means it is a context-free grammar². Parsing is a wonderful subject to study thanks to the depth of the subject and the breath of texts available explaining it. Have fun! ¹) https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_F... ²) https://en.wikipedia.org/wiki/Context-free_grammar https://en.wikipedia.org/wiki/Context-free_grammar
- varlock 11y agoI honestly didn't know! Thanks for the pointers!