core_templates3/postfix2.scala
changeset 425 6e990ae2c6a3
parent 396 ea39bbc8d98d
equal deleted inserted replaced
424:3c81352ec565 425:6e990ae2c6a3
    33                 "^" -> 4)
    33                 "^" -> 4)
    34 
    34 
    35 // the operations in the basic version of the algorithm
    35 // the operations in the basic version of the algorithm
    36 val ops = List("+", "-", "*", "/", "^")
    36 val ops = List("+", "-", "*", "/", "^")
    37 
    37 
    38 // (3) Implement the extended version of the shunting yard algorithm.
    38 // ADD YOUR CODE BELOW
    39 // This version should properly account for the fact that the power 
    39 //======================
    40 // operation is right-associative. Apart from the extension to include
       
    41 // the power operation, you can make the same assumptions as in 
       
    42 // basic version.
       
    43 
    40 
       
    41 
       
    42 
       
    43 // (3) 
    44 def syard(toks: Toks, st: Toks = Nil, out: Toks = Nil) : Toks = ???
    44 def syard(toks: Toks, st: Toks = Nil, out: Toks = Nil) : Toks = ???
    45 
    45 
    46 
    46 
    47 // test cases
    47 // test cases
    48 // syard(split("3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3"))  // 3 4 8 * 5 1 - 2 3 ^ ^ / +
    48 // syard(split("3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3"))  // 3 4 8 * 5 1 - 2 3 ^ ^ / +
    49 
    49 
    50 
    50 
    51 // (4) Implement a compute function that produces an Int for an
    51 // (4)
    52 // input list of tokens in postfix notation.
       
    53 
       
    54 def compute(toks: Toks, st: List[Int] = Nil) : Int = ???
    52 def compute(toks: Toks, st: List[Int] = Nil) : Int = ???
    55 
    53 
    56 
    54 
    57 // test cases
    55 // test cases
    58 // compute(syard(split("3 + 4 * ( 2 - 1 )")))   // 7
    56 // compute(syard(split("3 + 4 * ( 2 - 1 )")))   // 7