Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is parsing in terms that a new programmer would understand? [closed]

I am a college student getting my Computer Science degree. A lot of my fellow students really haven't done a lot of programming. They've done their class assignments, but let's be honest here those questions don't really teach you how to program.

I have had several other students ask me questions about how to parse things, and I'm never quite sure how to explain it to them. Is it best to start just going line by line looking for substrings, or just give them the more complicated lecture about using proper lexical analysis, etc. to create tokens, use BNF, and all of that other stuff? They never quite understand it when I try to explain it.

What's the best approach to explain this without confusing them or discouraging them from actually trying.

like image 214
Daisetsu Avatar asked May 28 '10 23:05

Daisetsu


People also ask

What does parsing mean in programming?

What Does Parse Mean? To parse, in computer science, is where a string of commands – usually a program – is separated into more easily processed components, which are analyzed for correct syntax and then attached to tags that define each component.

What does it mean to parsing?

1a : to divide (a sentence) into grammatical parts and identify the parts and their relations to each other. b : to describe (a word) grammatically by stating the part of speech and explaining the inflection (see inflection sense 2a) and syntactical relationships.

What is the meaning of parsing of data?

Data parsing is a method where one string of data gets converted into a different type of data. So let's say you receive your data in raw HTML, a parser will take the said HTML and transform it into a more readable data format that can be easily read and understood.

What is parsing problem in programming language?

Parsing is the problem of transforming a linear sequence of characters into a syntax tree. Nowadays we are very good at parsing. In other words, we have many tools, such as lex and yacc, for instance, that helps us in this task. However, in the early days of computer science parsing was a very difficult problem.


2 Answers

I'd explain parsing as the process of turning some kind of data into another kind of data.

In practice, for me this is almost always turning a string, or binary data, into a data structure inside my Program.

For example, turning

":Nick!User@Host PRIVMSG #channel :Hello!" 

into (C)

struct irc_line {     char *nick;     char *user;     char *host;     char *command;     char **arguments;     char *message; } sample = { "Nick", "User", "Host", "PRIVMSG", { "#channel" }, "Hello!" } 
like image 77
LukeN Avatar answered Sep 28 '22 11:09

LukeN


Parsing is the process of analyzing text made of a sequence of tokens to determine its grammatical structure with respect to a given (more or less) formal grammar.

The parser then builds a data structure based on the tokens. This data structure can then be used by a compiler, interpreter or translator to create an executable program or library.

alt text
(source: wikimedia.org)

If I gave you an english sentence, and asked you to break down the sentence into its parts of speech (nouns, verbs, etc.), you would be parsing the sentence.

That's the simplest explanation of parsing I can think of.

That said, parsing is a non-trivial computational problem. You have to start with simple examples, and work your way up to the more complex.

like image 39
Robert Harvey Avatar answered Sep 28 '22 11:09

Robert Harvey