简体   繁体   English

没有替代项的算术表达式语法?

[英]Grammar for arithmetic expressions without alternatives?

How to write Unambiguous Grammar for arithmetic expressions eg a+(b+c)*d Eg 如何为算术表达式(例如a +(b + c)* d Eg)编写明确语法

E -> E + T | T
T -> T * F | F
F -> ( E ) | i

WITHOUT alternatives - in my case without |T and |F and |i 没有替代方案-在我的情况下,没有| T和| F和| i

This should be possible by adding more sentences to the grammar but I'm having hard time to figure out how... NOTE: this is for University... so may be not a good real world Grammar :) 通过在语法中添加更多句子,应该可以实现这一点,但是我很难弄清楚该怎么做...注意:这是给大学使用的...所以可能不是一个好的现实世界语法:)

What you're asking for is impossible. 您要的是不可能的。 If you do not have alternative productions in your grammar, then it is not possible for there to be any decisions about which productions to use. 如果您的语法中没有替代产品,那么就不可能决定要使用哪种产品。 As a result, your grammar will either generate no strings, or will generate a single string. 结果,您的语法将不生成字符串,也不会生成单个字符串。 Grammars with these properties are called LL(0) grammars and are not at all practical. 具有这些属性的语法称为LL(0)语法 ,根本不实用。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM