Post by email@example.com
I recently started writing some OOP classes to represent rooms, items, etc.
for IF. I want to try my hand at writing IF, but I have a question.
I would be writing my own parser, at least if I want to use the classes I've
e written. How difficult is it to create a usable, even if simple, parser?
It could be as basic as noun-verb, though I'd prefer something a little bit
more sophisticated. I could learn Inform, naturally, but I so far I've
enjoyed trying to program this thing myself. Should I write a few
simplistic/"naive" parsers first, for practice? What should they do?
I don't have any story for a game yet, but inspiration may come as I program
(especially since I have to have some sort of world in place to test parser/
world model components as I add them.)
What programming language are you using? If you are interested, you may
look at what I implemented for xyzabcde2 (Game of XYZABCDE -- Part II). It
works basically like this:
1. Convert input to lowercase, discard most punctuation, and split the
input into words.
2. Use a binary search in the vocabulary table to convert each word into
the corresponding number. If not found, display an error message. (The
index of the word in the table is used, and it is defined as a compile
time constant, which is then referenced in the rest of the program.)
3. Look up the first word in the verbs table, and call the function listed
there. If not found, display an error message.
4. The verb implementation function will call other functions for parsing
5. The noun parse function looks for available objects (currently, far
objects are not implemented), and reads the noun phrases for those objects
to match them with user input.
6. With each noun phrase of an object, it has a priority value associated
with it; there is also a function to determine the extra priority due to
7. The object with the best priority is used. If there is a tie, then
display an error message, unless the objects have the "indistinguish" flag
set and have the same prototype, in which case, just pick one arbitrarily.
Also, even if you do not use Inform, I would recommend to use a VM such as
Glulx or Z-machine or TAVERN32, if possible. (I do not know of any program
to compile a C code to Glulx, and there is perhaps the difficulty that you
cannot take the address of a local variable in Glulx.)