Fork me on GitHub
#braveandtrue
<
2016-05-06
>
marek-sed10:05:19

Hi guys, I am working through excercises in book and I can't figure how to solve excercise 2 in chapter 7. It is clear to me how to recursively build a nested list structure, but I am stuck on figuring out how to apply operator precedence to it. Can someone give some tips, how to do it? And btw in assignment this phrase is unclear to me "takes list like (1 + 3 * 4 - 5)", means function should take list of any size, or only lists with 4 numbers and 3 infixed operators? thank you very much for any help

nonrecursive12:05:10

@marek-sed for your second question, “takes list like …” means take a list that has any arbitrary arithmetic expression

nonrecursive12:05:00

coding operator precedence is definitely tricky. googling “operator precedence parser” might yield some useful results

nonrecursive12:05:47

though the results are very involved and technical

kjbrock22:05:10

@marek-sed You can give higher precedence to an operator by wrapping its operands up in their own list and using it as a component in the lower-precedence list. You can get a fairly short solution to the problem if you’re only dealing with two levels of precedence, as with +-/*.