frontend to LLVM-based compiler - parsing

I am trying to develop a compiler based on the LLVM infrastructure. My language has a C like syntax and so I would like to leverage existing C compilers. Right now I am focusing on the frontend (lexical analysis, parsing), but I am confused as to which frontend would be the best approach. Clang, llvm-gcc or traditional flex/bison tools?
I am specially interested in the simplest solution which would allow me to generate LLVM IR code for later stages of my compiler.

If you want to code everything by hand, then I recommand you the LLVM tutorial Kaleidoscope:
http://llvm.org/docs/tutorial/

Related

Which IDE in order to install and use a compiler with C++14 constexpr relaxation?

I apologize if this question is out of topic, but it's a matter of accessibility for C++14 programmers.
Today i've updated Qt v5.4 on my PC (Windows 8.1/64bit/x86) and it support now the gcc compiler v4.9.2. But i've seen that constexpr relaxation (which really interest me) is available since gcc v5.1.
A search on google shows that :
clang is the better compiler for C++14 latest features (v3.6 is even dealing with experimental C++17)
clang is not easily suitable with Qt libraries
both gcc and clang "datas" are downloadable but i'm not an expert...
So i'm asking how to get a free IDE on Windows 8.1 with an adequate compiler.
If i dismiss Qt for my C++14 experiments, is Codeblocks a better solution ?
Does any else IDE already include an adequate compiler during the installation ?
Where can i find help to install such a compiler ?
Your question is poorly phrased -- for the most part, ide's and compilers are decoupled -- the exception that comes to mind is visual studio, which is an ide that is tightly coupled to microsoft's compiler.
Whether you chose codeblocks, or eclipse, or use a simple text editor, you should be able to choose your compiler fairly easily, and independently of your ide. So you have two independent questions: Where can you get a free compiler for windows with high standards compliance, and what's a good IDE with which to use that compiler.
I'm not a windows person, but very simple, one-file projects, you might actually find it easy to use a gnu-linux environment, which you can do under windows by using cygwin:
http://preshing.com/20141108/how-to-install-the-latest-gcc-on-windows/
This may seem daunting at first, but let me tell you the benefits:
you'll learn the difference between your compiler and editor.
As long as you are only experimenting with the standard, you may find it simpler to get set up than using an ide.
You'll have to learn about the c++ compile process (compiling, linking, possibly preprocessing), not about ide specific stuff.
This will prevent you from conflating ide-specific stuff with c++ stuff, as you have done in your question. As you begin working with projects you'll probably find an ide an advantage, but in the beginning staying close to the raw tools may give you the fastest learning return on investment.
After install cygwin, all you have to do is write your code (using a syntax highlighting editor like gedit or emacs is suggested), and then run
g++ -std=c++14 filename.cpp
to compile your code.
You should be able to use clang under cygwin as well.

Can I use ANTLR on C++ on XCode?

I am wondering if I can use ANTLR on C++ on Xcode? If not, are there any alternatives?
I need production quality of the 3rd party libraries.
Also see: Integrating ANTLR 4 in a C++ application
ANTLR3 has a C target which you can use in a C++ project, albeit with a bit of hacking (no personal experience with that, I base it by reading the answers there).
If not, are there any alternatives?
Sure, it's even been asked before: C++ parser generator which links to the Wiki list of parser generators, and of course, there's Google that has more than one suggestion.

Why do erlang builds include .c and .erl source?

I am not even a newbie to erlang yet, I am just using RabbitMQ, which is written in Erlang. After I run configure/make/make install, the build output directories have plenty of .c and .erl files. Is this necessary? What's the reasoning behind it?
some examples:
./lib/erlang/lib/erl_interface-3.7.6/src/misc/show_msg.c
./lib/erlang/lib/cosNotification-1.1.18/src/oe_CosNotification.erl
Yes, it's necessary. The runtime system of Erlang is written in C, and most of the standard library is written in Erlang.
What's the reasoning behind it?
What would be the alternative? In order to execute any Erlang code, you need to have the runtime system already started, and so it can't be written in Erlang. It could be written in:
Assembly
C
C++ or some other language
Erlang could be executed without a runtime
Assembly is obviously a bad choice: you'd have to rewrite it nearly completely for any new CPU target and it would be much harder to maintain.
C provides excellent performance and portability, and ability to call C code from Erlang would at any rate be required. This is the choice made not only by Erlang, but by Python, Ruby, Perl, etc. as well.
C++ complicates portability (some OSes have C compilers available, but not C++ compilers; quality of C++ compilers varies more); other languages even more so (along with performance, possibly requiring their own runtime, etc.).
The final option would make Erlang a completely different language.

Parser generator for Delphi?

Can anyone recommend a parser generator that will produce win32 Delphi code? What I'm trying to do is create a simple Domain-Specific Language.
How complex is your DSL?
I created a parser (in Delphi) for the new Delphi RIDL language to support some in-house COM generation tools we use.
My approach was to use ANTLR to play around with the syntax rules until I had something that parsed the various test files I had. I then hand-coded a recursive descent parser (based on the Java generated by ANTLR). I was also using the Castalia Delphi Parser in the project, so I based my lexical analyser on that.
Recursive descent parsers are actually really simple (but tedious :-) ) to write manually.
The Delphi versions of Coco/R are quite ok:
http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/
most notably Pat Terry's one:
http://www.scifac.ru.ac.za/coco/
Try this:
http://www.grendelproject.nl/dyacclex/
I have not tried this at all and I just noticed the information while I was reading through the documentation, but FastScript, in their documentation which you can get here, says that you can use their parser to create your own language which you specify in an XML file. This might give you something you can use.
I found Antlr For Delphi 3.1.1.
SharpPlus Antlr For Delphi Target
3.1.1, a language tool that provides a framework for constructing
recognizers, interpreters, compilers
with Delphi!
It is a commercial product. I have no idea what it is like.

