尝试写一个解析器
我正在尝试使用 Shunting Yard (SY) 算法来解析语法。语法包括以下命令(尽管还有很多其他命令!)
a + b // a and b are numbers
setxy c d //c,d can be numbers
setxy c+d b+a //all numbers
本质上,setxy 是一个函数,但它不需要任何函数参数分隔符。由于缺少括号和函数参数分隔符,这使得通过 SY 进行操作变得非常困难(不可能?)。
知道 SY 是否可以用于解析无括号/无函数参数分隔符的函数,或者我应该转向不同的解析算法吗?如果是这样,您会推荐哪一个?
谢谢! DJ22
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, which one would you recommend?
Thanks!
djs22
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
定义了正确的语法后,您可以使 http://www.antlr.org/ 为您生成解析器。是否是合适的解决方案取决于你的作业“要求”。
至少你可以生成它并在里面寻找一些提示。
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?