Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an existing algorithm for this notation translation/conversion?

A system has a notation that would require writing an expression like (A+B)*C as #MUL(#ADD(A,B),C). Is there already an algorithm to do this kind of notation conversion so users can enter in a more conventional way? In other words an algorithm to convert from infix -> my notation. First issue is I don't know an exact name for my notation... it's similar to reverse-polish but not quite. Every operator is encoded as a function taking arguments.

like image 872
Mr. Boy Avatar asked Dec 28 '22 13:12

Mr. Boy


2 Answers

Shunting-yard algorithm can be used to parse infix notation.

like image 131
el.pescado - нет войне Avatar answered Apr 29 '23 11:04

el.pescado - нет войне


Here's some Lisp that attempts the infix -> prefix transformation. It could serve as a useful starting point.

like image 39
Hank Gay Avatar answered Apr 29 '23 10:04

Hank Gay