Lexical Analysis - compiler design IT & Software Notes | EduRev

IT & Software : Lexical Analysis - compiler design IT & Software Notes | EduRev

 Page 1


Lexical Analysis 
Page 2


Lexical Analysis 
The Scanner 
? The job of the scanner is to read characters 
from the source code and form them into 
tokens.  
? Token classes include: 
– Identifiers 
– Literals (numeric, string, character) 
– Keywords and reserved words 
– Operators 
– Others 
Page 3


Lexical Analysis 
The Scanner 
? The job of the scanner is to read characters 
from the source code and form them into 
tokens.  
? Token classes include: 
– Identifiers 
– Literals (numeric, string, character) 
– Keywords and reserved words 
– Operators 
– Others 
Representing Tokens 
? using the #define macro (C/C++): 
 
 #define IF 256 
 #define THEN 257 
 #define ELSE 258 
 ... 
Page 4


Lexical Analysis 
The Scanner 
? The job of the scanner is to read characters 
from the source code and form them into 
tokens.  
? Token classes include: 
– Identifiers 
– Literals (numeric, string, character) 
– Keywords and reserved words 
– Operators 
– Others 
Representing Tokens 
? using the #define macro (C/C++): 
 
 #define IF 256 
 #define THEN 257 
 #define ELSE 258 
 ... 
Representing Tokens 
? Using named constants (Java): 
 
 public static final IF = 256; 
 public static final THEN = 257; 
 public static final ELSE = 258; 
 ... 
Page 5


Lexical Analysis 
The Scanner 
? The job of the scanner is to read characters 
from the source code and form them into 
tokens.  
? Token classes include: 
– Identifiers 
– Literals (numeric, string, character) 
– Keywords and reserved words 
– Operators 
– Others 
Representing Tokens 
? using the #define macro (C/C++): 
 
 #define IF 256 
 #define THEN 257 
 #define ELSE 258 
 ... 
Representing Tokens 
? Using named constants (Java): 
 
 public static final IF = 256; 
 public static final THEN = 257; 
 public static final ELSE = 258; 
 ... 
Representing Tokens 
? Token classes may have attributes 
– Identifiers have a string name 
– Numeric literals have a value 
– Relational operators have 1 of 6 values 
? We need more than a single scalar object to 
represent tokens. 
– struct 
– class 
Read More
Offer running on EduRev: Apply code STAYHOME200 to get INR 200 off on our premium plan EduRev Infinity!

Related Searches

shortcuts and tricks

,

ppt

,

Lexical Analysis - compiler design IT & Software Notes | EduRev

,

MCQs

,

Semester Notes

,

Viva Questions

,

Previous Year Questions with Solutions

,

Lexical Analysis - compiler design IT & Software Notes | EduRev

,

Extra Questions

,

Objective type Questions

,

Important questions

,

Free

,

Exam

,

past year papers

,

video lectures

,

mock tests for examination

,

pdf

,

Sample Paper

,

practice quizzes

,

Lexical Analysis - compiler design IT & Software Notes | EduRev

,

Summary

,

study material

;