Gang of Four: lexi editor c++ source - c++

I'm reading "Design Patterns: Elements of Reusable OOSW". In chapter two, the authors provide a case study of an editor they refer to as Lexi, which seems to be written in C++. I've looked around everywhere, but the only useful link I could find said this:
The Gof tell us in a note that Lexi is
based on "Doc, a text editing
application developed by Calder". But
this paper only outlines an editor,
without any source. And I even believe
today that Lexi never truly existed as
a program.
The link provides Delphi source. I'm after C++, cause that's what I'm comfortable with, and that's what's used in the book.
Does anybody know where I can find C++ source for Lexi? If the original never existed, it would be good to find something that I can use as a base. I really don't feel like writing my own text editor from scratch just so I can work through the case study in this book.

Doc was developed using the InterViews UI toolkit. I believe that doc source is part of the InterViews distribution. Doc was used to typeset Paul's thesis. (Paul Calder was my lecturer at Flinders University)
If you look at the InterViews code you might be surprised. It was developed before modern C++ existed. For example, there are no templates. And there are no comments in the code.
To my understanding, Lexi never existed. It was created as an example for the book by GoF.

Maybe a Java implementation can help, being it more similar to c++. Here it is:
jexieditor - A WYSIWYG editor based on JavaSE. I have not had a look at the code yet, anyway

I may be showing my age here but are you sure about C++? I have a funny feeling that when that book came out originally it may have been oriented toward Smalltalk. Its just something nagging at the back of my mind, I can't substantiate it I'm afraid

I'm currently implementing Lexi analog, pls take a look https://github.com/romaonishuk/LexI. Implementation is still in progress, but most of the described in GoF patterns and concepts are implemented using C++.

This is the code source of LEXI, written in Delphi unfortunately for you: LEXI sources.

It appears that the source code might be on the CD-ROM version of Design Patterns that came out in 1998. According to the Amazon listing, the CD contains (among other things):
Sample code demonstrating pattern implementation
Furthermore,
All patterns are compiled from real-world examples and include code that demonstrates how they may be implemented in object-oriented programming languages such as C++ and Smalltalk. Readers who already own the book will want the CD to take advantage of its dynamic search mechanism and ready-to-install patterns.
Whether these code samples include the full Lexi source is impossible to tell from the listing, and the current price of the CD (£86.87) is rather high. But it might be worth checking if any local libraries have the CD in stock.

I was just trying to find out if a real working Lexi version exists, to have a concrete reference, but I didn't find it.
I found this Java version on GitHub: https://github.com/AmitDutta/lexi
I don't know, maybe it could be useful for someone's purpose here.

Related

Making a GUI with turbo c++?

