Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kariaro/ampleprogramminglanguage
Creating a compiler for my own programming language
https://github.com/kariaro/ampleprogramminglanguage
compiler lexical-analysis programming-language
Last synced: 24 days ago
JSON representation
Creating a compiler for my own programming language
- Host: GitHub
- URL: https://github.com/kariaro/ampleprogramminglanguage
- Owner: Kariaro
- License: mit
- Created: 2020-07-24T15:49:12.000Z (over 4 years ago)
- Default Branch: develop
- Last Pushed: 2022-10-24T18:36:59.000Z (about 2 years ago)
- Last Synced: 2023-06-17T22:36:04.211Z (over 1 year ago)
- Topics: compiler, lexical-analysis, programming-language
- Language: Java
- Homepage:
- Size: 1.78 MB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ample Programming Language
The main idea of this compiler is to play around with lexers, optimizations and solving problems that comes with large
projects.The programming language is still under construction and is not be suitable for any real uses outside of exporting to
interesting instruction sets.## Exporting
The compiler currently exports to four different languages:
* Ir **Compiler instructions*
* Spooky **Not stable*
* Assembly x64
* Chockintosh I## Usage
> The compiler cli has not been tested
```
Usage: [options]options:
--format-list displays a list of available output formats--project, -p compile the project from an xml file
--target, -t set the target output of the compiler
--format, -f set the format of the compiler
--use-cache change how the compiler deals with cache files
-i specify the input file to compile
-o specify the output folder
```## Compiler
Here is an example of the language syntax:
```c
func printhex (i64: number) {
u8[]: hex_data = stack_alloc("0123456789abcdef");
u8[]: hex_strs = stack_alloc("................\n");for (i32: i = 15; i >= 0; i = i - 1) {
hex_strs[i] = hex_data[number & cast(15)];
number = number >> cast(4);
continue;
}printstr(hex_strs, 17L);
ret;
}
```## Lexer
The lexer is located in the directory `src/main/java/me/hardcoded/lexer`
The compiler lexer is used to take combine a list of characters into bigger groups. One example of a group is numbers
which could be combined using the simple regex `[1-9][0-9]+`All tokens returned by the lexer contains information about where the token started and ended, file location, content
and group information.Here is an example of what the lexer does.
```
Input: "char hello ='a'"Output:
List = [
{ type: TYPE, value: "char" , index: 0 },
{ type: SPACE, value: " ", index: 4 },
{ type: NAME, value: "hello", index: 5 },
{ type: SPACE, value: " ", index: 10 },
{ type: EQUALS, value: "=", index: 11 },
{ type: STRING, value: "'a'", index: 12 }
];
```## Visualization
The visualization classes are located inside the directory `src/main/java/me/hardcoded/visualization`
Visualizations are used to debug how the compiler works and can help a developer identify errors made by the compiler
and make it easier to fix them.Currently, there exists three visualization.
* Source Code Viewer
* Parse Tree Viewer
* Instruction Viewer