Re: get unused integer
- From: Christian Theil Have <christiantheilhave@xxxxxxxxx>
- Date: Sat, 17 May 2008 16:50:20 -0700 (PDT)
Hi Simon
I am not 100% certain if I understand your problem correctly.
Apologies if this is a solution to the wrong problem...
You can add a variable binding store as a parameter to your
grammar rules. It could look something like this:
s(Label, T1, T3, LabelsIn, LabelsOut) :-
(member([s_uniq_rule_name, Label], LabelsIn) ->
Labels1 = LabelsIn
;
next_label(Label, LabelsIn),
Labels1 = [ [ s_uniq_rule_name, Label] | LabelsIn ]
),
np(_NPLabel, T1, T2, Labels1, Labels2),
vp(_VPLabel, T2, T3, Labels2, LabelsOut).
next_label(0, []).
next_label(N, [[_,PrevLabel]|_]) :-
N is PrevLabel + 1.
It is untested, so not it might not work, but the idea is that like
you have
in and out difference list, you also have in and out "variable
bindings" where
the labels are stored. The above code assumes that you add similar
code to all
your grammar rules.
I hope this helps.
Regards,
Christian
On May 16, 4:58 pm, Simon Strobl <Simon.Str...@xxxxxxxxx> wrote:
Hello,
in a parsing procedure, I need to assign labels to certain tokens
(under certain circumstances, i.e. NOT each time a rule is applied).
No two tokens must get the same label. A new label should be assigned
like in
(1) NewLabel is OldLabel + 1
I think I cannot simply use a label argument in grammar rules, as
shown below:
(2) s(Bla, Bli, Label, T1, T3) :-
NPLabel is Label + 1,
VPLabel is Label + 2,
np(Bla, Bli, NPLabel, T1, T2),
vp(Bla, Bli, VPLabel, T2, T3).
Apart from not satisfying condition (1), this strategy and similar
strategies will not make sure that no label is used twice.
I do not want to use global variables nor any technique that is
probable to be in the way when the program uses multiple threads.
How can this problem be solved?
Simon
.
- Follow-Ups:
- Re: get unused integer
- From: Simon Strobl
- Re: get unused integer
- References:
- get unused integer
- From: Simon Strobl
- get unused integer
- Prev by Date: Re: Why Prolog code from Wikipedia doesn't run?
- Next by Date: Higher order programming: apply/3 implemented in swi
- Previous by thread: get unused integer
- Next by thread: Re: get unused integer
- Index(es):