[DGD] Working with parse_string()

Kamil N kamiln at gmail.com
Mon Jul 20 23:12:39 CEST 2009


Thanks everyone for your hints, with your help I'm making some
progress with parser for this horrible grammar :) But I found one
strange thing happening with certain number of words involved:

separator = /[i,]/
word = /[a-zA-Z]+/
whitespace = / +/
number = /[0-9]+/

verb: 'give' OBJI_ACC LIV_DAT                     ? parse_give_command
LIV_DAT:    DAT SELECTOR ?      find_living
OBJI_ACC: ACC SELECTOR ?      find_inventory

ACC: ? accusative
DAT: ? dative

SELECTOR: OBJ                   ? parse_selector
OBJ: ADJ ADJ word
OBJ: ADJ word
OBJ: word

ADJ: word


So with this grammar and my find_* functions set up so they return
either object found or nil (if nothing can be found), I'm running into
strange behaviour, only using certain number of words:

give heavy steel axe nonexistant mob

HEAVY STEEL AXE exists, NONEXISTANT MOB doesnt

(I'm writing sentences in English, but they're actually Polish, doesnt
matter that much, and easier for you to read).

This is what my parsing logger registers when parsing is done on this phrase:

-----------parse_selector:  - ({ "heavy", "steel", "axe" })
searching in inventory - ({ ({ "accusative" }), "heavy", "steel", "axe" })
FOUND:  - "heavy steel axe"
-----------
found is logged in LPC function just before it does return ({
heavy_steel_axe_obj }), so if I understand parsing correctly, it means
that tokens "heavy", "steel" and "axe" are used now and should not
appear again

-----------parse_selector:  - ({ "nonexistant", "mob" })
searching live - ({ ({ "dative" }), "nonexistant", "mob" })
NOT FOUND:  - ({ "nonexistant", "mob" })

-----------parse_selector:  - ({ "heavy", "steel" })
searching in inventory - ({ ({ "accusative", 1 }), "heavy", "steel" })
NOT FOUND:  - ({ "heavy", "steel" })

You can see that first it does parse for OBJI and finds it, then it
searches for LIV and can't find it but suddenly it again searches for
"heavy" and "steel" as if it hasn't found it already. Is it normal
behaviour or I messed something really badly? Maybe my grammar rules
are incorrect or I return wrong values in LPC functions that cause
this.

Is it possible for single rule "verb: 'give' OBJI_ACC LIV_DAT" to
first look for OBJI_ACC, then for LIV_DAT and then again OBJI_ACC?

Also note that it only happens when I use exactly 5 words in my
phrase, that is 3 words for ITEM and 2 words for LIVING.

Regards,
KN



More information about the DGD mailing list