What is parsing and how do I use it?

My guess is that parsing is something that locates a keyword in a statement.

My guess, okay? I don't understand wiki. If it isn't, is there something that can locate something in a statement and do something if it finds it? :/

Parsing usually means 'grammatical analysis'. A parser is a program which understands the structure of a text and extracts information from the text according to this structure. For exemple with the expression x + 2* y , a mathematical parser could produce the python structure ("binary_expression", ("operator", "+"), ( ("name", "x"), ("binary_expression", ("operator", "*"), ( ("integer", 2), ("name", "y"))))) .

Well, the output of a parser is much easier to manipulate programmatically than the input text. Almost every program which manipulates text and does something with the text's content uses a parser. For example the python interpreter must 'understand' your code to run it. It first parses the code to produce a syntax tree and then uses this syntax tree to produce bytecode which can be executed.

If you want to experiment with what parsing means, you should start using a simple parser for html for example. Install the module lxml and parse an html page as described in the lxml documentation. The result is a tree of nodes which contain the information of the html page. Try to use this tree to extract information from the page. See http://codespeak.net/lxml/

If you want to write parsers yourself, you could install the wisent module http://seehuhn.de/pages/wisent, read the tutorial, then try to write your own simple grammar rules and create your first parser.

Edited 6 Years Ago by Gribouillis: n/a

This article has been dead for over six months. Start a new discussion instead.