What tools are built using themselves? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am curious about what tools are used to build the next version of themselves.
For example, Delphi has long claimed that "Delphi is written in Delphi".
I assume Visual Studio is written using Visual Studio.
What are some other examples of tools that written in themselves?
Interestingly, the VB.NET & C# compilers themselves are written in unmanaged C++ (leading to the C++ team's T-Shirt: "My compiler compiled yours"). The C# team hopes to have a fully managed-C# hosted C# compiler for VS2010.
Bjarne Stroustrup mentioned in The Design and Evolution of C++ that the first C++ compiler was written in C++.
I've just noticed this is also a question in his FAQ:
The first C++ compiler (Cfront) was
written in C++. To build that, I first
used C to write a "C with
Classes"-to-C preprocessor. "C with
Classes" was a C dialect that became
the immediate ancestor to C++. That
preprocessor translated "C with
Classes" constructs (such as classes
and constructors) into C. It was a
traditional preprocessor that didn't
understand all of the language, left
most of the type checking for the C
compiler to do, and translated
individual constructs without complete
knowledge. I then wrote the first
version of Cfront in "C with Classes".
This is off-topic, but strictly speaking, it is an example of a tool which builds itself.
The reprap - an open-source 3d prototyping machine, which recently gave 'birth' to "its first complete working replicated copy".
I love this kind of stuff.
Generically speaking, C compilers are usually written in C... *nix kernels are compiled on *nix, etc.
Also, there's the pypy project which provides a Python interpreter written in Python.
When gcc (the Gnu C compiler http://gcc.gnu.org/) was not available widely, you had to compile it from source, compiling stage1 compiler, then compile stage2 with stage1, till you have your final compiler. I assume it must be the same today.
Here is another example: Mono's C# compiler is self hosting - i.e. it's written in C# and used to compile itself.
Dog fooding refers to the more general practice of a company using its own product internally, especially during its development.
Lots of folks like to look at how Lisp can be implemented in Lisp.
Squeak is a Smalltalk-80 implementation written in itself.
even its virtual machine is written entirely in Smalltalk making it easy to debug, analyze, and change.
Sun's Java compiler has long been written in Java. However, recent work is writing a JIT compiler in Java as well. This is the JVM component that converts Java byte code to native processor instructions.
We use to develop using RealBasic. The IDE is written in itself, or so I've been lead to believe.
ghc, the Haskell compiler, is mostly written in Haskell.
tcc is another self-hosting C compiler for x86 and ARM. Its claim to fame is being, well, tiny (100k or so for preprocessor, compiler, assembler, and linker).
I would assume that pretty much any tool that's part of the typical development process would be involved in its own development, to whatever extent possible. This includes:
certain programming languages, especially compiled ones
IDEs
text editors
version control systems
bug trackers
build systems
If you're on a team building one of these tools, and you're not developing it for a specific niche that doesn't apply to your team, I don't know why you wouldn't use it to build itself. Having developers be users of the product is one of the best ways to find possible improvements.
For the AmigaOS there was a third party Basic interpreter (don't remember the name) for which you could later buy a compiler. The compiler was delivered as source, so you had to use the interpreter to run the compiler to compile itself...
To cite Kent Beck:
...it may seem a bit like performing brain surgery on yourself.
Visual Studio and Team Foundation Server build themselves. It's called dogfooding, a term which if not originating in Microsoft, it certainly likes
Oracle Application Express is a web application development tool that is built in itself.
Eclipse IDE is generally built and developed using Eclipse IDE.
It is fairly typical to have a languages compiler written in its own language. This is called self-hosting or bootstrapping.
Maven2 is built using Maven2.
Ok, it's not built (i.e. written) using itself, as it is a tool to build (i.e. compile) project, but it is using its own code to compile...
I was amazed with JSLint
In short it has been described as Javascript "compiler" using javascript.
I am building an IDE-based code generator, and I am using it to build itself. If fact, as Stroustrup did, I am first building a valid generator model and using a pre-processor to build the final C++ code to compile. Once I have a good working version of the IDE, I'll start using it to build further versions of itself.
It's like giving a new dimension to the meaning of "recursive programming"!
AFAIK does the OpenJDK build itself first with the installed java and afterwards with itself.
Naturally the Jetbrains team uses its own IDE IntelliJ IDEA to develop this IDE.
I assume this is true for most IDE vendors.
As far as I know, when building EMACS from source, all of the ELISP code is bootstrapped. I found that quite noteworthy.
Not quite what you're asking for, but the entire development environment for Revolution http://www.runrev.com is built using Revolution itself, and the source (except for small parts that enforce the license) is completely exposed in source form. So if you don't like the way the dev environment is implemented, you can change it. Find a bug, fix it. You can also easily build additional development tools and integrate them.
Ada and Forth
I gave the Smalltalk-80 answer an uptick. Best, most elegant example I can think of. The question also reminds me of a slightly related problem that used to be popular: write a program that outputs itself. Not the same level of bootstrapping, but a fun little programming puzzle for your amusement. Maybe not possible in all languages?
The old Watcom C/C++ compiler was built using itself.
Kragen Sitaker's Ur-Scheme is a fine example of a small nontrivial compiler written in itself. That page links to several more good sources in that vein.

Resources