Note: I am new to programming and extremely new to c++.I have seen scouring google for a long time and only things i can come up with are external headers and very complicated code..
I want to do this at school, and there we are provided with Turbo C++. We can't bring any external headers in there, gotta work with whatever i've got.
I want to create a GUI. I want to create something really good for our annual project and i want to create a GUI.
I would like to make as detailed a GUI as possible, but would be satisfied if i can create as much as several text options and clicking on em triggers respective functions (I am sorry if thats not how GUIs work, i never worked with one).
Again help is highly appreciated, i understand most discussions on Stack Overflow are much more complicated than this, i appreciate you taking the time to read and (hopefully) answer a layman question.
I'll suggest a non-technical solution because this is actually largely not a technical problem. Much of your problem is that you have to use Turbo C++. Unfortunately, a number of poorer countries have, for some reason, stuck with extremely outdates software in education. I know because I'm originally from one of the "Turbo countries", and I know that the main technical university there still uses Turbo for undergrad courses.
This is bad. Large projects in school are there to teach you to work on software. A regular programming course should teach you to think like a programmer, and it doesn't matter what language you use. But term projects are supposed to be more practical. The problem is, with Turbo C++, not only will you fail to learn enough, you will learn things that are bad. You'd be writing a 16-bit program that takes effort to even run on modern hardware, while not being able to use the C++ language properly. The compiler is older than the first ISO C++ standard!
If you want to make an impressive project that will stand out in your studies, especially if you later want to continue at a foreign university, I urge you to talk to your professor, explain the situation, and ask if you can use something else for the project. A modern compiler with some framework like Qt. If you can reach an agreement to use something else, it will benefit you.
Otherwise, if you have no choice, get Turbo Vision. There are versions of BC++ packaged with it, or you can find it elsewhere, Turbo Vision is a fairly comprehensive interface framework for the dinosaur era.
First off, the toolchain and operating system you are using is outdated and incapable. And the language support Turbo C++ offers can hardly be called C++ at all; the code you will write will not be C++ code. At best, it will be C with classes code.
All that aside, there was a fairly-capable Text-based User Interface (TUI) library available with Turbo C++ (as well as Borland's Pascal-based toolchains,) called Turbo Vision. You might be able to use that. It generates UIs quite similar to the Turbo C++ IDE itself.
But IIRC, it was not trivial to use, so I advise you to find a book or reference or comprehensive tutorial of some kind. However, since your environment precludes anything that is not available already with TC, I see no option for you other than using Turbo Vision or writing your own, which doesn't sound like something you can do or want to do.

Is it necessary to learn Java for contributing to an open source project?

I am more into C/C++. But many of my seniors here in college ask me to learn Java if I want to contribute to an open source project.. I'm in dilemma. what to do? Can't we do a design project in C/C++?
There are plenty of open source C and C++ projects - as well as loads in virtually any other language you can come up with.
Of course it's never a bad idea to learn another language, but don't feel too constrained by "only" knowing C and C++.
If you want to contribute to a specific open source project which is written in Java, of course, that's a different matter... but if you're trying to find C and C++ open source projects, some of the major hosting sites support querying by project language, I believe. For example, you can look at Google Code C++ projects and SourceForge projects tagged C++.
is it necessary to learn java for contributing to an open source project?
#: No
what to do??
#: Do whatever you are passionate with
Can't we do a design project in c/c++??
#: Of course you can, lots of non-java projects out there
Select an interesting C or C++ project and contribute to it. For example look at Tortoise SVN - it's in Visual C++, it's widely used, it's actively developed and its authors accept any useful contributions.
Not unless you want to participate in a Java project, and then again, you can learn it pretty quick if you know C++.
It would only be necessary to learn java if the open-source project you want to contribute is in java. There are so many open-source projects in c/c++ as well. The great example is Linux
If you are good at c/C++ there are plenty of OS projects in c/c++.
They are also fair amount of project in Dot Net and c#.
Contribute where you are strong...
It up to you in which domain you would like to be an expert, so select an open source project based on your interests and start contributing to that domain which would definitely help you in future.
You should also have the fundamental knowledge of other technologies so to learn a new thing is always good.
It up to you in which domain you would like to be an expert, so select an open source project based on your interests and start contributing to that domain which would definitely help you in future.
You should also have the fundamental knowledge of other technologies so to learn a new thing is always good.
Yes, you could contribute in areas like documentation/setup/deployment issues if not.

How do C/C++ compilers work?

After over a decade of C/C++ coding, I've noticed the following pattern - very good programmers tend to have detailed knowledge of the innards of the compiler.
I'm a reasonably good programmer, and I have an ad-hoc collection of compiler "superstitions", so I'd like to reboot my knowledge and start from the basics.
Can anyone recommend links to online resources or favorite books? I'm particularly interested in C/C++ compiling, optimization, GCC and LLVM.
Start with the dragon book....(stress more on code optimization and code generation)
Go onto write a toy compiler for an educational programming language like Decaf or Cool.., you may use parser generators (lex and yacc) for your front end(to make life easier and focus on more imp stuff)....
Then read gcc internals book along with browsing gcc source code.
GCC Internals Manual.
CPP Internals Manual
LLVM Documentation
Compiler Text are good, but they are a bit heavy for teaching yourself. Jack Crenshaw has a "Book" that was a series of articles you can download and read call "Lets Build a Compiler." It follows a "Learn By Doing" methodology that is great if you didn't get anything out of taking formal classes on the subject, or it's been WAY too many years since took it (that's my case). It holds your hand and leads you through writting a compiler instead of smacking you around with Lambda Calculus and deep theoretical issues that only academia cares about. It was a good way to stir up those brain cells that only had a fuzzy memory of writting something on the Vax (YEAH, that right a VAX!) many many moons ago at school. It's written very conversationally and easy to just sit down and read, unlike most text books which require several pots of coffee just to get past the first chapter. Once you have a basis for understanding then more traditional text such as the Dragon book are great references to expand on your understanding. (And personal I like the Dead Tree versions, I printed out Jack's, it's much easier to read in a comfortable position than on a laptop. And the Ebook readers are too expensive for something that doesn't actually feel like you're reading a real book yet.)
What some might call a "downside" is that it's written in Pascal, but I thought that just made me think about it more than if someone had given me a working C program to start with. Appart from that it was written with the 68000 in mind, which is only being used in embedded systems at this point time. Again for me this wasn't a problem, I knew 68000 asm and 68000 asm is easier to read than some other asm.
If you want dead-tree edition, try The Art of Compiler Design: Theory and Practice.
As noted by Pete Eddy, Jack Crenshaw's tutorial is excellent for newbies. But if you want to see how to a real, production C compiler works—one which was designed by brilliant engineers instead of created by throwing code at the wall until something stuck—get yourself a copy of Fraser and Hanson's A Retargetable C Compiler: Design and Implementation, which contains the source code to the very clean lcc compiler. Explanations of the design and implementation are mixed in with the code. It is not a first book for a beginner, but it will repay careful study, and you can get a used copy for $35.
For a longer blurb about lcc, see Compile C Faster on Linux.
The lcc web page also has links to a number of good textbooks. I don't know of an intro text that I really like, however.
P.S. Sorry you got ripped off at Uni.
http://se-radio.net/podcast/2007-07/episode-61-internals-gcc
see Fabrice Bellard's otcc source code
http://bellard.org/otcc/
Depending on what you exactly want to know, you should have a look at pipes&filter pattern, because as far as I know this (or something similar) is used in a lot of compilers in the last years.
When my compiler knowledge is not too outdated it works like this:
Parse sourcecode into symbolic representation
Clean up symbolic representation, do some normalization
Optimization of the symbolic tree based on certain rules
write out executable code based on symbolic tree
Of course dependencies etc. have to be resolved too.
And of course having a look at gcc or javac sourcecode may help in getting more detailed understanding.
It may also be valuable to pick up and read the source code to a compiler. I doubt that GCC is the best first choice, since it is burdened with full compatibility to more than 20 years of evolution of the language. But I'm also sure that a reading of its source, guided by one of the internal reference manuals, would be educational.
I'd seriously consider looking at the source to a scripting language that is internally compiled to a bytecode for a virtual machine. Several languages fit that description, but I would start with Lua. The language is small, and the VM is novel. The source code is also small and the bits I've looked at have been very clear although lightly commented.
have a look on Kaleidoscope.
You can write your own compiler in just a few days with LLVM.

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up.
I am basically looking for something to take code written by two people, and clean it up to a standardized style. Does such an app exist?
Thanks a bunch!
Artistic Style
is a source code indenter, formatter,
and beautifier for the C, C++, C# and
Java programming languages.
GC Great Code
is a well known C/C++ source code
beautifier.
Of course I find an answer to my own question moments later. What luck, I probably spent an hour searching earlier.
Should anyone be looking for the same thing, check out Uncrustify at http://uncrustify.sourceforge.net/
If you're using Visual Studio then you could take a look at StyleManager*. It's a VS add-in that makes it easy to set up formatting styles and apply them to code whenever you need to. It's a popular choice with VS users, and in particular was used by the DirectX SDK team to tidy up their sample code.
*Huge disclaimer: I'm one of the authors of this software, so apologies for the shameless plug!
You can tidy your code online, with this website:
https://codebeautify.org/cpp-formatter-beautifier
https://codebeautify.org/cpp-formatter-beautifier

Good tools for creating a C/C++ parser/analyzer [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
What are some good tools for getting a quick start for parsing and analyzing C/C++ code?
In particular, I'm looking for open source tools that handle the C/C++ preprocessor and language. Preferably, these tools would use lex/yacc (or flex/bison) for the grammar, and not be too complicated. They should handle the latest ANSI C/C++ definitions.
Here's what I've found so far, but haven't looked at them in detail (thoughts?):
CScope - Old-school C analyzer. Doesn't seem to do a full parse, though. Described as a glorified 'grep' for finding C functions.
GCC - Everybody's favorite open source compiler. Very complicated, but seems to do it all. There's a related project for creating GCC extensions called GEM, but hasn't been updated since GCC 4.1 (2006).
PUMA - The PUre MAnipulator. (from the page: "The intention of this project is to
provide a library of classes for the analysis and manipulation of C/C++ sources. For this
purpose PUMA provides classes for scanning, parsing and of course manipulating C/C++
sources."). This looks promising, but hasn't been updated since 2001. Apparently PUMA has been incorporated into AspectC++, but even this project hasn't been updated since 2006.
Various C/C++ raw grammars. You can get c-c++-grammars-1.2.tar.gz, but this has been unmaintained since 1997. A little Google searching pulls up other basic lex/yacc grammars that could serve as a starting place.
Any others?
I'm hoping to use this as a starting point for translating C/C++ source into a new toy language.
Thanks!
-Matt
(Added 2/9): Just a clarification: I want to extract semantic information from the preprocessor in addition to the C/C++ code itself. I don't want "#define foo 42" to disappear into the integer "42", but remain attached to the name "foo". This, unfortunately, excludes several solutions that run the preprocessor first and only deliver the C/C++ parse tree)
Parsing C++ is extremely hard because the grammar is undecidable. To quote Yossi Kreinin:
Outstandingly complicated grammar
"Outstandingly" should be interpreted literally, because all popular languages have context-free (or "nearly" context-free) grammars, while C++ has undecidable grammar. If you like compilers and parsers, you probably know what this means. If you're not into this kind of thing, there's a simple example showing the problem with parsing C++: is AA BB(CC); an object definition or a function declaration? It turns out that the answer depends heavily on the code before the statement - the "context". This shows (on an intuitive level) that the C++ grammar is quite context-sensitive.
You can look at clang that uses llvm for parsing.
Support C++ fully now link
The ANTLR parser generator has a grammar for C/C++ as well as the preprocessor. I've never used it so I can't say how complete its parsing of C++ is going to be. ANTLR itself has been a useful tool for me on a couple of occasions for parsing much simpler languages.
Depending on your problem GCCXML might be your answer.
Basically it parses the source using GCC and then gives you easily digestible XML of parse tree.
With GCCXML you are done once and for all.
pycparser is a complete parser for C (C99) written in Python. It has a fully configurable AST backend, so it's being used as a basis for any kind of language processing you might need.
Doesn't support C++, though. Granted, it's much harder than C.
Update (2012): at this time the answer, without any doubt, would be Clang - it's modular, supports the full C++ (with many C++-11 features) and has a relatively friendly code base. It also has a C API for bindings to high-level languages (i.e. for Python).
Have a look at how doxygen works, full source code is available and it's flex-based.
A misleading candidate is GOLD which is a free Windows-based parser toolkit explicitly for creating translators. Their list of supported languages refers to the languages in which one can implement parsers, not the list of supported parse grammars.
They only have grammars for C and C#, no C++.
Parsing C++ is a very complex challenge.
There's the Boost/Spirit framework, and a couple of years ago they did play with the idea of implementing a C++ parser, but it's far from complete.
Fully and properly parsing ISO C++ is far from trivial, and there were in fact many related efforts. But it is an inherently complex job that isn't easily accomplished, without rewriting a full compiler frontend understanding all of C++ and the preprocessor. A pre-processor implementation called "wave" is available from the Spirit folks.
That said, you might want to have a look at pork/oink (elsa-based), which is a C++ parser toolkit specifically meant to be used for source code transformation purposes, it is being used by the Mozilla project to do large-scale static source code analysis and automated code rewriting, the most interesting part is that it not only supports most of C++, but also the preprocessor itself!
On the other hand there's indeed one single proprietary solution available: the EDG frontend, which can be used for pretty much all C++ related efforts.
Personally, I would check out the elsa-based pork/oink suite which is used at Mozilla, apart from that, the FSF has now approved work on gcc plugins using the runtime library license, thus I'd assume that things are going to change rapidly, once people can easily leverage the gcc-based C++ parser for such purposes using binary plugins.
So, in a nutshell: if you the bucks: EDG, if you need something free/open source now: else/oink are fairly promising, if you have some time, you might want to use gcc for your project.
Another option just for C code is cscout.
The grammar for C++ is sort of notoriously hairy. There's a good thread at Lambda about it, but the gist is that C++ grammar can require arbitrarily much lookahead.
For the kind of thing I imagine you might be doing, I'd think about hacking either Gnu CC, or Splint. Gnu CC in particular does separate out the language generation part pretty thoroughly, so you might be best off building a new g++ backend.
Actually, PUMA and AspectC++ are still both actively maintained and updated. I was looking into using AspectC++ and was wondering about the lack of updates myself. I e-mailed the author who said that both AspectC++ and PUMA are still being developed. You can get to source code through SVN https://svn.aspectc.org/repos/ or you can get regular binary builds at http://akut.aspectc.org. As with a lot of excellent c++ projects these days, the author doesn't have time to keep up with web page maintenance. Makes sense if you've got a full time job and a life.
how about something easier to comprehend like tiny-C or Small C
Elsa beats everything else I know hands down for C++ parsing, even though it is not 100% compliant. I'm a fan. There's a module that prints out C++, so that may be a good starting point for your toy project.
See our C++ Front End
for a full-featured C++ parser: builds ASTs, symbol tables, does name
and type resolution. You can even parse and retain the preprocessor
directives. The C++ front end is built on top of our DMS Software Reengineering
Toolkit, which allows you to use that information to carry out arbitrary
source code changes using source-to-source transformations.
DMS is the ideal engine for implementing such a translator.
Having said that, I don't see much point in your imagined task; I don't
see much value in trying to replace C++, and you'll find building
a complete translator an enormous amount of work, especially if your
target is a "toy" language. And there is likely little point in
parsing C++ using a robust parser, if its only purpose is to produce
an isomorphic version of C++ that is easier to parse (wait, we postulated
a robust C++ already!).
EDIT May 2012: DMS's C++ front end now handles GCC3/GCC4/C++11,Microsoft VisualC 2005/2010. Robustly.
EDIT Feb 2015: Now handles C++14 in GCC and MS dialects.
EDIT August 2015: Now parses and captures both the code and the preprocessor directives in a unified tree.
EDIT May 2020: Has been doing C++17 for the past few years. C++20 in process.
A while back I attempted to write a tool that will automatically generate unit tests for c files.
For preprosessing I put the files thru GCC. The output is ugly but you can easily trace where in the original code from the preprocessed file. But for your needs you might need somthing else.
I used Metre as the base for a C parser. It is open source and uses lex and yacc. This made it easy to get up and running in a short time without fully understanding lex & yacc.
I also wrote a C app since the lex & yacc solution could not help me trace functionality across functions and parse the structure of the entire function in one pass. It became unmaintainable in a short time and was abandoned.
What about using a tool like GNU's CFlow, that can analyse the code and produce charts of call-graphs, here's what the opengroup(man page) has to say about cflow. The GNU version of cflow comes with source, and open source also ...
Hope this helps,
Best regards,
Tom.