Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example parsers to learn how to write them [closed]

I am looking for source codes of parsers and/or parser generators that could be studied in order to develop further, my skills that I acquired during a school course. Do you know any recommendable parsers of any type?

like image 509
gregory561 Avatar asked Feb 25 '12 21:02

gregory561


People also ask

What is parser example?

Examples include LL parsers and recursive-descent parsers. Top-down parsing is also called predictive parsing or recursive parsing. Bottom-Up Parsing: Involves rewriting the input back to the start symbol.

What is parsing in writing?

Pantsing (also known as winging it) is the term Wrimos use refer to writing without a fixed outline (an outline that the writer will force themselves to follow). A Wrimo who adopts the pantsing approach to writing is called a pantser.


3 Answers

You should know how to build recursive descent parsers by hand. Here's an SO link to a quick lesson on how to do this: https://stackoverflow.com/a/2336769/120163

If you want to understand how recursive descent parsers can be constructed automatically, you can read a paper (and see a tutorial) on MetaII at this link: https://stackoverflow.com/a/1142034/120163

like image 198
Ira Baxter Avatar answered Sep 28 '22 01:09

Ira Baxter


  • Bison is a classical example (C/C++).
  • Pyparsing is a great module, and it is very easy to use (Python) .
  • Lemon is very easy to use (C++).

Check the examples, and good luck.

Edit:

I guess I should comment. A parser is a program which processes an input and "understands" it. A parser generator is a tool used to write parsers. I guess you mean you want to learn more about generating parsers, in which case, you should refer to the documentation of parser generators (all of the above).

like image 33
Escualo Avatar answered Sep 28 '22 02:09

Escualo


Parsers themselves are usually not that interesting, it's the generators of parsers that are more of a subject of study.

  • ANTLR generates LL parsers which are easily readable once generated. (Java)
  • Bison generates LALR(1) parsers which are impossible to read. (C)

If LALR(1) interests you, I have a library up on github that tries to do a new number on LALR parsing. Feel free to take a look. It's in C# and I've tried my finest to make the code comprehensible. It's been a learning project for me, but it's smaller than the big tools and a bit easier to penetrate. And definitely feel free to contribute, lots of features to add still.

Otherwise, take a look at the generated code of these tools to see how they build the actual parsers that do the work.

like image 33
Dervall Avatar answered Sep 28 '22 02:09

Dervall