Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON !!!! HW4 Lexer GUI using python Now it is time to merge our GUI design with our lexer logic together and create the

IN PYTHON !!!!

HW4 Lexer GUI using python

Now it is time to merge our GUI design with our lexer logic together and create the Lexer GUI.

You will need the complete answers from the below works to form the answer for this HW.

--- HW2: get input from input window and print output out line-by-line to output window.

--- PythonLab3: with 1 line of source code input, cut the line into tokens, and output a string with list.

Example code that your Lexer should be able to process:

int A1=5

int BBB2 =1034

int cresult = A1 +BBB2 + BBB2

if (cresult >10):

print(TinyPie )

Please pay attention to this program, as you can see, user can choose to type any number of spaces between an identifier, literal and the = sign or + sign or > sign, etc.

image text in transcribed

When user press the next line the first time, the first line gets processed and give out the list on the right side. In you last GUI homework, you printed out this line directly. This time, you need call the token finding function that you wrote in PythonLab3 to find out the list.

Again, your lexer can have different appearance from this example. We check for functionalities when grading. Grading details on next page.

IMPORTANT: Start coding early and ask for help early to get your Lexer work. It is a lot harder to debug code with GUI in it. You can use VS code or python visualizer to debug your pythonLab3, and copy/past code over to your GUI when you know cutting 1 line into token list is working.

Submit only 1 python 3 .py file that we can run and check if your lexer works. This is solo work.

image text in transcribed

Please note this is the code that needs editing

----------------------------------------------------------

import tkinter as tk

current_line_index = 0

def next_line():

global current_line_index

text = ip_text_box.get('1.0', 'end-1c').split(' ')

if current_line_index >= len(text) - 1:

return

ip_line_tb.delete(0, tk.END)

ip_line_tb.insert(tk.END, current_line_index + 1)

op_text_box.insert(tk.END, text[current_line_index] + ' ')

current_line_index += 1

def quit(): app.quit()

# Main window

app = tk.Tk()

#app.configure(background = 'red')

app.title('Lexical Analyzer for TinyPie')

app.geometry("1500x700+20+50")

app.resizable(False, False)

ip_container = tk.Frame(app, width=1, height=1,background = 'dark orange')

ip_container.grid_propagate(False)

ip_container.pack(side="left", fill="both", expand=True)

ip_label = tk.Label(app, text='Source Code Input:')

ip_label.place(x=50, y=50)

ip_text_box = tk.Text(ip_container)

ip_text_box.place(x=50, y=80)

ip_line_label = tk.Label(app, text='Current Processing Line:')

ip_line_label.place(x=400, y=500)

ip_line_tb = tk.Entry(app)

ip_line_tb.size()

ip_line_tb.place(x=550, y=500)

ip_next_button = tk.Button(app, text='Next', command=next_line)

ip_next_button.place(x=550, y=550)

op_container = tk.Frame(app, width=10, height=10, background = 'RoyalBlue1')

op_container.grid_propagate(False)

op_container.pack(side="right", fill="both", expand=True)

op_label = tk.Label(app, text='Lexical Analysed Result:')

op_label.place(x=790, y=50)

op_text_box = tk.Text(op_container)

op_text_box.place(x=50,y=80)

op_next_button = tk.Button(app, text='Quit', command=quit)

op_next_button.place(x=1350, y=550)

app.mainloop()

#OUTPUT

Show transcribed image text

Required GUI functions for this HW Lexer for TinyPie Source Code Tokens nt A1-5 int BBB2-1034 int cresult = A1 +BBB2 +| | Kidentifier, A1> BBB2 if (cresult 10): print("TinyPie " ) Current line number: 1 Exit Next Line When user press "Next Line" button, the second line gets processed and the GUI looks like the following graph and gives out more pairs Lexer for TinyPie Source Code Tokens nt A1-5 nt BBB21034 int cresult = A1 +BBB2 +| | BBB2 kidentifier, BBB2> And so on... if (cresult 10): print("TinyPie " ) Current line number: 1 Exit Next Line Required GUI functions for this HW Lexer for TinyPie Source Code Tokens nt A1-5 int BBB2-1034 int cresult = A1 +BBB2 +| | Kidentifier, A1> BBB2 if (cresult 10): print("TinyPie " ) Current line number: 1 Exit Next Line When user press "Next Line" button, the second line gets processed and the GUI looks like the following graph and gives out more pairs Lexer for TinyPie Source Code Tokens nt A1-5 nt BBB21034 int cresult = A1 +BBB2 +| | BBB2 kidentifier, BBB2> And so on... if (cresult 10): print("TinyPie " ) Current line number: 1 Exit Next Line

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

More Books

Students also viewed these Databases questions