From: Charmed Snark on
Robert A Duff expounded in news:wcceijk0vze.fsf(a)shell01.TheWorld.com:

> Warren <ve3wwg(a)gmail.com> writes:
>
>> except that the discriminant also be described somehow
>> as 3-bits.
>
> I'm not sure what you mean. If you're saying "I don't know
> how to specify the layout for discriminants", then the answer
> is "same as other components" -- you just put the usual
> "Discrim at ... range 0..2" or whatever.

Yep, that was what I was after. So it _is_ possible after
all ;-) I'll keep that in my back pocket for now, because
I got things working satisfactory now. My cases where I
had auxiliary info were not that numerous, so I just created
a couple of factory functions employing case statements. Wordy,
but it works.

The "Georg" solution was good for that "catch all case" where
there was no aux info involved.

>>> You said you wanted efficiency. Well, this:
>>>
>>> T : Token_Type := Token_Type'Val(Character'Pos(Ch));
>>>
>>> is unlikely to be efficient. The case statement will be better
>>> in that regard.
>>
>> If true, I'd like to know why. I can't see that in the compiled
>> code being much other than a move short. If I get time tonight,
>> I'll investigate it.
>
> Ah, I see I misread your code. I thought you were using
> 'Image and 'Value. Sorry.
>
> So you're right -- the above 'Pos and 'Val should be efficient.

Yep, it is (from objdump):

6: c6 45 fd 01 movb $0x1,-0x3(%ebp)
a: 66 c7 45 fe 01 00 movw $0x1,-0x2(%ebp)

> But I don't think it does what you want! The 'Pos of the
> Character '!' is not the same as the 'Pos of the Token '!'.
>
> - Bob

Oh yes it does, hee hee. My awk script goes to great lengths
to define the Token_Type to align with the characters (it
generates the type specification from #defines, sorted and
munged from the yacc output y.tab.h). I did alude to this
in the first post as a FYI, that it has a for Token_Type
use (...) statement to ensure this. Otherwise, you would
be quite correct.

Thanks to everyone, the problem is now solved and I can
move on. The Georg solution was key.

Warren
From: Warren on
Robert A Duff expounded in news:wccr5nj247r.fsf(a)shell01.TheWorld.com:

> X : Token_Unit (Token => T);
>
> to default-initialize stuff.
>
> But I agree it's not worth the trouble.
>
> By the way, why do we call the kind/type of token "Token",
> and the whole token is "Token_Unit" or some such? I realize that's
> what the compiler textbooks often do, but I'd prefer the enumeration
> be called Token_Kind, and the record (containing the kind as well as
> the identifier string or whatever) be called something else, like
> Token.
>
> - Bob

Actually, that is a good point. Before I left the Ada faith a few
years ago, I started doing that (using *_Kind). Its not too late
for me to make that change, so it might get done tonight. ;-)

Warren
From: Warren on
Jeffrey R. Carter expounded in news:hnov3m$t4o$1(a)tornado.tornevall.net:

> Warren wrote:
>>
>> The other way for me to solve this is simply provide
>> a discrimanant that only identifies the few variants. But
>> to keep to 32-bits, I'd have to find a way to specify the
>> discriminant as 3-bits, which I don't think is possible.
>
> Looking at what you have, it looks like a design problem to me. You
> have a whole bunch of enumeration values, but you don't have a bunch
> of variants.

Yep.

> I'd probably have an enumeration type with 3 values that
> serves as the discriminant. Then have 3 enumeration types, one for
> each variant, that gives the specific information that you're now
> trying to use for the discriminant as well.

I was considering that. In fact, I am still mulling over that
possibility for the reason that the choice of "aux info" may change
over time. For example a LEX_FLOAT may initially just point (by ID)
back the collected string. Later it may convert to the actual binary
value etc. So having an independed "representation" descriminant,
may be the right way to go.

> Whether you can encode that in a certain number of bits as you seem to
> be trying to do is another question.

Apparently, that can be done.

Warren
From: Robert A Duff on
Charmed Snark <snark(a)cogeco.ca> writes:

> Robert A Duff expounded in news:wcceijk0vze.fsf(a)shell01.TheWorld.com:
>> But I don't think it does what you want! The 'Pos of the
>> Character '!' is not the same as the 'Pos of the Token '!'.
>
> Oh yes it does, hee hee. My awk script goes to great lengths
> to define the Token_Type to align with the characters (it
> generates the type specification from #defines, sorted and
> munged from the yacc output y.tab.h). I did alude to this
> in the first post as a FYI, that it has a for Token_Type
> use (...) statement to ensure this.

But "for Token_Type use (...)" has no effect on the 'Pos/'Val
attributes. It sets the internal representations, not the
position numbers.

- Bob
From: Warren on
Robert A Duff expounded in news:wcchbof2ec4.fsf(a)shell01.TheWorld.com:

> Charmed Snark <snark(a)cogeco.ca> writes:
>
>> Robert A Duff expounded in news:wcceijk0vze.fsf(a)shell01.TheWorld.com:
>>> But I don't think it does what you want! The 'Pos of the
>>> Character '!' is not the same as the 'Pos of the Token '!'.
>>
>> Oh yes it does, hee hee. My awk script goes to great lengths
>> to define the Token_Type to align with the characters (it
>> generates the type specification from #defines, sorted and
>> munged from the yacc output y.tab.h). I did alude to this
>> in the first post as a FYI, that it has a for Token_Type
>> use (...) statement to ensure this.
>
> But "for Token_Type use (...)" has no effect on the 'Pos/'Val
> attributes. It sets the internal representations, not the
> position numbers.
>
> - Bob

True, but Character'Pos(NUL) is still zero etc. I could get
into trouble though if I were to skip (in Token_Type) any
ranges of [printable] characters, but this is not the case.
After the last non-printable character, this is unimportant
because I don't apply those.

Up until the first printable character, I fill in values,
where I don't have actual token values. Values like LEX_009
for example. So it does work in this particular case.

Warren