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>

In reply to Re: Re: Re: Parse::RecDescent for 48bits by BrowserUk
in thread Parse::RecDescent for 48bits by bear_hwn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.