---
title: "What is lexical analysis and syntax analysis in a compiler?"  
description: "What is lexical analysis and syntax analysis in a compiler?"  
author: "Utpal Vishwas"  
published: 2023-04-07  
updated: 2023-04-08  
canonical: https://www.mindstick.com/forum/157727/what-is-lexical-analysis-and-syntax-analysis-in-a-compiler  
category: "compiler design"  
tags: ["computer hardware", "computer system"]  
reading_time: 1 minute  

---

# What is lexical analysis and syntax analysis in a compiler?

What is lexical [analysis](https://www.mindstick.com/articles/323533/prospective-analysis) and syntax analysis in a [compiler](https://www.mindstick.com/articles/27/just-in-time-compiler)?

## Replies

### Reply by Krishnapriya Rajeev

*Lexical analysis* and *syntax analysis* are two phases of the compilation process that help translate a high-level programming language into machine code that a computer can understand.

**Lexical analysis**, also known as scanning, is the first phase of the compilation process. It reads the source code character by character and groups them into meaningful sequences called *lexemes.* It then produces tokens, which are pairs of a token name and an attribute value. The tokens are passed on to the next phase, syntax analysis. Tokens are of the form <token-name, attribute-value> for each lexeme.

**Syntax analysis**, also known as parsing, is the second phase of the compilation process. It takes the tokens produced by the lexical analyzer and arranges them into a tree-like structure called a syntax tree or parse tree. The syntax tree creates a tree-like representation that shows the grammatical structure of the token stream. The syntax analyzer reports any syntax errors to the programmer if it finds any.


---

Original Source: https://www.mindstick.com/forum/157727/what-is-lexical-analysis-and-syntax-analysis-in-a-compiler

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
