| ▲ | ckok a year ago | ||||||||||||||||
I think this makes it sound a lot more difficult than it has to be, with the formal theory. When it's really one of the most simple things if you divide it in parts and look at it from a tokenizer (string to list of tokens) and parser on top. Where the tokenizer can usually be very simple: a loop, large switch on the current character, where a choice is made on "what can this be", and making it into a formal token or error. Then a simple recursive parser that can almost be a 1 to 1 copy of the (E)BNF. | |||||||||||||||||
| ▲ | jrop a year ago | parent | next [-] | ||||||||||||||||
I love writing parsers like this. Add in Pratt Parsing for operator precedence and writing parsers can be really easy. | |||||||||||||||||
| ▲ | detourdog a year ago | parent | prev | next [-] | ||||||||||||||||
I got the impression the author was trying to add higher level reasoning to the chosen term for string to AST parsing. I felt that they were pointing out how the cognitive load of understanding is effected by word choice. | |||||||||||||||||
| |||||||||||||||||
| ▲ | joz1-k a year ago | parent | prev | next [-] | ||||||||||||||||
I had exactly the same feeling as you after reading the article. And interestingly, all production parsers for all major languages are hand-written recursive descent parsers. On the other hand, if you inspect the actual code for these production parsers (even for newer languages like Swift, Scala, Kotlin, or Rust), the complexity and amount of code is still quite staggering. | |||||||||||||||||
| |||||||||||||||||
| ▲ | antononcube a year ago | parent | prev | next [-] | ||||||||||||||||
It seems you are describing how functional parsers (aka parser combinators) work. (BTW, there is a "Parser combinators" section in the featured post/article.) | |||||||||||||||||
| |||||||||||||||||
| ▲ | DemocracyFTW2 a year ago | parent | prev | next [-] | ||||||||||||||||
IMHO it gets even better when you can use regular expressions and write a 'modal' parser where each mode is responsible for a certain sub-grammar, like string literals. JavaScript added the sticky flag (y) to make this even simpler. | |||||||||||||||||
| |||||||||||||||||
| ▲ | a year ago | parent | prev [-] | ||||||||||||||||
| [deleted] | |||||||||||||||||