/Parser-Learning

My parser Implementation for LeetCode problem 227. Basic Calculator II

Primary LanguagePythonMIT LicenseMIT

Parser-Learning

This repository contains many of my parser Implementation for LeetCode problem 227. Basic Calculator II. I also posted the same content into leetcode discussion, you can check the post there directly.

Why should I learn parser?

A way to dive deep into the details of PEP617 is to get your hands dirty. And leetcode is one of the best online judges to verify the implementation.

Resource to learn Compiler

If you are like me before without a background in language parsing, here is the resource I used.

Firstly, Leetcode contains many parsing related questions, 227. Basic Calculator II is one of the simplest one with just enough constraints for learning, which only requires to handle 5 type of symbols: + - * / and number, and all the input strings are valid.

Secondly, before I started my study, there were only LL(1) parser and Operator Precedence parser posts in discussion, LR(0), and Packrat parser were missing. Even if you search the related simple implementation in Google or other search engines, there's actually no organized work like this. (Implement all sorts of parsers for the same problem.)

Unpromised TODO(?)

  • Add CST parser for LL(1)'s non-recursive parser
  • Write PEG parser from scratch