Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Recognition of Tokens - Lexical Analysis, Computer Science and IT Engineering

Recognition of Tokens - Lexical Analysis, Computer Science and IT Engineering - Computer Science Engineering (CSE) PDF Download

RECOGNITION OF TOKENS

For this language fragment the lexical analyzer will recognize the keywords if, then, else, as well as the lexemes denoted by relop, id, and num.

Consider the following grammar fragment: stmt → if expr then stmt

| if expr then stmt else stmt | ε

expr → term relop term

| term

term → id | num


where the terminals if , then, else, relop, id and num generate sets of strings given by the following regular definitions:

if → if

then → then

else → else

relop → <|<=|=|<>|>|>=

id → letter(letter|digit)*

num → digit+ (.digit+)?(E(+|-)?digit+)?


For this language fragment the lexical analyzer will recognize the keywords if, then, else, as well as the lexemes denoted by relop, id, and num. To simplify matters, we assume keywords are reserved; that is, they cannot be used as identifiers.

 

Transition diagrams

It is a diagrammatic representation to depict the action that will take place when a lexical analyzer is called by the parser to get the next token. It is used to keep track of information about the characters that are seen as the forward pointer scans the input.

The document Recognition of Tokens - Lexical Analysis, Computer Science and IT Engineering - Computer Science Engineering (CSE) is a part of Computer Science Engineering (CSE) category.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)

Top Courses for Computer Science Engineering (CSE)

FAQs on Recognition of Tokens - Lexical Analysis, Computer Science and IT Engineering - Computer Science Engineering (CSE)

1. What is lexical analysis in computer science?
Ans. Lexical analysis, also known as scanning, is the first phase of the compiler design process. It involves breaking down a sequence of characters into meaningful elements called tokens. These tokens represent the basic building blocks of a programming language, such as keywords, identifiers, operators, and literals.
2. What is the purpose of token recognition in lexical analysis?
Ans. The purpose of token recognition in lexical analysis is to identify and classify different tokens present in the source code of a program. By recognizing tokens, the lexical analyzer can provide the subsequent phases of the compiler with a structured representation of the program, which simplifies the parsing and analysis processes.
3. How does lexical analysis work in computer science?
Ans. Lexical analysis works by scanning the source code character by character and identifying tokens based on predefined patterns or regular expressions. It uses a technique called finite automaton to match the input characters against the patterns and generate tokens as output. The lexical analyzer then passes these tokens to the next phase of the compiler for further processing.
4. What are some examples of tokens in lexical analysis?
Ans. In lexical analysis, tokens can vary depending on the programming language being analyzed. However, some common examples of tokens include keywords (e.g., if, else, while), identifiers (variable names), operators (+, -, *, /), literals (numbers, strings), and punctuation symbols (brackets, commas, semicolons).
5. How does lexical analysis contribute to the overall compilation process?
Ans. Lexical analysis is a crucial step in the compilation process as it provides a structured representation of the program through tokens. This structured representation simplifies subsequent phases of the compiler, such as parsing, semantic analysis, and code generation. By breaking down the source code into tokens, lexical analysis helps in identifying syntax errors, building symbol tables, and generating intermediate code or machine instructions.
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

Important questions

,

Recognition of Tokens - Lexical Analysis

,

practice quizzes

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

Exam

,

video lectures

,

ppt

,

Objective type Questions

,

Sample Paper

,

mock tests for examination

,

Previous Year Questions with Solutions

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

Summary

,

Extra Questions

,

study material

,

MCQs

,

Recognition of Tokens - Lexical Analysis

,

pdf

,

shortcuts and tricks

,

Free

,

past year papers

,

Viva Questions

,

Semester Notes

,

Recognition of Tokens - Lexical Analysis

;