HW 4 Problem 1 Solved

$24.99 $18.99

Question: 1. Define an enumerated type called TokenType witht the following elements: ◦ CONSTANT ◦ OPERATOR ◦ VARIABLE ◦ SPECIAL 2. Define struct/class called Token with the following attributes ◦ text ◦ token_type 3. Given an input file, create a list of Token objects and print those objects in a custom manner Provided test cases:…

5/5 – (1 vote)

You’ll get a: zip file solution

 

Description

5/5 – (1 vote)

Question:

1. Define an enumerated type called TokenType witht the following elements:

◦ CONSTANT

◦ OPERATOR

◦ VARIABLE

◦ SPECIAL

2. Define struct/class called Token with the following attributes

◦ text

◦ token_type

3. Given an input file, create a list of Token objects and print those objects in a custom manner
Provided test cases:

1. Input: “a := 0 + 1;”

2. Input: “b:=1;”

 

 

 

 

 

 


Note: First language is Python

Algorithm/Pseudo code:

 

 

 

 

 

 

 

 

 

 

 

 

Actual Code:

Syntax Error:

• When I defined a custom print function for a Token object in lines 22 and 23, I added a print statement instead of actually returning the string.

Working Code

Debugging

1. When assigning self.token_type in the constructor of the object, I check if the input is present within the name of the enumerated value instead of list/string associated with it. To fix:

 

 

 

 

 

 

 

2. Did not account for the fact that we can have operators that contain two characters when parsing the input string. To fix:

 

 

 

 

 

 

3. Made a mistake when doing the second debug step. If there was a “=” after any token, it would be counted as an operator. For example, “0 =” would become “0=”. To fix:

 


Add Documentation

 

Extra Test Cases Used for Debugging:

1. Input: “d:= 1*1 / 1 * 0 == 0;”

2. Input: “d := 0*0 <= 0/ 1 * 1;”

 

 

 

 

 

 

 

 

 

 

 

 

3. Input: “c := 1*0 != 0/ 1;”

4. Input: “c := 0 % 1 >= 0/ 1;”

 

 

 

 

 

 

 

 

 

 

Note: Second language is Rust

Actual Code:

Syntax Error:

1. In lines 32, 35, and 38, there is an ownership problem with the way that I use u_input. I need to borrow it using its reference.

Working Code

 

 

 

 

 

 

 

 

 

 

 

 

 

Debugging

1. In line 52, self.input is printed twice, instead of self.id being printed once and self.input being printed once. To fix:

 

 

2. When I encountered a token that was two characters long, I did not concatenate the second character to the first. To fix:

 


Add Documentation

 

HW 4 Problem 1 Solved
$24.99 $18.99