In article <0C6PJ.1096642$X81f....@fx14.ams4>,
Johann 'Myrkraverk' Oskarsson <joh...@myrkraverk.invalid> wrote:
>Then I was thinking, if all of this has been written about compilers,
>hasn't /something/ been written about IF parsers? Maybe it hasn't
>and it's all in the compiler literature? One thing is different, IME,
>in IF, and that's the game itself can add keywords and nouns. Though
>maybe that's not too different from adding types in languages like C++.
>The difference being that the compiler grammar is /fixed/ while the IF
>grammar is more flexible with verbs being added and nouns changing as
>the game progresses.
Maybe? But plenty of languages let you extend the syntax. FORTH is
my favorite example, but anything LISP-like (and FORTH's stack is just
a LISP expression stood up on end) encourages you to do exactly that.
If you're not scared of wading through source...even though Inform 7
isn't yet open-source, you can wade through its implementation of the
parser and standard library, since that's written in Inform 6 and 7
and bundled with the application.
I'm working with the Mac app, so inside the Inform.app directory,
you'd want to go to Contents/Resources. Linux and Windows will have
analogous structures. Once inside there...Library/6.11 contains a
bunch of Inform 6, including parserm.h, which contains the input
tokenizer and parser. The I6 standard world model is in that
directory as well. Going back up to Contents/Resources, and then down
to Internal/Extensions/Graham\ Nelson will bring you to Standard\
Rules.i7x, which is both the definition of the I7 standard model and
the glue that binds it to I6.
It's an enlightening read, if you want to see how the sausage is made.
What you will find is what Greg Ewing said: the tokenizer is pretty
straightforward, and the parser...recognizes a lot less than you think
it might. The language extensibility is the cool bit, and Inform 7 is
a really neat experiment in making extending the language -- which is
to say, writing Interactive Fiction -- an awful lot like playing a
game written in the language.
Adam