Docsity

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

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