4 ms·
Not mentioned in the article is the typedef problem in C. Early C didn't have typedef, just struct. The grammar was LALR(1), and context-independent - knowing
by Animats 12y ago
Not mentioned in the article is the typedef problem in C.
Early C didn't have typedef, just struct. The grammar was LALR(1), and context-independent - knowing the syntax and the reserved words, you could parse C.
Then came typedef. Now, to parse C/C++, you must know the names of types. So, to parse a C/C++ file, you must read and interpret all the #include files first. This makes it hard to write tools that work on C/C++ source.
This isn't a problem with the declaration syntax of the Pascal/Modula/Ada/Go line of languages, where declarations have the order "x int" instead of "int x". So "go fmt" doesn't have to have all the dependencies just to clean up the indentation.
- WalterBright 12y agoBecause of macros, you have to read and interpret all of the #include files anyway.
- Animats 12y agoTrue. I've seen macros used to drastically change the syntax of C. Such as #define IF(x) if (x) { #define ELSE } else { #define ENDIF }
- deleted 12y ago[deleted]
- gnuvince 12y agoGo has a similar problem: function calls and type conversions share the same syntax (or sufficiently the same syntax). If you see `x(t)` in a Go file, there's no way to know if that's a function call or a type conversion without some semantic information. Also built-ins, which also look like functions, come in to add an extra layer of difficulty.
- tomp 12y agoYou can interpret that as calling a coercion function that converts a value from one type to another type. Python actually works like that.