Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,156,018 members, 7,828,587 topics. Date: Wednesday, 15 May 2024 at 11:44 AM

Compiler Construction/ Building A Programming Language - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Compiler Construction/ Building A Programming Language (953 Views)

What Was Used To Compile The Code That Was Used In Creating A Compiler? / HTML5 A Programming Language Or Not / Where Can I Download Free Fortran Compiler (2) (3) (4)

(1) (Reply)

Compiler Construction/ Building A Programming Language by Nobody: 3:54pm On Aug 24, 2019
How would you like to build your own programming Language. It sounds strange and impossible but it is the reason why we have high level languages today okay let me get down to history.
Computers are very old as we all know they date back as far as the 1600s (if possible farther) though computers of today are children of Charles Babbage's inventions. The first generation of computers the mainframes made use of 1's and 0's for doing operations it was annoying slow and errors always occurred making debugging(finding and solving errors) near to impossible until a woman known as Kathleen Booth made the assembly language which used an Assembler to turn this assembly code to machine code. This was a breakthrough and the geeks all over the world celebrated this new finding because it was much easier to learn and debug. It was much more human friendlier than 1's and 0's but still was hard to learn and debug and could be a billion lines long well not a billion actually.

Then at last FORTRAN entered the scene became a gem in its time it used a Compiler to turn it's code to assembly.
Then BASIC came some time later followed by C sometime after, these languages where much easier to learn, could do many things like make decisions, do loops and so many other things but they still had problems. Reusing code was near to impossible and it was so disarranged too. Then at last a dynamic breakthrough at Bell Labs was born C++ by Bjarne Stroustrup. It made code structures simpler and it encouraged object oriented programming(that is modelling objects with code) plus code reusability at last came into play, Java, Python and C# followed later and some others too.

Now these languages apart from Assembly uses either an interpreter or a compiler. An interpreter takes code and turns it into source code immediately that is it executes it immediately. A compiler on the other hand takes code checks it if it to understand what it is saying then turns it into its target code(usually Assembly).
I am going to give you a start on how to create a compiler. Note: languages like Javascript and VBscript are not compiled or interpreted.

1. If you want to create a Compiler you have to know two languages and at least be on the intermediate level in one. It is better you know Assembly or C so that your language will be fast.

2. You have to be a stubborn bastard because it is annoying I am currently making one and sometimes I just get so confused.

3. You have to check tutorials on YouTube. Quick advice don't buy any book on compiler construction they are boring as hell.

4. And lastly preferably get a team. I would like a team to help me so if you are interested in joining my near impossible quest hit me up 07058681642. You could do it yourself though but it is a rocky road.

Okay let's get down to the process of compiler construction.
1. Lexical Analysis..
The compiler goes through the code and checks if everything is named correctly for example. An identifier like 'letter' '_letter' 'letter1' is named correctly in C# but '1letter' '=letter' 'let+ter' are not allowed which draws us to the rule of identifiers- [letter | _|[letter|_|digit]*] which means we either have a letter first or an underscore first then optionally we can have letters underscores and digits following the first letter or underscore. Then digits we must have from 0-9 with occasions like f's as suffices for floats and b's or x's for binary and hexadecimal (advanced stuff but you can work it out).

2. Syntactic Analysis...
The compiler then goes through the code and checks if we put things correctly in their order like for example. int i=5; and 5 int=*; the first one is valid and accepted at this stage but the other no then while doing this it creates a tree like structure which are like commands by making an intermediate code that is more explanatory than the source.

3. Intermediate Optimisation...
Here the compiler makes our code easier it removes all those things which makes it so large like commas and brackets and the rest and if possible makes it more explanatory this section is optional.

4. Code Generator...
At last the compiler turns our explanatory code into our target code that is it changes that explanatory code to the target that is the code you want to turn it into that is C or C++ or C#(C# or Java your language will be slow) or Assembly or even Machine Code (you must be a geek god) and at last that ends it.
There are so many blogs and posts online about this case of compiler construction go and check when you are free and in case you want to help out with my compiler project - Argon. You could hit me up my number again is 07058681642. Hope I helped you on your road to greatness. Bye.

(1) (Reply)

Ai’s Breakthrough Year In Cyber Security : Video / Common Challenges To Devops And How To Resolve Them / Full Stack Developer Needed! Paid, Remote

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.