Question: / / Project 0 : Structs and Traits in Rust, Parsing / ASTs , S - expressions, Polish notation / / Write a parser that

// Project 0: Structs and Traits in Rust, Parsing/ASTs, S-expressions, Polish notation
// Write a parser that parses an S-expression language for Polish notation and converts it into an AST using the structs defined in the lib.rs file
// The language should support 4 artihmetic operations: +,-,*,^ where arguments can be integers or other polish notation expressions
// Parentheses are optional for binary operators, but are mandator in other k-ary instances
// These are some examples of equivalent inputs:
//+125=>(+125)
//-+321=>(-(+32)1)
//(-321)=>(-(-32)1) Note that operations +,-, and * are all left associative
//(^321)=>(^3(^21)) Note that the operation ^ is right associative
//(-2)=>(-02)
//(+3)=>3
// Note that + and - support unary arguments, whereas * and ^ do not
// Parse errors: return an ErrorExp struct
// e.g.,
//(*4) return ErrorExp, * and ^ cannot be used as unary operators
//(^5) ditto
//() return ErrorExp, parens cannot go alone
//(+) return ErrorExp, operators must have 1 or more operands in all cases
// x return ErrorExp, only numeric 0-9 characters, whitespace, (,),+,-,*,^, are valid input characters

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