Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Any help will be great. Thank you. Hi! I do not understand your question, Does the user want it in C. The directions say to
Any help will be great. Thank you.
Hi! I do not understand your question, "Does the user want it in C."
PROBLEM STATEMENT: Write a Python program to (1) perform lexical analysis on a text nie enter each unique identifier in a symbol table as it is recognized. Extract all lexemes from an input file (described below) and output them to the screen and to a file, as described below. Enter the identifiers into a symbol table represented as a Python dictionary where the key is the identifier and the value is a list of line numbers where this identifier has been referenced. LEXICAL SYNTAX The token types you are responsible for identifying are Identifiers, defined as follows: letter{letterdigit) . Integers, defined as follows: digit{digit)* Floats, defined as integer.integer Characters: any ASCII character, enclosed in single quotes: e.g., Z Keywords: bool char else false float if int main true while (Recognize first according to the identifier rule and then as a keyword) Operators: -, !-, instead of > and Simplification: You can assume that all lexemes are terminated by a blank There are two errors the lexer should able to detect. First: nonsense sequences such as "600" are errors. Second: all floats must have a digit before and after the decimal point. 34." is not a token, it is an error. INPUT: Your program should be able to read data from an input file and divide it into lexemes. You can test the program with your own input, but it will be graded based on my input file. OUTPUT: The test program should print a message describing the purpose of the program followed by a list of all lexemes identified and their token class.. Any errors detected should be output as well. Fonowing that, print the symbol table, properly identified. See next page for sample output. The output format shown is merely a suggestion, but it's important to print neatly and identify items printed Example 1: sample input file int main() chare; int item; float x2b; c 'h'; item =c+3; X2b = 5.67; Examplel Your output file should look something like this, screen output should contain the same information Input file: See above. Output: Line Number Token Type Lexeme keyword int keyword main punctuation punctuation punctuation keyword char identifier punctuation keyword int identifier item punctuation keyword float identifier x2b punctuation identifier identifier punctuation SYMBOL TABLE Symbol (first line is line 1) Line Numbers (3, 6, ..) item x2b (4) (5) PROBLEM STATEMENT: Write a Python program to (1) perform lexical analysis on a text nie enter each unique identifier in a symbol table as it is recognized. Extract all lexemes from an input file (described below) and output them to the screen and to a file, as described below. Enter the identifiers into a symbol table represented as a Python dictionary where the key is the identifier and the value is a list of line numbers where this identifier has been referenced. LEXICAL SYNTAX The token types you are responsible for identifying are Identifiers, defined as follows: letter{letterdigit) . Integers, defined as follows: digit{digit)* Floats, defined as integer.integer Characters: any ASCII character, enclosed in single quotes: e.g., Z Keywords: bool char else false float if int main true while (Recognize first according to the identifier rule and then as a keyword) Operators: -, !-, instead of > and Simplification: You can assume that all lexemes are terminated by a blank There are two errors the lexer should able to detect. First: nonsense sequences such as "600" are errors. Second: all floats must have a digit before and after the decimal point. 34." is not a token, it is an error. INPUT: Your program should be able to read data from an input file and divide it into lexemes. You can test the program with your own input, but it will be graded based on my input file. OUTPUT: The test program should print a message describing the purpose of the program followed by a list of all lexemes identified and their token class.. Any errors detected should be output as well. Fonowing that, print the symbol table, properly identified. See next page for sample output. The output format shown is merely a suggestion, but it's important to print neatly and identify items printed Example 1: sample input file int main() chare; int item; float x2b; c 'h'; item =c+3; X2b = 5.67; Examplel Your output file should look something like this, screen output should contain the same information Input file: See above. Output: Line Number Token Type Lexeme keyword int keyword main punctuation punctuation punctuation keyword char identifier punctuation keyword int identifier item punctuation keyword float identifier x2b punctuation identifier identifier punctuation SYMBOL TABLE Symbol (first line is line 1) Line Numbers (3, 6, ..) item x2b (4) The directions say to program in Python. It is my understanding that C is not Python. Any help will be great. Thanks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started