diff -r 3c81352ec565 -r 6e990ae2c6a3 core_templates3/postfix.scala --- a/core_templates3/postfix.scala Sat Oct 08 00:30:51 2022 +0100 +++ b/core_templates3/postfix.scala Tue Nov 01 15:03:48 2022 +0000 @@ -19,28 +19,14 @@ // helper function for splitting strings into tokens def split(s: String) : Toks = s.split(" ").toList +// ADD YOUR CODE BELOW +//====================== -// (1) Implement below the shunting yard algorithm. The most -// convenient way to this in Scala is to implement a recursive -// function and to heavily use pattern matching. The function syard -// takes some input tokens as first argument. The second and third -// arguments represent the stack and the output of the shunting yard -// algorithm. -// -// In the marking, you can assume the function is called only with -// an empty stack and an empty output list. You can also assume the -// input os only properly formatted (infix) arithmetic expressions -// (all parentheses will be well-nested, the input only contains -// operators and numbers). -// You can implement any additional helper function you need. I found -// it helpful to implement two auxiliary functions for the pattern matching: -// - +// (1) def is_op(op: String) : Boolean = ??? def prec(op1: String, op2: String) : Boolean = ??? - def syard(toks: Toks, st: Toks = Nil, out: Toks = Nil) : Toks = ??? @@ -58,13 +44,7 @@ //syard(split("( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )")) // 3 4 5 + + -// (2) Implement a compute function that evaluates an input list -// in postfix notation. This function takes a list of tokens -// and a stack as argumenta. The function should produce the -// result as an integer using the stack. You can assume -// this function will be only called with proper postfix -// expressions. - +// (2) def compute(toks: Toks, st: List[Int] = Nil) : Int = ???