repo/
│
├── asm-ref/
│ ├── print.s # Assembly reference for printing
│ └── exit.s # Assembly reference for exiting
│
├── src/
│ └── compiler.c # The complete GoneLang compiler implementation
│
└── example/
└── main.gl # Example GoneLang program
GoneLang is a minimal experimental language with the file extension .gl. This compiler is written in C and translates GoneLang code into Linux x86-64 assembly. The compiler then assembles and links the program into an executable that runs and exits with a given status code.
Currently, GoneLang supports only one statement:
exit <int>;→ exit the program with the specified integer code.
Example:
exit 5;
This program exits with code 5.
GoneLang programs are broken into tokens. Currently, only one token type exists:
_EXIT→ Represents theexitstatement.
enum TokenType{
_EXIT = 1
};
struct TOKEN{
enum TokenType type;
int value;
};The tokenise function scans the source code from example/main.gl, identifies keywords, and extracts integer values.
Supported syntax:
exit <integer>;
If an unknown keyword or incorrect syntax is found, the compiler raises an error.
The codegen function maps tokens to assembly instructions. For the _EXIT token, it generates Linux x86-64 system call assembly:
.global _start
_start:
mov $<value>, %rdi # exit code
mov $60, %rax # syscall: exit
syscallThis assembly is written into output.s.
The compiler automatically:
-
Assembles the assembly file into an object file:
as -64 output.s -o output.o
-
Links the object file into an executable:
ld output.o -o output
-
Runs the executable and prints the exit status:
./output Program exited with code: <value>
-
Write a GoneLang program inside
example/main.gl. Example:exit 7; -
Compile and run the compiler:
gcc src/compiler.c -o gonelang ./gonelang
-
Output:
Token: EXIT, Value: 7 Program exited with code: 7
- Only supports
exit <int>;andprint("{your text}")orprintnfor newline - No variables, expressions, or multiple statements.
- Error handling is basic.
- Add support for arithmetic expressions.
- Implement variables and assignments.
- Expand grammar beyond
exit. - Improve lexer (tokeniser) and parser for robustness.
GoneLang is an experimental language project to learn about lexing, parsing, code generation, and system calls in Linux x86-64.
├── Makefile # Build configuration
├── README.md # This file
├── asm-ref/ # Reference assembly files
│ ├── exit.s
│ └── print.s
├── build/ # Build artifacts (auto-generated)
├── example/ # Example programs
│ └── main.gl
├── include/ # Header files
│ └── compiler.h
└── src/ # Source files
└── compiler.c # Main compiler implementation
To build the compiler:
makeThis will create the compiler executable in the project root.
./compiler example/main.gl- Basic print statement
- Exit statement
- Split code into logical modules (lexer/parser/codegen)
- Add proper error handling
- Implement symbol table
- Add more language features
[Add your license here]
- The current implementation keeps all functionality in
compiler.cas per the requirement to not change the original code.