I am developing a Pascal Compiler, […]
You're developing
a compiler? Oy.
The FPC doesn't suit your case, or what? You know, you're welcome to contribute, don't you [rhetorical]?
[…] I need some syntax that let me declare some kind of variables, with the ability to be accessed, globaly or bit by bit. […]
There are already
sets providing some sort of bitwise read/write access. Or do you want that as an additional language construct to
all types, in order to disclose the internal memory structure?
Somehow that sounds to me contrary to Pascal's paradigms.
One chunk of memory has
one interpretation (data type).
VAR
foo: […] //let me access as byte or individually bits
I would refrain from providing some general way – working out of the box – to access all the bits. Instead the programmer should explicitly request “Hey,
also I'd like to interpret that chunk of memory as a set of independent bits”, e.g. like so:
var
// statements with colon ':',
// define variables allocating _new_ memory
foobar: byte;
// analog the 'type' section introduce aliases
// to _same_ _spots_ we already allocated
foobit = bits(@foobar);
Now, the
bits data type is some
record structure or a (bitpacked) array of boolean values (like already suggested). This statement should be valid, iff
sizeOf(foobar) = sizeOf(foobits) (so a
byte is as large as
bits).
Taking this approach variables still reside on the
stack, but you (as a developer) don't have to typecast them every single time you'd like to access them, since a
second identifier is gained.
PS: The topic's title reads “Pascal Syntax for bit access.”. Well, to be fair you'd like to come up with some Pascal-
ish syntax.