Unfortunately, unless you are using a 64-bit processor, the 'q' pack format specifier won't help you at all, and if you were using a 64-bit processor you wouldn't have the problem.
I've never had a need for Parser::RecDescent, so your sample grammer is just so much Greek to me;) I do not understand the meaning of your statement about "doesn't recognise nop"? Hopefully, someone with knowledge of that module, maybe even TheDamian himself will happen by and help you with that.
The main problem would appear to be trying to use 48-bit hex constants. You could use the decimal equivalents and just allow them to become floating point with no fear of lost precision, but decimal numbers are mightily inconvenient for this type of work. I'm not sure if P::RD allows you to use functions within the grammer definitions? If it does, you could maybe get away with using a function like
sub BigHex{
my ($int,$long) = unpack'nN', pack 'H*', $_[0];
return 2**32 * $int + $long
}
This would allow you to specify your hex constants as a string parameter to BigHex() (lousy name but you can choose your own), and it would convert it and return a number:
print BigHex 'ffffffffffff'
281474976710655
Unfortunately, attempting to do bitwise arithmetic with numbers greater than 32-bits appears to silently truncate the operands to 32-bit and attempting string-wise bit manipulations of hex-strings won't produce numerically valid results.
print BigHex('ffff0000ffff') | BigHex('0000ffff0000')
4294967295
The other thought I had was using the constant module to define your constants. eg.
use constant xFFFFFFFFFFFE => 281474976710654;
which would be efficient as the constant subs get optimised away, but the silent truncation of values during bitwise manipulations would still be a problem, which is why I think that using two or three integers, or if p::RD can handle it, maybe an array of 2 or 3 integers is probably the only reasonable solution other than Math::BigInt and I am unsure how that would play with P::RD either.
I'm not sure if any of this is useful to you, but maybe it will trigger some other ideas.
Would you mind me asking what the processor is that you are aiming this at? I've never encountered a 48-bit cpu.
Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.
</code>
|