Question: Assignment using the Rust programming language 1 .Traits and Deriving Traits Automatically. (a) Write an enum Token that contains variants for a simple expressions grammar:

Assignment using the Rust programming language

1 .Traits and Deriving Traits Automatically.

(a) Write an enum Token that contains variants for a simple expressions grammar: identifiers, + and * operator, assignment operator, parentheses, and end-of-input.The identifier should carry a String containing the identifier name.

(b) Derive the Debug trait automatically to be able to print your enum.

(c) Implement the Display trait yourself. Use the Rust documentation and the Internet to find a way to print a Token by mapping to the Debug print functionality.

(d) Implement the Partial Eq and Eq trait to compare two enum variants with-out comparing attached values. Note, the match!( , ) macro compares two enum values.

2 .Create a crate named interpreter.

(a) Create modules scanner,parser, and ds in the crate. Put the Token enum from the last exercise into the ds module.

(b) Write a function scan_string in module scanner that converts a tiny string into a vector of tokens and returns it. Assume for now that identifiers are just one ASCII character (e.g.,(a+b)*c+d*f).

(c) Call your functions can_string from the main function.

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 Programming Questions!