Flex/Bison based compiler - binary generation [closed] - c++

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 5 years ago.
Improve this question
I have a compiler of Pascal subset written using Flex/Bison and C++. As input I use own .pas files. I have noticed that when I run my compiler with those input it works more like an interpreter because I get an instant result. I would like to get the binary file to avoid the need of using the compiler every time. My question is:
What is the best approach to generate binary file?

You can do this for example in this way (I done it in this way many years ago):
Using Flex/Bison, you have to generate pseudo asm code.
In the next step, you have to translate it to macro assembly for the given CPU architecture (x86/ARM/MC68k/PPC/...)
Compile output asm file into object file (.o)
Link .o file/files with needed libs (.lib) into executable file.
Besides, as commented above, try to find some book about compilers. The best one will be the Dragon Book, a kind of compiler bible: https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools

Related

How do I change the architecture of my .so file to arm64-v8a? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
Improve this question
I have a file called libheloo.so (also the source code) and I want to change the architecture of it to arm64-v8a or armeabi-v7a. I looked around online but couldn't find anything. Can someone help me change the architecture to one of these please.
[updated]
The binary is pretty useless. You'll need to rebuild the source code, probably using the exact same compiler settings as you're using for your source own code.
(Obviously, your own code also has to build for arm64-v8a if it's going to load that .so. After all, the whole point of an ABI is to describe how one function calls another, so the arm64-v8a ABI describes how one arm64-v8a function calls another arm64-v8a function)

Prettify compiling C++ from Command Line [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 4 years ago.
Improve this question
I'm playing with compiling C++ from native Windows CMD via VS 2017 compiler (vsvarsall.bat setup).
Is there any way to reduce the output of cl command, like Microsoft rigths for compiler and linker?
Also, offtop question: is it possible to compile code with UNICODE or ANSI strings (like I'm able to build from Visual Studio IDE), or am I gotta use manual #defines?
For your first question, see the /nologo compiler flag.
I'd guess the second is why people are voting to close--there's quite a variety of ways to deal with ANSI/Unicode strings, and without quite a bit more definition of what you really want, chances are pretty poor that anybody can give a meaningful answer.

Programatically creating and compiling from a program in C++ [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 8 years ago.
Improve this question
Let's say we've got a first program called Program1.exe which contains the necessary information to create and compile another application called Program2.exe. Actually it could also load that information from a txt file or whatever.
Googling, I've found that this is "easy" to do in C#, using Visual Studio:
How to programatically build and compile another c# project from the current project
Programmatically Invoke the C# Compiler
The problem is that I'm not using (and can't use) C#, but C++. Summing it up, my question is if that I can do this same thing using C++.
I would prefer to do it without additional libraries, but if that's not possible, or if it's too hard to do, you can also recommend any library allowing it.
I think you'll probably have noticed it, but my goal is to use it under Windows so I don't care if it's not portable.
Thanks everybody.
It's trivial (if maybe a bit odd) for a C++ program to compile and run another based on code stored in a text file. Debugging that other program, however, isn't.

Compilation process for C++ application? [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 have been programming for 2 years now and always have faced difficulty when dealing with the compilation process.
I did not study Computer Science during my Engineering, but necessity drove me towards learning C++.
I tried understanding the compilation process from some blogs, but they were always in a language I could not understand.
So I searched this site for a similar question, but could find none.
So I would like to know how the text from a .cpp is converted to a binary executable?
Basically, the preprocessor runs first resolving all your #includes, #defines, etc with simple text substitution. Then the compiler creates a compilation-unit for each .cpp file which pretty much boils everything down to machine-code except for "connections" or linkages between shared data and functions. There may be many levels of optimisation for speed and/or space performed. This is repeated for all your .cpp files. Finally, a link phase ties all these compilation-units and the libraries they use together into an executable.

Building a compiler steps [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 have been thinking about building my own compiler for a while and a few days ago I finally started on it. My compiler works like this:
Parse code from my own file. (With a .exe file made with c++)
Create assembly code
Create a file containing those assembly code
Compile that assembly file if it is made (done with a vbs script)
Link the .obj file
And we have our .exe file
Now I am having difficulties with finding the best way to parse my code. I haven't really made this yet but I will put my ideas here.
Find all variables and declare them. variables will be preceded with a 'var ' (for now). uninitialized variables will be put in the .data? section and initialized ones in the .data section.
Find the main procedure and start executing the functions and operations.
Now I was simply wondering if someone can improve my ideas. Or if someone has a better idea to make some kind of compiler and your own programming language.
Get yourself a copy of A. V. Aho, M. S. Lam, R. Sethi, J. D. Ullman: Compilers: Principles, Techniques, and Tools and start studying
The book covers the necessary theoretical background, especially:
Context-free grammars
Recursive-descent, LL, LR parsing
Symbol handling
Intermediate representation