Task 1: For the following sample program find all the tokens. Note that a lexical Analyzer is responsible for 1. Scan In

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Task 1: For the following sample program find all the tokens. Note that a lexical Analyzer is responsible for 1. Scan In

Post by answerhappygod »

Task 1: For the following sample program find all thetokens.Note that a lexical Analyzer is responsible for1. Scan Input2. Remove WS, NL, ...3. Identify Tokens4. Create Symbol Table (ST)
in python5. Insert Tokens into ST6. Generate Errors7. Send Tokens to Parser
Fig 1: Lexical Analyzer
Input:int a, b, c;float d, e;a = b = 5;c = 6;if ( a > b){
Page 4 of
c = a - b;e = d - 2.0;}else{d = e + 6.0;b = a + c;}Output:Keywords: int, float, if, elseIdentifiers: a, b, c, d, eMath Operators: +, -, =Logical Operators: >Numerical Values: 5, 6, 2.0, 6.0Others: , ; ( ) { }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply