Skip to content
BENIBIX Learn

Parser

Development⚙️ Compilers & RuntimesCompilation

Also known as Parsing, Code Parser

A program that reads text and finds how its parts fit.

Think of it like

Think of it like a teacher reading a sentence. They check each word fits the rules of grammar.

Example

Lucy's app gets a line of JSON text from a server. JSON.parse reads it and hands back an object. Now she can ask for its age field.

Why it matters

All code and all data files go through a parser first. Nothing else can happen before that.

Definition

A parser is a program that reads text and works out its structure. It checks that the text follows the rules of its language. If it does, the parser turns it into a shape the program can use, often a tree. If not, it stops with an error, which is where a syntax error comes from. Compilers, browsers and JSON readers all start with a parser.

Example code

console
$ node -e 'console.log(JSON.parse("{\"name\":\"Emma\",\"age\":9}").age)'
9
The parser turns plain text into an object, so the age can be read.

Common mistake

Trying to read a structured format, like HTML or JSON, with your own text search. Use a real parser instead.

Key takeaways

  1. 1
    Text in. Plain characters, one after another.
  2. 2
    Structure out. Often a tree.
  3. 3
    Grammar check. Bad input stops here.