Note that there are some explanatory texts on larger screens.

plurals
  1. POParser generator, predicate not returing true or false
    primarykey
    data
    text
    <p>I have a some problem with my PROLOG assignment.</p> <p>Namely, I have to write predicate accept(+Automaton, +Word) that return true if Word belong to language (Automaton is represented by Goto table, Action table and grammar, but it is not so important), false otherwise (it is required in my assignment to return true or false). I have written</p> <pre><code>accept(Automaton, Word) :- parse(Automaton, Word, RightmostDeriv), nl, print_list(RightmostDeriv), nl. </code></pre> <p>where</p> <p>Predicate <code>parse(+Automaton, +Word, -RightmostDeriv)</code> calculate righmost derivation. If Word cannot be parsed then <code>RighmostDeriv == ['mistake']</code></p> <p>As you see I can print rigthmost derivation, but I do not know how to return false or true.</p> <p>I have found this <a href="https://csc.cdf.toronto.edu/mybb/showthread.php?tid=2100" rel="nofollow">https://csc.cdf.toronto.edu/mybb/showthread.php?tid=2100</a> and I see that here can be a problem. </p> <p>But maybe is here any solution (e.g with member predicate, something like member('mistake', RightmostDeriv) ) to return true or false?</p> <p>Edit: having</p> <pre><code>accept(Automaton, Word) :- parse(Automaton, Word, RightmostDeriv), nl, print(RightmostDeriv), nl. </code></pre> <p>I received (Test 2 - example from wikipedia <a href="http://en.wikipedia.org/wiki/LR_parser#Additional_Example_1.2B1" rel="nofollow">http://en.wikipedia.org/wiki/LR_parser#Additional_Example_1.2B1</a>)</p> <pre><code>[4] ?- make. =============== Test 1 =================== [mistake] =============== Test 2 =================== [5,3,5,2] true . [4] ?- </code></pre> <p>and having:</p> <pre><code>accept(Automaton, Word) :- parse(Automaton, Word, RightmostDeriv), RightmostDeriv \= ['mistake']. </code></pre> <p>I received (infinite loop)</p> <pre><code>?- make. =============== Test 1 =================== ^CAction (h for help) ? break % Break level 1 [1] ?- </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload