https://github.com/milesbarr/plx
A programming language compiler written in C.
https://github.com/milesbarr/plx
c c-lang c-language compiler compiler-construction compiler-design compilers programming-language programming-language-development programming-languages
Last synced: 12 months ago
JSON representation
A programming language compiler written in C.
- Host: GitHub
- URL: https://github.com/milesbarr/plx
- Owner: milesbarr
- License: apache-2.0
- Created: 2024-04-24T14:46:25.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-15T14:16:55.000Z (almost 2 years ago)
- Last Synced: 2025-03-30T05:15:29.928Z (12 months ago)
- Topics: c, c-lang, c-language, compiler, compiler-construction, compiler-design, compilers, programming-language, programming-language-development, programming-languages
- Language: C
- Homepage:
- Size: 82 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Programming Language X
Programming Language X is a compiler written in C.
## Current State
The compiler implements parsing, name resolution, type checking, and code generation for a limited number of programming language features and includes two backends: [LLVM IR](https://llvm.org/docs/LangRef.html) and [WebAssembly](https://webassembly.org/).
## Building
In order to build the compiler from source, [CMake](https://cmake.org/) and a C compiler such as [Clang](https://clang.llvm.org/) or [GCC](https://gcc.gnu.org/) is required. First, ensure these dependencies are installed on your system. Next, clone this repository and open a shell in the directory. Lastly, build the compiler by running the following commands:
```bash
mkdir build
cd build
cmake ..
cmake --build .
```
## Syntax
### Definitions
Define a constant.
```go
const foo = 1;
```
Define a variable.
```go
var foo = 1;
```
Declare a variable.
```go
var foo: s32;
```
Define a function.
```go
func foo(bar: s32) -> s32 {
return bar;
}
```
### Types
Integer types:
```go
s8
s16
s32
s64
u8
u16
u32
u64
```
Floating point types:
```go
f32
f64
```
Boolean type:
```go
bool
```
Function types:
```go
func (s32) -> s32
```
Array types:
```go
[8]s32
```
Slice types:
```go
[]s32
```
## Examples
Add two integers.
```go
func add(a: s32, b: s32) -> s32 {
return a + b;
}
```
Fibonacci sequence.
```go
func fib(n: s32) -> s32 {
if n == 0 {
return 0;
} else if n == 1 or n == 2 {
return 1;
} else {
return fib(n - 1) + fib(n - 2);
}
}
```