Author | Message |
---|---|
rabbott
Posts: 1649
|
Posted 17:43 Apr 17, 2019 |
I apologize that the discussion of the Haskell operator precedence code was not very well organized. Here is a brief discussion. I hope it helps. I have Dept meetings in the morning and two senior design groups Friday--at 2:00 and 3:00. If anyone is interested, I'm willing to stay after the senior design groups, say 4:00, to discuss the code. Please let me know in advance. Last edited by rabbott at
21:32 Apr 17, 2019.
|
jungsoolim
Posts: 38
|
Posted 20:43 Apr 17, 2019 |
Please count me in. Thanks! Soo |
rabbott
Posts: 1649
|
Posted 11:22 Apr 20, 2019 |
If any of you are still struggling with the Python version of the Operator Precedence code, here's mine if you want to look at it. For the most part, it's a more or less direct translation of the Haskell. It's somewhat simpler, but it also has some additional features. Unless you have (or expect to have by Monday) your own working version, please look at mine and do your best to understand it. (It's straightforward Python; nothing tricky.) Post whatever questions you have here. (If you are doing the Prolog option, stick with that -- and post whatever questions you have about it.) Last edited by rabbott at
11:34 Apr 20, 2019.
|
jungsoolim
Posts: 38
|
Posted 00:13 Apr 21, 2019 |
I added few more operators: gt, lt, or, and, eq. ( I used |, &, = for or, and, eq) Now, we can evaluate the followings: print(f'{showResult(*evalArith("10+4.3>6", trace=True))} (True)') print(f'{showResult(*evalArith("10+4.3<6", trace=True))} (False)') print(f'{showResult(*evalArith("10+4.3<6&1>2", trace=True))} (False)') print(f'{showResult(*evalArith("10+4.3<6|1>2", trace=True))} (False)') print(f'{showResult(*evalArith("10+4.3<6=1>2", trace=True))} (True)') > evalArith("10+4.3>6") << (, 10, +, 4.3, > >> 6,) "10+4.3>6" -> ((10+4.3)>6) -> 1 (True)
<< (, 10, +, 4.3, < >> 6,) "10+4.3<6" -> ((10+4.3)<6) -> 0 (False)
<< (, 10, +, 4.3, < >> 6,and,1,>,2,) "10+4.3<6&1>2" -> (((10+4.3)<6)and(1>2)) -> 0 (False)
<< (, 10, +, 4.3, < >> 6,or,1,>,2,) "10+4.3<6|1>2" -> (((10+4.3)<6)or(1>2)) -> 0 (False)
<< (, 10, +, 4.3, < >> 6,eq,1,>,2,) "10+4.3<6=1>2" -> (((10+4.3)<6)eq(1>2)) -> 1 (True) Process finished with exit code 0
Last edited by rabbott at
03:57 Apr 21, 2019.
|
jungsoolim
Posts: 38
|
Posted 00:19 Apr 22, 2019 |
Now we can handle !=, <=, >= as well. > evalArith("10+4.3<=6==1>=2") << (, 10, +, 4.3, <= >> 6,eq,1,>=,2,) "10+4.3<=6==1>=2" -> (((10+4.3)<=6)eq(1>=2)) -> 1 (True)
<< (, 10, +, 4.3, <= >> 6,ne,1,>=,2,) "10+4.3<=6!=1>=2" -> (((10+4.3)<=6)ne(1>=2)) -> 0 (False) Process finished with exit code 0
|