Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fall 2017 Python Pattern Search- Lexical Analyzer Assigned: Thursday, November 16, 2017 Due, in class: Tuesday, November 28, 2017, submitted on Blackboard before class (9:30AM)

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Fall 2017 Python Pattern Search- Lexical Analyzer Assigned: Thursday, November 16, 2017 Due, in class: Tuesday, November 28, 2017, submitted on Blackboard before class (9:30AM) In Chapter 4, we discussed the design of a lexical analyzer to identify tokens and lexems in a language. The code on pp. 166-170 provides an implementation in C Given what you have learned about the power of Python, please design a lexical analyzer to review Java programs and determine if they are correctly formed. If not, an appropriate error messages should be generated. You may have to use the mutability of lists, a dictionary, pattern matching and sequences You'll have to: 1. 2. Write the code in Python to read in a program of Java code and determine correctness. Resulting output should include a listing of reserved words, variables, the number of errors and the type of errors public class Welcome public class Welcome f public static void main(Stringll args) [ public static void mine(Strap[] args) System.out.println("Welcome to Java!"); System.out.println("Welcome to Java!" Test Case #l output might include: All checks out ok! Errors =0 Reserved Word list public, class, static, void, main, String, args Method Calls: System.out.println Curly brace pair count: 2 pairs, all matched. Error in program: Curly braces do not match One variable string: "Welcome to Java!" Test Case #2 output might include Oh no! Errors = 6 (Note: your count may differ) Error on line 2: "mine" not found Error on line 2: Strap" not found Error on line 3: missing' Error on line 3: miss ing Error in program: Does not terminate For full credit, at least 4 test cases should be run - two as above and two more complex, including at least one logic structure and one iteration loop. The variety and nature of errors detected (greater variety is good) will be assessed. Fall 2017 Python Pattern Search- Lexical Analyzer Assigned: Thursday, November 16, 2017 Due, in class: Tuesday, November 28, 2017, submitted on Blackboard before class (9:30AM) In Chapter 4, we discussed the design of a lexical analyzer to identify tokens and lexems in a language. The code on pp. 166-170 provides an implementation in C Given what you have learned about the power of Python, please design a lexical analyzer to review Java programs and determine if they are correctly formed. If not, an appropriate error messages should be generated. You may have to use the mutability of lists, a dictionary, pattern matching and sequences You'll have to: 1. 2. Write the code in Python to read in a program of Java code and determine correctness. Resulting output should include a listing of reserved words, variables, the number of errors and the type of errors public class Welcome public class Welcome f public static void main(Stringll args) [ public static void mine(Strap[] args) System.out.println("Welcome to Java!"); System.out.println("Welcome to Java!" Test Case #l output might include: All checks out ok! Errors =0 Reserved Word list public, class, static, void, main, String, args Method Calls: System.out.println Curly brace pair count: 2 pairs, all matched. Error in program: Curly braces do not match One variable string: "Welcome to Java!" Test Case #2 output might include Oh no! Errors = 6 (Note: your count may differ) Error on line 2: "mine" not found Error on line 2: Strap" not found Error on line 3: missing' Error on line 3: miss ing Error in program: Does not terminate For full credit, at least 4 test cases should be run - two as above and two more complex, including at least one logic structure and one iteration loop. The variety and nature of errors detected (greater variety is good) will be assessed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

ISBN: 321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

How to defuse hostile, potentially violent employees and customers

Answered: 1 week ago