• Getting started with IF: on homemade parsers

    From 1zadast@gmail.com@21:1/5 to All on Mon May 6 19:59:54 2019
    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 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.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John W Kennedy@21:1/5 to 1zadast@gmail.com on Tue May 7 17:23:46 2019
    On 5/6/19 10:59 PM, 1zadast@gmail.com wrote:
    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 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.)

    It’s hard. Basically, you can’t just build a parser, the parser has to
    be tightly integrated with the world model. It needs to know that you shouldn’t name anything you can’t see, or at least that you haven’t
    seen, or interact with anything you can’t touch (except that you can
    look at it if it’s behind glass doors, or talk to it if it’s behind
    bars). I strongly recommend you master both Inform 6 and Inform 7, or
    something equivalent, just to give you an understanding of the nature of
    the problems involved.

    --
    John W. Kennedy
    "The blind rulers of Logres
    Nourished the land on a fallacy of rational virtue."
    -- Charles Williams. "Taliessin through Logres: Prelude"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Wiehe@21:1/5 to All on Mon May 20 12:51:15 2019
    Am Dienstag, 7. Mai 2019 04:59:57 UTC+2 schrieb 1za...@gmail.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 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.)

    In my humble opinion it makes sense to start with a simple verb noun parser. You can improve it later. Of course it depends on your coding mentality. I mean: Perhaps you are a programmer who has more fun when the challenge is greater.

    The premium solution would be to separate game data from the general game mechanisms. But that's more difficult. But this way you could publish your game once for all systems and let the player use it on every machine he/she wishes with a system-specific
    game-runner.
    Greetings
    Peter

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From news@zzo38computer.org@21:1/5 to 1zadast@gmail.com on Sun Jul 14 18:06:01 2019
    1zadast@gmail.com wrote:

    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 additional words.

    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
    the context.

    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.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Happy MAC XL@21:1/5 to All on Fri Aug 9 11:36:18 2019
    I know you've probably got your heart set on a DIY parser, but can I tempt you to look at ZIL and ZILF? You can edit that existing parser, or other library files, to your heart's content!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)