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? :/

Recommended Answers

All 3 Replies

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"))))) .

How do we use it?

Oh, and how close was my stupid guess? :P

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.