开发者

Trying to write a parser

I'm trying to parse a syntax using the Shunting Yard (SY) algorithm. The syntax includes the following commands (they're are many many others though!)

a + b // a and b are numbers
setxy c d //c,d can be numbers
setxy c+d b+a //all numbers

Essentially, setxy is a function but it doesn't expect any function argument separators. This makes it very difficult (impossible?) to do via SY due to the lack of parens and function argument separators.

Any idea if SY can be used to parse a parentheses-less/function argument separator-less function or should I move on to a different parsing algorithm? If so, whic开发者_运维百科h one would you recommend?

Thanks! djs22


Having defined correct grammar you can make http://www.antlr.org/ generate parser for you. Whether it is appropriate solution depends on your homework "requirements".

At least you can generate it and look inside for some hints.


I don't fully understand what you are trying to do, but perhaps you could use some regex? what are you trying to do write a simple command line program?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