Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
zestones committed Feb 10, 2025
1 parent 1b57c8e commit de6788b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 63 deletions.
106 changes: 49 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,15 @@
<img src="./extensions/custom-icons/icons/icon.png" alt="Argonaut">

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/zestones/argonaut/build.yml?branch=main)](https://github.com/zestones/argonaut/actions)
[![Build Status](https://img.shields.io/github/actions/workflow/status/zestones/Argonaut/build.yml?branch=main)](https://github.com/zestones/Argonaut/actions)
[![Dependencies](https://img.shields.io/badge/dependencies-GCC%2C%20Flex%2C%20Bison-orange)](https://gcc.gnu.org/)

<p>Argonaut is a procedural programming language designed for educational purposes, featuring a compiler and virtual machine implemented in C. This project aims to provide a comprehensive understanding of how compilers and interpreters function.
</p>
</div>

## 🚀 Key Features

### Compiler Architecture

- **Three-phase compilation process**
```mermaid
graph LR
subgraph "Compiler Pipeline"
direction LR
Frontend["Frontend (Lexer/Parser)"] --> Middleend["Middleend (Semantic Analysis)"]
Middleend --> Backend["Backend (Code Generation)"]
end
Frontend -.-> SymbolTable["Symbol Tables"]
Middleend -.-> TypeSystem["Type System"]
Backend -.-> IR["Intermediate Representation"]
IR --> VM["Virtual Machine Execution"]
```

- Modular design with clean separation between:
- Frontend (Lexer/Parser)
- Middleend (Semantic Analysis)
- Backend (Code Generation)

## 📜 Language Overview

### Sample Program
```js
PROG fibonacci;

func int fib(int n) {
if n <= 1 {
return n;
}
return fib(n-1) + fib(n-2);
}

VAR x: int = 10;

MAIN {
print("Fibonacci sequence:");
for var i = 0; i < x; i++ {
print(fib(i));
}
}
```
> [!IMPORTANT]
> Checkout **[wiki](#link)** documentation to understand how the Argonaut compiler and vm works.
## 🛠️ Getting Started

Expand All @@ -71,29 +27,65 @@ Before you begin, ensure you have the following installed:
### Installation

```bash
git clone https://github.com/zestones/argonaut.git
cd argonaut
git clone https://github.com/zestones/Argonaut.git
cd Argonaut

# Build compiler and VM
make
```

The executable files will be generated in the `bin` directory. ``argoc`` stand for Argonaut compiler and ``argov`` stand for Argonaut virtual machine.

## 🚀 Usage

- **Compiler:** Run ``./bin/argoc -a <source-file> -o <output-file>``. Use ./``./bin/argov --help`` for more options.
- **Virtual Machine:** Run ``./bin/argov –a <intermediate-file>``. Use ``./bin/argov –h`` for more options.

## 📜 Language Overview

Checkout the **[Argonaut Language Guide](#link)** documentation to write your own programs in Argonaut.

### Sample Program

```js
func fibonacci(num : int) -> int {
if (num <= 1) {
return num;
}

return fibonacci(num - 1) + fibonacci(num - 2);
}

proc main() {
var num : int;
print("Enter a number: ");
input("%d", num);

print("fibonacci(%d) = %d\n", num, fibonacci(num));
}

main();
```

> [!NOTE]
> Example programs are provided in the `examples/interpretation` directory.
## 📂 Project Structure

```bash
.
├── bin/ # Compiled binaries
├── docs/ # Generated documentation
├── examples/ # Sample programs
│ ├── hello.ag # Basic example
│ └── algorithms/ # Complex programs
│ ├── hello.arn # Basic example
│ └── algorithms/ # Complex programs
├── include/ # Header files
├── lib/ # Utility libraries
├── src/ # Core implementation
│ ├── frontend/ # Lexer/Parser
│ ├── middleend/ # Semantic analysis
│ └── backend/ # Code generation
└── tests/ # Test suite
│ ├── frontend/ # Lexer/Parser
│ ├── middleend/ # Semantic analysis
│ └── backend/ # Code generation
└── tests/ # Regression tests
```

## 🤝 Contributing
Expand All @@ -118,7 +110,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

<div align="center">
<p>Made with ❤️ by the Argonaut Contributors</p>
<a href="https://github.com/zestones/argonaut/graphs/contributors">
<img src="https://contrib.rocks/image?repo=zestones/argonaut" />
<a href="https://github.com/zestones/Argonaut/graphs/contributors">
<img src="https://contrib.rocks/image?repo=zestones/Argonaut" />
</a>
</div>
Binary file modified bin/argov
Binary file not shown.
17 changes: 17 additions & 0 deletions example/interpretation/fibonacci.arn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
func fibonacci(num : int) -> int {
if (num <= 1) {
return num;
}

return fibonacci(num - 1) + fibonacci(num - 2);
}

proc main() {
var num : int;
print("Enter a number: ");
input("%d", num);

print("fibonacci(%d) = %d\n", num, fibonacci(num));
}

main();
12 changes: 6 additions & 6 deletions src/parser/interpreter_grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,21 @@ static void print_usage(const char *program_name) {

// Arguments section (merged short and long options)
fprintf(stdout, COLOR_BOLD_YELLOW "Arguments:\n" COLOR_RESET);
fprintf(stdout, COLOR_GREEN " -i <file> " COLOR_RESET ": The input file to be interpreted (required).\n");
fprintf(stdout, COLOR_GREEN " -a <file> " COLOR_RESET ": The input file to be interpreted (required).\n");
fprintf(stdout, COLOR_GREEN " -v, --verbose " COLOR_RESET ": Enable verbose mode (display symbol tables, AST and execution Stack).\n");
fprintf(stdout, COLOR_GREEN " -h, --help " COLOR_RESET ": Show this help message and exit.\n");

// Examples section
fprintf(stdout, "\n" COLOR_BOLD_YELLOW "Examples:\n" COLOR_RESET);
fprintf(stdout, COLOR_CYAN " %s -i my_program.arg -v\n" COLOR_RESET, program_name);
fprintf(stdout, COLOR_CYAN " %s -a my_program.arg -v\n" COLOR_RESET, program_name);
fprintf(stdout, " - Interprets 'my_program.arg' with verbose output (symbol tables, AST, execution Stack, etc.).\n\n");

fprintf(stdout, COLOR_CYAN " %s -i my_program.arg --verbose\n" COLOR_RESET, program_name);
fprintf(stdout, COLOR_CYAN " %s -a my_program.arg --verbose\n" COLOR_RESET, program_name);
fprintf(stdout, " - Long option equivalent of the above example.\n\n");

// Constraints section
fprintf(stdout, COLOR_BOLD_YELLOW "Constraints:\n" COLOR_RESET);
fprintf(stdout, COLOR_RED " - The input file must be specified with the '-i <file>' option.\n");
fprintf(stdout, COLOR_RED " - The input file must be specified with the '-a <file>' option.\n");
fprintf(stdout, COLOR_RED " - If no file is specified, the program will terminate with an error.\n\n");

exit(EXIT_SUCCESS);
Expand All @@ -200,9 +200,9 @@ int main(int argc, char **argv) {
};

// Parse command-line options
while ((opt = getopt_long(argc, argv, "i:vh", long_options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "a:vh", long_options, NULL)) != -1) {
switch (opt) {
case 'i':
case 'a':
input_file = optarg; // Capture the file argument
break;
case 'v':
Expand Down

0 comments on commit de6788b

Please sign in to comment.