[M3devel] C-like syntax for Modula-3 [was Re: "target specific pragmas"?]
Mika Nystrom
mika at async.caltech.edu
Sun Feb 17 06:43:38 CET 2008
Well I used to be mostly a C programmer but I long since weaned
myself off that syntax :)
Your point of the post- and pre-increment might be a bit difficult
for C programmers to stomach, but... well it is probably hard to
tell what programmers will hate and what they will love.
Wouldn't a way to go about it be to take the Modula-3 BNF and modify
the rules as needed? Would you like to be able to convert back and
forth (why not), e.g., using m3tk (m3pp?)? You have to lower-case
all the keywords, convert the braces appropriately (a bit tricky
since Modula-3 has abandoned the Pascal/Algol FOR i := 0 TO 10 DO
BEGIN END, so braces map only to the ENDs, not BEGINs (for the most
part)).
Type "attributes"(is that the right word?) are also an area where
Modula-3 is significantly different from the C family. In C, you
write
int *a, *b, c;
we have
REF INTEGER a, b;
INTEGER c;
And arrays?
VAR arr : REF ARRAY OF ARRAY [FIRST(SomeEnum)..LAST(SomeEnum)] OF ARecord;
ARecord *arr[][first(SomeEnum)..last(SomeEnum)];
I prefer Algol syntax myself but I could definitely see that there
might be people who would prefer a syntax mapped to C. One might
be able to sneak Modula-3 into places where it wouldn't otherwise
be used...
Would it be possible to make "m3c" close enough in syntax that some
simple C header files could be processed? Am I just being ridiculous
now? A compiler that can process both C and Modula-3 in the same
file?
Python, by the way, provides some interesting hooks for C programs
to interact with the Python garbage collector. Something similar
could be done here. (But there is far less reason to write C code
to plug into M3 than there is to write it to plug into Python.)
Mika
Darko writes:
>If you like the idea, maybe you'd like join me in working out what
>such a syntax would look like? Note that I want to keep the structure
>the same, so no assignments in expressions, for example. Also, would C
>programmers revolt at not having post and pre increment, also inside
>expressions (as statements would be ok)? Requiring some sort of EVAL
>statement? I guess the big question is whether removing these things
>would make the whole idea unacceptable to the target audience. Does
>the Algol syntax serve a purpose in making it clear that it isn't C?
>
>
>On 16/02/2008, at 8:42 PM, Mika Nystrom wrote:
>
>>
>> "If Steve Bourne could turn C into Algol using cpp, I'm sure you
>> can figure out how to turn Algol[Modula] back into C using <...>"...
>>
>> If you think it would help acceptance of Modula-3, I don't see why
>> not?
>>
>> I copied the code exactly the way it came off the old half-inch
>> tape from Berkeley.
>>
>> Darko writes:
>>> I'm not sure what you're getting at or if I'm missing something
>>> witty.
>>> I've said the form of the keywords makes little or no difference in
>>> my
>>> opinion. In my mail you quote I say there should be a C like syntax
>>> for M3 as well as the existing one. I wasn't being sarcastic. It's a
>>> matter of taste. I write in both all the time and it doesn't have any
>>> impact on me, I go almost entirely by indentation, which I think is
>>> very important. The indentation is pretty awful in code you posted
>>> but
>>> it could me my mailer.
>>>
>>> On 16/02/2008, at 10:51 AM, Mika Nystrom wrote:
>> ...
More information about the M3devel
mailing list