As an example, Emacs syntax-highlights both "YY xx" and "int xx" the same way.
As an example, Emacs syntax-highlights both "YY xx" and "int xx" the same way.
(A) * B
This is either A multiplied by B, or type A casting the dereferenced value of B: http://en.wikipedia.org/wiki/The_lexer_hackSignificant whitespace is evil, at least in the context of C where it is not significant anywhere else.
That's basically what C++ did by requiring the space in:
Foo<Bar<Baz> > var;
to make it easy to lexically distinguish the '>>' right-shift operator from the '> >' sequence of two successive template-parameter closing symbols.C++0x is changing that though, due to the unpopularity of making programmers accomodate what looks like a parser-implementation hack.
The article says that this code is "evil", but I disagree. There is a valid pattern that I use quite often (I described it in an article for ACCU a few years ago, too). It's an example from C++ but I think I could apply it to C as well. Consider (with a modification of the example I used in that article):
struct PirateShip { struct Cannons { char* cannon1; char* cannon2; } Cannons; }
Now you can use
PirateShip s; printf("Name of the first cannon: %s\n", s.Cannons.cannon1);
which is very readable and idiomatic (once you get used to it ;) )
More abstract, it provides an idiomatic way to group collections of objects/structs at the source code/syntactic level.
(one could name the struct and the member differently, I realize; the benefit of using the same name is when you define constant members in the inner struct, that way you can reference constants and properties with the same name and you never have to think about which one to use.)
(also again I use this from C++, there may be things that are different in C, but afaik this part is the same).
struct PirateShip {
struct PirateShip {
char* cannon1;
char* cannon2;
}
PirateShip PirateShip;
}
Am I misunderstanding?To parse this correctly, the parser has to receive a "TYPE-NAME" token for XX and an "IDENTIFIER" token for yy. If the parser receives an IDENTIFIER token for XX, this will result in a parse error.
Or, to put it another way, you resort to uglyfying the lexer to overcome definiciencies in the parser.