Author Topic: Parser confusion  (Read 24682 times)

0 Members and 1 Guest are viewing this topic.

Offline Doan Sephim

Parser confusion
« on: November 11, 2022, 11:48:02 AM »
I'm trying to write a parser command that will read if the player types either
ask about NOUN
or
ask man about NOUN
This easily works for ask about:
Code: [Select]
(if (Said '(ask<about)>')
(if (Said '/NOUN')
(Print 2 25) ; default statement
)
But I'm having trouble with ask man about...
Something like this kind of works:
Code: [Select]
(if (Said '(ask<about)/man/NOUN')It does allow me to ask NOUN about man which is a little weird, but not too bothersome.
But when I try to this:
Code: [Select]
(if (Said '(ask<about)/man>
(if (Said 'NOUN')
It doesn't work.
I've tried something like:
Code: [Select]
(if (Said '(ask<about)[/man]>')
(if (Said '/NOUN')
(Print 2 25) ; default statement
)
But the parser doesn't like this at all.

Does anyone have any thoughts?
« Last Edit: November 11, 2022, 11:54:23 AM by Doan Sephim »


Artificial Intelligence Competition

Offline troflip

Re: Parser confusion
« Reply #1 on: November 11, 2022, 04:31:21 PM »
There are up to 3 parts that need to be parsed, separated by '/'.

The split up equivalent of:
Code: [Select]
'(ask<about)/man/NOUN'
Would be:
Code: [Select]
'(ask<about)/man>'followed by
Code: [Select]
'//NOUN'
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Doan Sephim

Re: Parser confusion
« Reply #2 on: November 11, 2022, 04:35:18 PM »
There are up to 3 parts that need to be parsed, separated by '/'.

The split up equivalent of:
Code: [Select]
'(ask<about)/man/NOUN'
Would be:
Code: [Select]
'(ask<about)/man>'followed by
Code: [Select]
'//NOUN'
Can you explain the need for // in the final line. I'm not sure I understand

Offline troflip

Re: Parser confusion
« Reply #3 on: November 11, 2022, 05:05:40 PM »
In the case of this code of yours:

Code: [Select]
(if (Said '(ask<about)[/man]>')
(if (Said '/NOUN')
(Print 2 25) ; default statement
)

you are matching 'man' and 'NOUN' to the same part of speech. If the player types "ask man about NOUN", NOUN is the indirect object of the sentence, whereas man would be the object.

Typically for a sentence like that, it goes:
'VERB/OBJECT/INDIRECTOBJECT'

So if you're targeting just the indirect object, you need to put two slashes:
'//INDIRECTOBJECT'
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline troflip

Re: Parser confusion
« Reply #4 on: November 11, 2022, 05:12:35 PM »
Actually, the <about thing is throwing me off. It needs to go with the indirect object, not the verb.

I typically just leave it out, using

Code: [Select]
'ask/man/NOUN'
(works for "ask man about noun")
or

Code: [Select]
'ask[/man]/NOUN'
(works for "ask man about noun" or "ask about noun")

Then to split it up, you can add the > to not fully claim the Said:

Code: [Select]
'ask[/man]>'
Followed by whatever nouns you want, leaving the first and second parts of speech blank:

Code: [Select]
'//NOUN'
« Last Edit: November 11, 2022, 05:16:36 PM by troflip »
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline troflip

Re: Parser confusion
« Reply #5 on: November 11, 2022, 06:59:49 PM »
Something I just realized might not be clear. The '>' character just means "don't claim the Said event even if this is a match". Subsequent calls to Said still attempt to match the entire phrase that was entered, not just the parts that weren't specified in whatever thing ended with '>'. That's why you need the two slashes.

I haven't tried it, but I suspect the following would work just as well:

Code: [Select]
(if (Said '//NOUN>')
    (if (Said 'ask[/man]')
        ; ask man about NOUN
    )
)
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Doan Sephim

Re: Parser confusion
« Reply #6 on: November 11, 2022, 08:53:51 PM »
Thank you so much for the ideas and variations. I now have something that works! Hooray!


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.057 seconds with 23 queries.