What Does Parser Mean?
A parser is the part of a compiler that breaks source code into small sections of character strings called tokens.
The term has its roots in linguistics. In linguistics, parsing involves physically diagraming the underlying structure of a sentence. The purpose is to help the learner understand the context of each sentence element and its relationship to the meaning of the sentence.
In computing, parsers create logical diagrams called trees. The purpose is to help the compiler understand the context of each token and its relationship to the underlying structure of the source code.
Parsers are widely used in the following technologies:
-
Java and other programming languages.
-
Database languages such as SQL.
-
Modeling languages, such as virtual reality modeling language (VRML).
-
Scripting languages such as Javascript.
-
Protocols, such as HTTP.
Techopedia Explains Parser
The technical process of parsing has three stages:
-
Lexical Analysis: produces tokens from a stream of input characters. A token is the smallest unit in a programming language that possesses some meaning (such as +, -, *, “function”, or “new” in JavaScript).
-
Syntactic Analysis: checks to see if the generated tokens form a meaningful expression.
-
Semantic Parsing: uses syntax trees and symbol look-up tables to determine whether the generated tokens are semantically consistent with a specific programming language.
Parsing can be conducted in either a top-down or bottom-up manner.
-
Top-Down Parsing: Parsing begins with the start symbol and trees are built from root to leaves. Top-down parsing is also called predictive parsing or recursive parsing.
-
Bottom-Up Parsing: Trees are built from leaves to root and ends with the start symbol. This type of parsing is also known as shift-reduce parsing.