Tuesday, December 11, 2018

Yet another parser

In computer science, the shunting-yard algorithm is a method for parsing mathematical expressions specified in infix notation. It can produce either a postfix notation string, also known as Reverse Polish notation (RPN), or an abstract syntax tree (AST). The algorithm was invented by Edsger Dijkstra and named the "shunting yard" algorithm because its operation resembles that of a railroad shunting yard. Dijkstra first described the Shunting Yard Algorithm in the Mathematisch Centrum report MR 34/61.

I got this one implemented also, gives me choices.  A good expression parser is going to add 50 lines of code to the default syntax engine.

Still a small price to pay for those who program  in Default, the new simple language. Default is for those who just while their time away with brackets, arithmetic (+-*^/" ) and dictionaries.

The hunter algorithm will construct the proper sequence on the args list:
Expr a b c + *;   //etc, the compound expressions unfolded for serial accumulation. Thus, once unfolded,thy are not reparsed when called again, as in a while loop.  The assembly code being the args list. Nothing in the syntax engines interferes with stand standard linux commands .

I was headed in this direction, and was smart enough to look around. The shunter is perfect. I just took the algorithm from Wiki and translated it into 'c'.

No comments: