简体   繁体   中英

Grammar for arithmetic expressions without alternatives?

How to write Unambiguous Grammar for arithmetic expressions 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

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.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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