|
|
This thread is locked; no one can reply to it.
|
1
2
|
| What about goto? |
|
Matt Weir
Member #7,476
July 2006
|
In the Allegro source code, I think it's in the gui stuff, you'll find an army of goto's. Suckers, you've been using them without knowing all this time, Mwa-ha-ha-ha-ha! |
|
Rampage
Member #3,035
December 2002
|
Quote:
What's here to fix? C/C++ parser builds longest symbols it can build, which I find to be very consistent behavior, so ">>" will always be interpreted as bit shifting operator and not as two separate greater-than's. And templates within templates? -R |
|
Krzysztof Kluczek
Member #4,191
January 2004
|
Quote: And templates within templates?
Template arguments are specified using < an > operators, so its reasonable that < and >> operators shouldn't work here. I'm not sure how they are going to "fix" this in C++0x as this will overcomplicate either parser or syntax analyzer. In first case parser will have to know whether >> should be passed to syntax analyzer as >> operator or two >'s. In second case syntax analyzer will have to be aware of starting < which could have been many lines earlier. In C++ as it is now syntax analyzer has only to look one symbol forward, which makes writing C++ parser using bison/yacc quite straightforward. ________ |
|
Thomas Fjellstrom
Member #476
June 2000
|
Quote:
What's here to fix? C/C++ parser builds longest symbols it can build, which I find to be very consistent behavior, so ">>" will always be interpreted as bit shifting operator and not as two separate greater-than's. Which is stupid. Theres context there to know what you've been parsing. You just saw a template started, why not realize that and see that its two separate >'s? Most parsers, especially generated ones, are too damn stupid to be of any real use. Just look at the horrible error messages they put out. They just don't have enough context to realize that the actual error is/was. Quote: this will overcomplicate either parser or syntax analyzer. Hardly. GCC 4 has already replaced their DUMB bison/yacc parsers with hand rolled recursive decent parsers, which are already faster, but should allow error messages to improve (since you can place them at any point, instead of at places a generated parser finally notices an error), and allow the parser to know what its parsing. Its not that hard. I have an oldish project that uses a lexicalanalyzer setup that allows you to push and pop modes for parsing, like for example, when parsing HTML, you can pop on a CSS analyzer, or javascript, all while the same parser pass is executing. Something like that, just done a little better would fix all the issues. The only time complicating the parser/scanner in a compiler mattered was when you only had 2K ram -- |
|
Krzysztof Kluczek
Member #4,191
January 2004
|
Quote: Which is stupid. Theres context there to know what you've been parsing. You just saw a template started, why not realize that and see that its two separate >'s?
Then parse the code below. template<class _T> class foo; template<int _I> class bar; foo< bar< 1024 >> 2 >
________ |
|
Kitty Cat
Member #2,815
October 2002
|
2 isn't a valid symbol name, so you obviously meant -- |
|
orz
Member #565
August 2000
|
Quote:
What's here to fix? C/C++ parser builds longest symbols it can build, which I find to be very consistent behavior, so ">>" will always be interpreted as bit shifting operator and not as two separate greater-than's. < and > are also used as matched pairs in template parameter lists. And, when multiple nested templates argument lists are terminated without anything intervening, the syntax gets rather weird. For an example with three levels of nesting, these are equivalent ways of naming the same type: std::vector<std::pair<int,std::list<int > > > std::vector<std::pair<int,std::list<int>>>>>> std::vector<std::pair<int,std::list<int>>>>>
Quote: And the way variable initializations are sometimes treated as function declarations.
Quote: Eh? Got an example?
Hm... I thought this was covered in Myers Effective C++, but I can't find it right now. class Foo { public: int a; Foo ( ) : a(0) {} }; int main(int argc, char **argv) { Foo bob(); printf("%d\n", bob.a);//compile error; bob is a function, not an object }
|
|
Bruce Perry
Member #270
April 2000
|
Quote: For an example with three levels of nesting, these are equivalent ways of naming the same type: That implies that someone decided ">>" should be accepted as a substitute for a single ">" in that context. Surely that's going to be even more confusing than just saying "Unexpected token '>>'"? I can see what you mean about the functions and variables now. Wow, C++ is such a mess -- |
|
Thomas Fjellstrom
Member #476
June 2000
|
Ok, I concede, C++ is so crappily designed that even a proper statefull parser couldn't easily handle it. -- |
|
Bob
Free Market Evangelist
September 2000
|
orz said:
< and > are also used as matched pairs in template parameter lists. And, when multiple nested templates argument lists are terminated without anything intervening, the syntax gets rather weird. For an example with three levels of nesting, these are equivalent ways of naming the same type: Umm... #include <vector> #include <list> int main() { std::vector<std::pair<int,std::list<int > > > foo1; std::vector<std::pair<int,std::list<int>>>>>> foo2; std::vector<std::pair<int,std::list<int>>>>> foo3; } MSVC 7.1: $ cl temp.cpp -nologo temp.cpp temp.cpp(5) : error C2947: expecting '>' to terminate template-argument-list, found '>>' temp.cpp(5) : error C2947: expecting '>' to terminate template-argument-list, found '>>' temp.cpp(5) : error C2143: syntax error : missing ';' before '>' temp.cpp(5) : error C2143: syntax error : missing ';' before '>' temp.cpp(6) : error C2947: expecting '>' to terminate template-argument-list, found '>>' temp.cpp(6) : error C2947: expecting '>' to terminate template-argument-list, found '>>' temp.cpp(6) : error C2143: syntax error : missing ';' before '>' temp.cpp(6) : error C2143: syntax error : missing ';' before '>' MSVC 8.0: $ cl -nologo temp.cpp temp.cpp temp.cpp(5) : error C2143: syntax error : missing ';' before '>' temp.cpp(5) : error C2143: syntax error : missing ';' before '>' temp.cpp(6) : error C2143: syntax error : missing ';' before '>' temp.cpp(6) : error C2143: syntax error : missing ';' before '>' GCC 3.4.4: $ gcc temp.cpp temp.cpp: In function `int main()': temp.cpp:5: error: `>>' should be `> >' within a nested template argument list temp.cpp:5: error: `foo2' undeclared (first use this function) temp.cpp:5: error: (Each undeclared identifier is reported only once for each function it appears in.) temp.cpp:5: error: spurious `>>', use `>' to terminate a template argument list temp.cpp:5: error: expected primary-expression before '>>' token temp.cpp:6: error: `>>' should be `> >' within a nested template argument list temp.cpp:6: error: spurious `>>', use `>' to terminate a template argument list temp.cpp:6: error: expected primary-expression before '>' token temp.cpp:6: error: `foo3' undeclared (first use this function) The C++ standard has no mention of this in the template grammar. -- |
|
orz
Member #565
August 2000
|
Hm... perhaps that was MSVC6 only? Certainly I wouldn't actually choose that syntax, but I have seen it work. |
|
HoHo
Member #4,534
April 2004
|
Quote:
Then parse the code below. Here you are
compiled without any warnings and printed out 256 __________ |
|
Krzysztof Kluczek
Member #4,191
January 2004
|
Quote:
Quote: Here you are
Yes, I know that it should work OK. The question arises when we allow >> to be interpreted as two >'s closing two templates - the compiler comes to >> and isn't quite sure whether to treat it as two >'s or one >>. ________ |
|
Thomas Fjellstrom
Member #476
June 2000
|
Technically, if it has access to the symboltable as it parses, and has some extra lookahead, it can see its in foo and bar, and needs a int, which 1024 >> 2 resolves to. Its not impossible, and I bet at somepoint GCC could handle it with its new parser, unless they decide to stick strictly to the specs, which it never has before (gcc has the best extensions -- |
|
Ron Ofir
Member #2,357
May 2002
|
Wow, lot's of interesting issues I never thought about, and probably never will... Anyway, what are trigraphs? And how would you label loops in Java? I don't recall ever seeing such a thing. |
|
Kibiz0r
Member #6,203
September 2005
|
Quote:
Yes, I know that it should work OK. The question arises when we allow >> to be interpreted as two >'s closing two templates - the compiler comes to >> and isn't quite sure whether to treat it as two >'s or one >>. Ick. If that's C++0x, I'm sticking to C++ && Boost. Same neat features, none of the insanity. Edit: Trigraphs. --- |
|
BAF
Member #2,981
December 2002
|
C++ is over. C# by far is superior. |
|
|
1
2
|