I’ve been developing a parser for my own IF engine, and I wanted it to have a certain fluidity, something closer to how people actually speak, and less tied to rigid English word order. That led me to build what I call a greedy, destructive N‑gram parser.
The basic idea is simple enough. The parser breaks the sentence/command input into match groups: verbs, nouns, adverbs/modifiers, prepositions, compass directions, exit names, etc.
Once those groups exist, the surface structure of the sentence stops mattering. The parser greedily claims the longest meaningful spans, marks them consumed, and resolves the remaining pieces by position and proximity.
This leads to some interesting (and to me, desirable) behavior:
“from the table take the book” parses the same as “take the book from the table”
If the world contains “a wood box” and “a glass box” in the same location, then
“in the box put the box” parses the same as “put the box in the box”. Disambiguation menu choice prompts are displayed for the player to pick the box for both noun and object.
If a rotor object has positions low, medium, high, off, then “turn the rotor to low” works the same as “to low turn the rotor”
I built this without any preconceived ideas, just memories of Scott Adams and Infocom games. One very strict the other not so much. I’m just remembering this from my teenager years when I read many paperbacks and played those text games. I formed a belief that you should be able to type things in flexible, natural ways and still be understood.
Recently someone testing one of my games remarked that the parser “accepts things out of order,” and it made me wonder: Is this kind of flexible, order‑agnostic parsing considered OK in parser IF? Is it helpful? Confusing? Too permissive? Do players expect strict English ordering, or do they appreciate looser, more natural phrasing?
Just curious about how you would make your parser work or made one work if you have tackled it. It is a great exercise in programming. Text parsing is a cottage industry for all kinds of computer programs including IF.




