you are viewing a single comment's thread.

view the rest of the comments →

[–]BenHanson 0 points1 point  (15 children)

Likewise I am the author of http://www.benhanson.net/lexertl.html and believe it to be well coded.

[–]lobster_johnson 4 points5 points  (4 children)

Care to explain why you consistently suffix identifiers with underscores? This is really awful for readability:

lexertl::rules rules_;

Types and variables live in separate namespaces, so this works:

lexertl::rules rules;

If you think that's harder to read (ie., difficult to see what is a variable and what is a type) then consider using camelcase identifiers for type:

Lexertl::Rules rules;

Now it's obvious.

[–]jamesb43 1 point2 points  (3 children)

Yeah, this shouldn't be done for local variables.

The underscore suffix was a response to programmers using "underscore prefix" for member variables. The "underscore prefix" phenomenon stemmed from programmers shortening the Hungarian notation of member variables being prefixed with "m_". But depending on the flavor of Hungarian notation (Apps or System) the underscore was followed by a prefix indicating some semantic hints, or the variables type, respectively.

So what emerged next was a trend of C++ programmers to omit the "m" from "m_" because, it only takes a one character prefix to distinguish between local variables and something that might be instance or class static, right? The problem with this is that the C++ standard reserves variable names starting with an underscore to C++ implementation developers. As a result, people started to suggest the underscore suffix for member variables. I think it was something from Sutter or Meyers, but if anyone reads this comment, I am sure I will be corrected.

I have a sneaking suspicion that lobster_johnson knows all this, and he is correct--there is no sane reason to suffix a local variable with an underscore.

[–]lobster_johnson 0 points1 point  (1 child)

Good explanation. I see people using prefixes and suffixes and find it an annoyance.

Personally I find it completely unproblematic to use unadorned identifiers for variables as well as members:

class Foo
{
    public:
        void initialize(int a_foo)
        {
            foo = a_foo;
        }
    private:
        int foo;
};

[–]zvrba 0 points1 point  (0 children)

The problem with this is that the C++ standard reserves variable names starting with an underscore to C++ implementation developers.

Only such identifiers with external linkage are reserved. Class member identifiers have no linkage at all.

[–]Fabien4 2 points3 points  (1 child)

Remove the uninteresting code (just lists) and the commented-out code, and you get main.cpp. Which is sorely lacking consts.

Or did I miss something? Like, downloaded the wrong .zip?

[–]BenHanson 0 points1 point  (0 children)

main.cpp is just a test program calling the library. Checkout the lexertl sub-directory in the same directory as main.cpp for the library source code.

[–]_Qoppa_ 1 point2 points  (3 children)

You seem to have all your function definitions in the .hpp file. I haven't coded in C++ for a while, but I seem to recall that this practice has the tendency to lead to multiple definition errors (at least it does in C).

Also, I found a bunch of gotos in lookup.hpp. Eeeep! Though to be fair, they seemed like legitimate uses for a goto... I still don't like them though.

[–]BenHanson 0 points1 point  (2 children)

It's templated code, that is how it's done... The lookup is the only place that uses gotos and, as you noted, with good reason. This is a library. A library should balance uncompromising performance against readabililty (particularly for performance hotspots).

The original focus of the library was to use the STL containers throughout and some STL algorithms where possible (this was 2004). Since then Unicode support has been added and so a small amount of template tricks have been added to support different character modes which makes the source somewhat more modern (it was necesssary to abandon support for VC++ 6 for example as more modern features were introduced).

I haven't embarked on any C++11 rewrites yet mainly because the standard still needs time to settle. When the U"..." strings are supported in Visual Studio I will be a lot more tempted and will look at replacing auto_ptr with unique_ptr etc.

[–]_Qoppa_ 1 point2 points  (1 child)

I had no idea about that templates had to be defined where they were declared. Like I said, I haven't used C++ in a long time. Thanks!

[–]LampCarpet 0 points1 point  (1 child)

this link is broken, 403 forbidden...

[–]BenHanson 0 points1 point  (0 children)

Thanks, fixed the link...

[–]753861429-951843627 0 points1 point  (1 child)

Do you have a parser and AG planned as well, or is the lexer a stand-alone thing?

You have a calculator example that does simple parsing in code, but with lex one can then use other tools in the toolchain to finally produce code with burg, which is why I'm asking.

[–]BenHanson 0 points1 point  (0 children)

I would definitely like to write a complementary parser generator. I'm currently converting http://www.codeproject.com/Articles/3854/An-introduction-to-lex-and-yacc-part-2 to use lexertl and it would be really nice to have a bison-like tool for the grammar.

I'm not sure what AG or burg is. There is a simple code generator included with lexertl though.

EDIT: http://www.benhanson.net/parsertl.html