Lexical Analysis (Compiler), Schemes and Mind Maps of Compiler Construction

It a topic of Compiler Construction

Typology: Schemes and Mind Maps

2021/2022

Uploaded on 06/04/2022

muhammad-faisal-9
muhammad-faisal-9 ๐Ÿ‡ต๐Ÿ‡ฐ

3 documents

1 / 52

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COMPILER CONSTRUCTION
LECTURE 2
Muhammad Fawad Nasim
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34

Partial preview of the text

Download Lexical Analysis (Compiler) and more Schemes and Mind Maps Compiler Construction in PDF only on Docsity!

COMPILER CONSTRUCTION

LECTURE 2

Muhammad Fawad Nasim [email protected]

Recap

  1. Analysis Phase
  2. Synthesis Phase

Synthesis Phase

๏‚ž Generates the target program with the help of intermediate source code representation and symbol table.

Lexical Errors

๏‚ž A character sequence that cannot be scanned into any valid token is a lexical error. ๏‚ž Lexical errors are uncommon, but they still must be handled by a scanner. ๏‚ž Misspelling of identifiers, keyword, or operators are considered as lexical errors. ๏‚ž Usually, a lexical error is caused by the appearance of some illegal character, mostly at the beginning of a token.

1-Lexical

Analysis

A lexical analyzer reads characters from the input and groups them into "token objects."

Assignment(Python) = Lexical

Analyzer

Logical Implementation

1. Scanning consists of the simple processes that do not require tokenization of the input, such as deletion of comments and compaction of consecutive whitespace characters into one.

  1. Lexical analysis proper is the more complex portion, where the scanner produces the sequence of tokens as output.

The role of lexical analyzer

Lexical Analyzer Parser Source program token getNextToken Symbol table To semantic analysis

Tokens Lexeme Patterns

In programming language, keywords, constants, identifiers, strings, numbers, operators and punctuations symbols can be considered as tokens. Types of Tokens Keywords (words that convey a special meaning to the language compiler. do, float etc in c++) Identifiers (variable names etc) Literals (constant) Punctuators (โ€œโ€, ; [] {}) Operators (+,/ etc)

Tokens Lexeme Patterns

Example 1

int value = 100;

๏‚ž int (keyword), value (identifier), = (operator), 100 (constant) and ; (symbol).

Tokens Lexeme Patterns