Community

SCI Programming => SCI Syntax Help => Topic started by: Doan Sephim on November 11, 2022, 11:48:02 AM

Title: Parser confusion
Post by: Doan Sephim 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?
Title: Re: Parser confusion
Post by: troflip 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'
Title: Re: Parser confusion
Post by: Doan Sephim 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
Title: Re: Parser confusion
Post by: troflip 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'
Title: Re: Parser confusion
Post by: troflip 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'
Title: Re: Parser confusion
Post by: troflip 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
    )
)
Title: Re: Parser confusion
Post by: Doan Sephim on November 11, 2022, 08:53:51 PM
Thank you so much for the ideas and variations. I now have something that works! Hooray!