More parser theory (Reply) [entries|reading|network|archive]
simont

[ userinfo | dreamwidth userinfo ]
[ archive | journal archive ]

[personal profile] simont Wed 2017-03-29 08:59
More parser theory
I had a conversation recently about low-priority prefix operators in infix expression grammars, which left me mildly uncertain about what they ought to mean. So here's a quick straw poll.

Suppose I have an expression grammar in which the multiplication operator * and the addition operator + have their usual relative priority (namely, * binds more tightly, i.e. is evaluated first). Then suppose I – perhaps unwisely – introduce a prefix operator, which I'll call PFX for want of a better name, which has intermediate priority between the two, so that

  • PFX a + b behaves like (PFX a) + b, i.e. the PFX is evaluated first
  • PFX a * b behaves like PFX (a * b), i.e. the PFX is evaluated second.
That's simple enough (if unusual). But things get weirder when PFX appears on the right of another operator. Specifically, what would you imagine happens to this expression:
a * PFX b + c
in which you can't process the operators in priority order (* then PFX then +) because the PFX necessarily has to happen before the *.


Poll #18119 BODMASWTFBBQ
Open to: Registered Users, detailed results viewable to: All, participants: 10


In what order should the parser process those operators?

View Answers

PFX then * then + to give (a * (PFX b)) + c
5 (50.0%)

+ then PFX then * to give a * (PFX (b + c))
0 (0.0%)

PFX then + then * to give a * ((PFX b) + c)
0 (0.0%)

None! Report a parse error and demand some disambiguating parentheses.
4 (40.0%)

Low-priority prefix operators misparsed my grandparents, you insensitive clod
1 (10.0%)

Link Read Comments
Reply:
From:
Anonymous( )Anonymous This account has disabled anonymous posting.
OpenID( )OpenID You can comment on this post while signed in with an account from many other sites, once you have confirmed your email address. Sign in using OpenID.
User
Account name:
Password:
If you don't have an account you can create one now.
Subject:
HTML doesn't work in the subject.

Message:

 
Notice: This account is set to log the IP addresses of everyone who comments.
Links will be displayed as unclickable URLs to help prevent spam.