Assignment 1: Problem Description In this assignment, your job is to program a simple lexical analyzer that will build a symbol table from given stream of chars. You will need to read a file named "input.txt" to collect all chars. For simplicity, input file will be a C program without headers and methods. Then you will identify all the numerical values, identifiers, keywords, math operators, logical operators and others   [distinct]. See the example for more details. You can assume that, there will be a space after each keywords. But, removal of space will add bonus point. Lab 1: Activity List Task 1: For the following sample program find all the tokens. Note that a lexical Analyzer is responsible for Scan Input Remove WS, NL, ... Identify Tokens Create Symbol Table (ST) Insert Tokens into ST Generate Errors Send Tokens to Parser Fig 1: Lexical Analyzer Input: int a, b, c; float d, e; a = b = 5; c = 6; if ( a > b) { c = a - b; e = d - 2.0; } else { d = e + 6.0; b = a + c; } Output: Keywords: int, float, if, else Identifiers: a, b, c, d, e Math Operators: +, -, = Logical Operators: > Numerical Values: 5, 6, 2.0, 6.0 Others: , ; ( ) { }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Assignment 1: Problem Description

In this assignment, your job is to program a simple lexical analyzer that will build a symbol table from given stream of chars. You will need to read a file named "input.txt" to collect all chars. For simplicity, input file will be a C program without headers and methods. Then you will identify all the numerical values, identifiers, keywords, math operators, logical operators and others

 

[distinct]. See the example for more details. You can assume that, there will be a space after each keywords. But, removal of space will add bonus point.

Lab 1: Activity List

Task 1: For the following sample program find all the tokens.

Note that a lexical Analyzer is responsible for

  1. Scan Input
  2. Remove WS, NL, ...
  3. Identify Tokens
  4. Create Symbol Table (ST)
  5. Insert Tokens into ST
  6. Generate Errors
  7. Send Tokens to Parser

Fig 1: Lexical Analyzer

Input: int a, b, c;

float d, e;

a = b = 5;

c = 6;

if ( a > b)

{

c = a - b;

e = d - 2.0;

}

else

{

d = e + 6.0;

b = a + c;

}

Output:

Keywords: int, float, if, else

Identifiers: a, b, c, d, e

Math Operators: +, -, =

Logical Operators: >

Numerical Values: 5, 6, 2.0, 6.0

Others: , ; ( ) { }

token
lexical
source
аnalyzer
parser
program
get next
token
symbol
table
Fig 1: Lexical Analyzer
Transcribed Image Text:token lexical source аnalyzer parser program get next token symbol table Fig 1: Lexical Analyzer
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY