PoorGo is a subset implementation of Go that generates LLVM IR and compiles to native code using the LLVM toolchain.
- Poor and understandable implementation
- Efficient code generation using LLVM
- Suitable feature set for educational purposes
// All programs must follow this format
package main
func main() {
// Program entry point
}
int // 32-bit integer
string // String
bool // Boolean
// Type inference
x := 42
name := "hello"
flag := true
// Explicit type declaration
var x int = 42
var name string = "hello"
var flag bool = true
// Basic function
func add(x int, y int) int {
return x + y
}
// Function without return value
func printValue(x int) {
print(x)
}
// If statement
if x > 0 {
// positive
} else if x < 0 {
// negative
} else {
// zero
}
// For loops
for i := 0; i < 10; i++ {
// Counter loop
}
for condition {
// While loop equivalent
}
for {
// Infinite loop
}
// Arithmetic operators
+ // Addition
- // Subtraction
* // Multiplication
/ // Division
// Comparison operators
== // Equal to
!= // Not equal to
< // Less than
> // Greater than
<= // Less than or equal to
>= // Greater than or equal to
// Logical operators
&& // Logical AND
|| // Logical OR
! // Logical NOT
graph TD
A[Source Code] --> B[Lexical Analysis]
B --> C[Syntax Analysis]
C --> D[Semantic Analysis]
D --> E[LLVM IR Generation]
E --> F[LLVM Optimization]
F --> G[Executable]
-
Lexer
- Token generation
- Source position tracking
- Basic error detection
-
Parser
- AST construction
- Grammar validation
- Syntax error reporting
-
Semantic Analyzer
- Type checking
- Symbol resolution
- Semantic constraint validation
-
Code Generator
- LLVM IR generation
- Runtime function integration
- Optimization settings
print(value) // Output value to stdout
len(value) // Get string length
error(message) // Create an error
- Stack allocation preferred
- Using LLVM built-in memory management
- Compile-time error detection
- Runtime panic mechanism
- Package declaration
- Main function
- Print statement
- Basic LLVM IR generation
- Variable declarations
- Basic expressions
- Control structures
- Function definitions
- Type checking
- Type inference
- Built-in types
- Error types
- LLVM optimization passes
- Debug information
- Error recovery
[Phase] Error at line <line>, column <column>: <message>
Examples:
[Lexer] Error at line 1, column 5: Invalid character '#'
[Parser] Error at line 3, column 10: Expected '{' after function declaration
[Semantic] Error at line 5, column 15: Undefined variable 'x'
[CodeGen] Error: Failed to generate LLVM IR