4 ms·
I think the two of you are talking past each other. You're saying, "yes, you need a symbol table", and he's saying, "yes, but a symbol table isn't very hard to
by xscott 5y ago
I think the two of you are talking past each other. You're saying, "yes, you need a symbol table", and he's saying, "yes, but a symbol table isn't very hard to do".
Personally, I wonder how many of these things would go away if pointers were a suffix operator with a different character (maybe the @ sign), and if casts looked like function calls.
A B@; # B is a pointer to type A
A(-B); # A is either a function or a type for casting
# Same AST regardless
- WalterBright 5y agoAs for symbol tables being hard to do, notice that C does not allow forward references. Supporting forward references while relying on the symbol table to drive the parse winds up with unresolvable problems.
- xscott 5y agoI'm not sure I understand your point. I don't think we're disagreeing about anything. C needs forward declarations for some things, and it needs a symbol table to resolve some parts of the grammar. All I was saying was that I think you could resolve both of them with minor changes. (I see that D has a "cast" keyword, and that's obviously one way to do it.)
- esfandia 5y ago> A B@; # B is a pointer to type A IIRC that's how Pascal did it, using a caret ^ for denoting a pointer.
- xscott 5y agoYeah, now only if Pascal had used curly braces, all could be right in the world :-)
- ksec 5y agoArh.... But then it wouldn't be Pascal ><
- peterashford 5y agoYes! As he said - all would be right with the world =)
- zerr 5y agoIt was more about AT&T monopoly I believe :)
- WalterBright 5y agoI don't know about Pascal, but AT&T allowed anyone to write a C compiler without needing a license. (C++, too, I know because I asked AT&T's lawyers.)
- benibela 5y agoKind of. A pointer to type A is: var B: ^A The parser knows it is a declaration because of the var, and it knows ^A is the type, because of the colon. That it is a caret does not really matter here