Question: Hello! Need help in C++, C, or Java. I need to open a .txt file and have the program read and tokenize each character. The

Hello! Need help in C++, C, or Java.

I need to open a .txt file and have the program read and tokenize each character. The program should be able to parse the file and then print out each char the file has, say what type of token it is, the lexeme, and which line and column the lexeme is found.

for example: file.txt has: Hello! Need help in C++, C, or Java. I need to open and the output should look like: start reading to scan file: file.txt keyword, symbol: import line:1 string literal, symbol: "scl.h" line 1 keyword, symbol: function line: 3 keyword, symbol: main line: 3 keyword, symbol: return line: 3 keyword, symbol: type line: 3 keyword, symbol: integer line: 3 keyword, symbol: is line: 3 keyword, symbol: variables line: 4 keyword, symbol: define line: 5 identifier, symbol: x line: 5 keyword, symbol: of line: 5 keyword, symbol: type line: 5 keyword, symbol: double line: 5 keyword, symbol: begin line: 6 keyword, symbol: display line: 7 string literal, symbol: "Welcome to the world of SCL" line 7 keyword, symbol: set line: 8 identifier, symbol: x line: 8 assignment, symbol: = line: 8 real constant, symbol: 45.95 line: 8 etc

import "scl.h" implementations function main return type integer is variables define x of type double // a variable declaration begin display "Welcome to the world of SCL" set x = 45.95 // assigns a value to variable x display "Value of x: , X exit // execution terminates OK endfun main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!