Jump to content

Hey guys

I made a compiler for my university assignment. I uses basics rules of parsing and stuff. Here is the Git of my compiler: https://github.com/DragoTechInnovations/PHP-to-ASM-Compiler

 

This compiler is made in PHP and converts my created language to Assembly Language, so yeah its basically an assembler.

Those who want to play around with is fork it, clone it, etc.

 

These are the usage and limitations:

 

Usage:

  • compile -h or compile --help
  • compile -i e.g: compile -i helloworld.dl * output is an ASM file with timestamp

Syntax:

  • variables are initialized as the following: int: a, b, c"
  • Only int is supported now 
  • A statement should end with a ", even comments
  • Comments are only single line, starting from ' 
  • variables are required to be initialized
  • only +, -, /, * operators are allowed 
  • = is used to assign variables 
  • floats and decimals are not allowed

 

NB: I made this in less then 2 hours so yeah its not so high-end, plus not an assembly guy.

 

Regards

Link to comment
https://linustechtips.com/topic/524632-compiler-construction/
Share on other sites

Link to post
Share on other sites

I made a brainfuck compiler(?) which translates the source code into assembly , so welcome to the club.

I did mine in C++ btw.

 

Also , interpreters are a lot easier to make.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
https://linustechtips.com/topic/524632-compiler-construction/#findComment-6964061
Share on other sites

Link to post
Share on other sites

I made a brainfuck compiler(?) which translates the source code into assembly , so welcome to the club.

I did mine in C++ btw.

 

Also , interpreters are a lot easier to make.

 

Yeah but PHP is my domain. :)

Do share the code if you want. Though i wont understand most of it. Dont understand C++

Link to comment
https://linustechtips.com/topic/524632-compiler-construction/#findComment-6964420
Share on other sites

Link to post
Share on other sites

You can add a little bit of code to invoke the system's assembler and probably linker for the user so it can be more convenient. Also it would be nice to follow GCC's flags convention.

You can also split off boilerplate and library code into a separate standard library, written probably part in this language and part in C or C++, for your language that is linked when building the code. This will make the compiler more streamline.

Last you may want to have a look at LLVM as they have a very well established optimization algorithm so you just need to emit either LLVM IL or even just AST and let them handle the optimization, assembler generation and even maybe assembly and linking for you.

The Fruit Pie: Core i7-9700K ~ 2x Team Force Vulkan 16GB DDR4-3200 ~ Gigabyte Z390 UD ~ XFX RX 480 Reference 8GB ~ WD Black NVMe 1TB ~ WD Black 2TB ~ macOS Monterey amd64

The Warship: Core i7-10700K ~ 2x G.Skill 16GB DDR4-3200 ~ Asus ROG Strix Z490-G Gaming Wi-Fi ~ PNY RTX 3060 12GB LHR ~ Samsung PM981 1.92TB ~ Windows 11 Education amd64
The ThreadStripper: 2x Xeon E5-2696v2 ~ 8x Kingston KVR 16GB DDR3-1600 Registered ECC ~ Asus Z9PE-D16 ~ Sapphire RX 480 Reference 8GB ~ WD Black NVMe 1TB ~ Ubuntu Linux 20.04 amd64

The Question Mark? Core i9-11900K ~ 2x Corsair Vengence 16GB DDR4-3000 @ DDR4-2933 ~ MSI Z590-A Pro ~ Sapphire Nitro RX 580 8GB ~ Samsung PM981A 960GB ~ Windows 11 Education amd64
Home server: Xeon E3-1231v3 ~ 2x Samsung 8GB DDR3-1600 Unbuffered ECC ~ Asus P9D-M ~ nVidia Tesla K20X 6GB ~ Broadcom MegaRAID 9271-8iCC ~ Gigabyte 480GB SATA SSD ~ 8x Mixed HDD 2TB ~ 16x Mixed HDD 3TB ~ Proxmox VE amd64

Laptop 1: Dell Latitude 3500 ~ Core i7-8565U ~ NVS 130 ~ 2x Samsung 16GB DDR4-2400 SO-DIMM ~ Samsung 960 Pro 512GB ~ Samsung 850 Evo 1TB ~ Windows 11 Education amd64
Laptop 2: Apple MacBookPro9.2 ~ Core i5-3210M ~ 2x Samsung 8GB DDR3L-1600 SO-DIMM ~ Intel SSD 520 Series 480GB ~ macOS Catalina amd64

Link to comment
https://linustechtips.com/topic/524632-compiler-construction/#findComment-6965628
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×