├── .dockerignore ├── .github ├── linters │ ├── .htmlhintrc │ ├── codespell.txt │ ├── .hadolint.yaml │ ├── .yaml-lint.yml │ ├── mlc_config.json │ └── .markdown-lint.yml ├── ISSUE_TEMPLATE │ ├── custom.md │ ├── feature_request.md │ ├── bug_report.md │ ├── join_doc_team.md │ ├── join_web_team.md │ └── join_core_team.md ├── dependabot.yml ├── FUNDING.yml ├── workflows │ ├── labeler.yml │ ├── first-interaction.yml │ ├── super-linter.yml │ ├── docker-image.yml │ ├── lint.yml │ └── codeql-analysis.yml └── labeler.yml ├── tmp ├── c-new │ ├── src │ │ ├── parser.test.c │ │ ├── one.h │ │ ├── file.h │ │ ├── array.h │ │ ├── compile.h │ │ ├── vm.h │ │ ├── tree.h │ │ ├── lexer.h │ │ ├── arg.h │ │ ├── one.c │ │ ├── file.c │ │ ├── array.c │ │ ├── error.h │ │ ├── vm.c │ │ ├── lexer.test.c │ │ ├── error.c │ │ ├── parser.h │ │ ├── compile.c │ │ ├── arg.c │ │ ├── tree.c │ │ ├── ast.h │ │ └── lexer.c │ ├── unit-tests │ │ ├── ast.test.c │ │ ├── parser.test.c │ │ └── lexer.test.c │ ├── tests │ │ ├── 46-tiny-hello.et │ │ ├── 47-tiny-hello.et │ │ ├── 49-tiny-hello.et │ │ ├── 53-hello.et │ │ ├── 12-hello-world-tiny.et │ │ ├── activity_error.etl │ │ ├── activity_index.etl │ │ ├── activity_login.etl │ │ ├── 51-hello.et │ │ ├── 50-hello.et │ │ ├── 2-main-return.et │ │ ├── 48-hello.et │ │ ├── 52-hello.et │ │ ├── 6-exit-code.et │ │ ├── 37-math-tan.et │ │ ├── 39-main-function-without-type.et │ │ ├── 1-hello-world.et │ │ ├── 54-variable-define.et │ │ ├── 45-exit-with-default-code.et │ │ ├── 35-math-sin.et │ │ ├── 44-math-cot.et │ │ ├── 55-variable-define.et │ │ ├── 43-architecture-sample.et │ │ ├── 40-architecture-sample.png │ │ ├── 41-architecture-sample.png │ │ ├── 42-architecture-sample.png │ │ ├── 5-comment.et │ │ ├── 59-function-define-call-print.et │ │ ├── 8-file-delete.et │ │ ├── 13-inline-assembly-exit-i386.et │ │ ├── 14-inline-assembly-exit-x86_64.et │ │ ├── 60-function-define-with-type.et │ │ ├── 58-function-call-print.et │ │ ├── 10-file-copy.et │ │ ├── 17-operator-test.et │ │ ├── 36-math-cos.et │ │ ├── 62-get-input-value.et │ │ ├── 11-file-set.et │ │ ├── 15-expression-test.et │ │ ├── 9-file-rename.et │ │ ├── activity_error.et │ │ ├── activity_index.et │ │ ├── activity_login.et │ │ ├── 3-function-define.et │ │ ├── 38-string-upper.et │ │ ├── 18-operator-test.et │ │ ├── 63-array-string.et │ │ ├── 22-loop-repeat.et │ │ ├── 23-loop-while.et │ │ ├── 65-array-char.et │ │ ├── 56-function-call-return.et │ │ ├── 21-loop-for.et │ │ ├── 66-array-char.et │ │ ├── 7-file-create.et │ │ ├── 61-get-input-value.et │ │ ├── 67-operator.et │ │ ├── 24-if-else.et │ │ ├── 25-if-else-odd-even.et │ │ ├── 64-array-char.et │ │ ├── 26-loop-count-number.et │ │ ├── 19-factorial.et │ │ ├── 40-architecture-sample.et │ │ ├── 57-function-call-return.et │ │ ├── 20-factorial-loop.et │ │ ├── 33-web-cgi.et │ │ ├── 28-if-else-which-largest.et │ │ ├── 27-if-which-largest.et │ │ ├── 41-architecture-sample.et │ │ ├── 32-web-architecture.et │ │ ├── 42-architecture-sample.et │ │ ├── 16-operator-test.et │ │ ├── 34-architecture.et │ │ ├── 31-sort-char.et │ │ ├── 29-sort-bubble.et │ │ ├── 30-sort-shell.et │ │ └── 4-print.et │ ├── CMakeLists.txt │ └── input.one ├── js │ ├── src │ │ ├── generator │ │ │ ├── types.js │ │ │ ├── commands │ │ │ │ ├── expression.js │ │ │ │ ├── if.js │ │ │ │ ├── for.js │ │ │ │ ├── print.js │ │ │ │ ├── while.js │ │ │ │ ├── function.js │ │ │ │ └── variable-define.js │ │ │ ├── temp.js │ │ │ ├── statements.js │ │ │ ├── statement.js │ │ │ ├── vm.js │ │ │ └── index.js │ │ ├── one.js │ │ ├── cli │ │ │ ├── io │ │ │ │ ├── index.js │ │ │ │ └── file.js │ │ │ ├── commands │ │ │ │ ├── version.js │ │ │ │ ├── run.js │ │ │ │ └── help.js │ │ │ └── index.js │ │ └── scanner │ │ │ └── parser.js │ ├── input.c │ ├── input.ast │ └── package.json ├── c │ ├── input.one │ └── src │ │ ├── scanner.c │ │ ├── scanner.h │ │ ├── arg.h │ │ ├── parser.h │ │ ├── one.h │ │ ├── lexer.h │ │ ├── arg.c │ │ ├── token.h │ │ ├── one.c │ │ ├── sdsalloc.h │ │ ├── lexer.c │ │ ├── vec.h │ │ └── vec.c ├── c-new2 │ ├── value.c │ ├── repl.h │ ├── file.h │ ├── one.h │ ├── interpret.h │ ├── array.h │ ├── repl.c │ ├── one.c │ ├── value.h │ ├── lexer.h │ ├── argument.h │ ├── array.c │ ├── file.c │ ├── interpret.c │ ├── generator.h │ ├── error.c │ ├── tree.h │ ├── parser.h │ └── error.h └── c-old │ ├── src │ ├── io.h │ ├── lexer │ │ ├── lexer.h │ │ ├── token.c │ │ ├── source.c │ │ ├── token.h │ │ ├── source.h │ │ ├── lexer.c │ │ └── tokens.h │ ├── io.c │ ├── one.h │ ├── buffer │ │ ├── sdsalloc.h │ │ └── testhelp.h │ └── one.c │ └── Makefile ├── .hound.yml ├── example ├── main.one ├── variable.one ├── hello.one ├── for-forever.one ├── hello-io.one ├── if.one └── for-c.one ├── CODEOWNERS ├── src ├── one.exe ├── parser │ ├── lexer │ │ ├── test.sh │ │ ├── build.sh │ │ ├── lexer.h │ │ └── main.c │ ├── build.sh │ ├── main.c │ └── parser_token.h ├── ast │ ├── build.sh │ ├── main.c │ └── ast-structure.txt ├── input.one └── builtins │ ├── string.h │ ├── array.h │ ├── file.h │ ├── array.c │ ├── error.c │ ├── string.c │ └── file.c ├── docker-compose.yml ├── .mergify.yml ├── Makefile ├── scripts └── ci │ └── pre-commit │ └── sort-and-uniquify-codespell-wordlist.sh ├── test ├── ast.test.c ├── parser.test.c ├── argument.test.c ├── file.c ├── build.sh └── test.h ├── .editorconfig ├── .gitignore ├── input.one ├── .gitattributes ├── Dockerfile ├── .clang-format └── CONTRIBUTORS.md /.dockerignore: -------------------------------------------------------------------------------- 1 | /.github 2 | -------------------------------------------------------------------------------- /.github/linters/.htmlhintrc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/c-new/src/parser.test.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/c-new/unit-tests/ast.test.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/js/src/generator/types.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/c-new/unit-tests/parser.test.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/linters/codespell.txt: -------------------------------------------------------------------------------- 1 | fo 2 | hel 3 | -------------------------------------------------------------------------------- /.hound.yml: -------------------------------------------------------------------------------- 1 | shellcheck: 2 | enabled: true 3 | -------------------------------------------------------------------------------- /example/main.one: -------------------------------------------------------------------------------- 1 | fn main { 2 | ret 1 3 | } 4 | -------------------------------------------------------------------------------- /tmp/c-new/tests/46-tiny-hello.et: -------------------------------------------------------------------------------- 1 | "Hello World!"; 2 | -------------------------------------------------------------------------------- /tmp/c-new/tests/47-tiny-hello.et: -------------------------------------------------------------------------------- 1 | _ "Hello World!"; 2 | -------------------------------------------------------------------------------- /tmp/c-new/tests/49-tiny-hello.et: -------------------------------------------------------------------------------- 1 | print "Hello World!"; 2 | -------------------------------------------------------------------------------- /tmp/c-new/tests/53-hello.et: -------------------------------------------------------------------------------- 1 | "Hello"; 2 | " World!"; 3 | -------------------------------------------------------------------------------- /tmp/js/input.c: -------------------------------------------------------------------------------- 1 | int32 main() 2 | { 3 | a = 4; 4 | } 5 | -------------------------------------------------------------------------------- /.github/linters/.hadolint.yaml: -------------------------------------------------------------------------------- 1 | failure-threshold: "error" 2 | -------------------------------------------------------------------------------- /tmp/c-new/tests/12-hello-world-tiny.et: -------------------------------------------------------------------------------- 1 | _ "Hello World!"; 2 | -------------------------------------------------------------------------------- /tmp/c-new/tests/activity_error.etl: -------------------------------------------------------------------------------- 1 | label 2 | { 3 | 4 | } 5 | -------------------------------------------------------------------------------- /tmp/c-new/tests/activity_index.etl: -------------------------------------------------------------------------------- 1 | label 2 | { 3 | 4 | } 5 | -------------------------------------------------------------------------------- /tmp/c-new/tests/activity_login.etl: -------------------------------------------------------------------------------- 1 | label 2 | { 3 | 4 | } 5 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @BaseMax @jbampton 2 | *.md @BaseMax @jbampton 3 | -------------------------------------------------------------------------------- /tmp/c-new/tests/51-hello.et: -------------------------------------------------------------------------------- 1 | main { 2 | "Hello World!"; 3 | } 4 | -------------------------------------------------------------------------------- /tmp/c-new/tests/50-hello.et: -------------------------------------------------------------------------------- 1 | main { 2 | _ "Hello World!"; 3 | } 4 | -------------------------------------------------------------------------------- /example/variable.one: -------------------------------------------------------------------------------- 1 | fn main { 2 | age := 34 3 | name := "YOU" 4 | } 5 | -------------------------------------------------------------------------------- /src/one.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/One-Language/One/HEAD/src/one.exe -------------------------------------------------------------------------------- /tmp/c-new/tests/2-main-return.et: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | return 1; 4 | } 5 | -------------------------------------------------------------------------------- /tmp/c-new/tests/48-hello.et: -------------------------------------------------------------------------------- 1 | int main() { 2 | _ "Hello World!"; 3 | } 4 | -------------------------------------------------------------------------------- /tmp/c-new/tests/52-hello.et: -------------------------------------------------------------------------------- 1 | "Hello"; 2 | main { 3 | " World!"; 4 | } 5 | -------------------------------------------------------------------------------- /tmp/c-new/tests/6-exit-code.et: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | return 10; 4 | } 5 | -------------------------------------------------------------------------------- /tmp/c-new/tests/37-math-tan.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | _ math.tan(0); 4 | } 5 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | one: 5 | build: . 6 | -------------------------------------------------------------------------------- /example/hello.one: -------------------------------------------------------------------------------- 1 | fn main { 2 | _ "Hello, World!\n" 3 | __ "Hello, World!" 4 | } 5 | -------------------------------------------------------------------------------- /tmp/c-new/tests/39-main-function-without-type.et: -------------------------------------------------------------------------------- 1 | main() 2 | { 3 | return 5; 4 | } 5 | -------------------------------------------------------------------------------- /tmp/js/src/one.js: -------------------------------------------------------------------------------- 1 | const { main } = require('./cli/'); 2 | 3 | main(process.argv); 4 | -------------------------------------------------------------------------------- /tmp/c-new/tests/1-hello-world.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | print "Hello World!"; 4 | } 5 | -------------------------------------------------------------------------------- /tmp/c-new/tests/54-variable-define.et: -------------------------------------------------------------------------------- 1 | //auto detect type! 2 | //$age=59; 3 | auto age=59; 4 | -------------------------------------------------------------------------------- /example/for-forever.one: -------------------------------------------------------------------------------- 1 | fn main int { 2 | for { 3 | _ "Repeat...\n" 4 | } 5 | ret 1 6 | } 7 | -------------------------------------------------------------------------------- /example/hello-io.one: -------------------------------------------------------------------------------- 1 | import io 2 | 3 | fn main { 4 | // io.print("Hello, World!\n") 5 | } 6 | -------------------------------------------------------------------------------- /tmp/c-new/tests/45-exit-with-default-code.et: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | return exit.success; 4 | } 5 | -------------------------------------------------------------------------------- /tmp/c-new/tests/35-math-sin.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | _ math.sin(90); 4 | print math.sin(180); 5 | } 6 | -------------------------------------------------------------------------------- /tmp/c-new/tests/44-math-cot.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | _ math.cot(90); 4 | print math.cot(180); 5 | } 6 | -------------------------------------------------------------------------------- /example/if.one: -------------------------------------------------------------------------------- 1 | fn main { 2 | if 5 > 3 { 3 | _ "yes" 4 | } else { 5 | _ "no" 6 | } 7 | ret 1 8 | } 9 | -------------------------------------------------------------------------------- /tmp/c-new/tests/55-variable-define.et: -------------------------------------------------------------------------------- 1 | main { 2 | //auto detect type! 3 | //$age=59; 4 | auto age=59; 5 | } 6 | -------------------------------------------------------------------------------- /src/parser/lexer/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | clear 4 | bash build.sh 5 | ./lexer ../input.one log 6 | cat log 7 | -------------------------------------------------------------------------------- /tmp/c-new/tests/43-architecture-sample.et: -------------------------------------------------------------------------------- 1 | title "Test"; 2 | author "Max"; 3 | 4 | h1 { 5 | _ "Hello,World!"; 6 | } 7 | -------------------------------------------------------------------------------- /example/for-c.one: -------------------------------------------------------------------------------- 1 | fn main { 2 | for i := 0; i < 10; i++ { 3 | if i == 7 { 4 | continue 5 | } 6 | __ i 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/parser/lexer/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | gcc lexer.c token.c main.c -I..\..\ ..\../builtins/*.c -D_ONE_TEST_ -o lexer 4 | -------------------------------------------------------------------------------- /tmp/c-new/tests/40-architecture-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/One-Language/One/HEAD/tmp/c-new/tests/40-architecture-sample.png -------------------------------------------------------------------------------- /tmp/c-new/tests/41-architecture-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/One-Language/One/HEAD/tmp/c-new/tests/41-architecture-sample.png -------------------------------------------------------------------------------- /tmp/c-new/tests/42-architecture-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/One-Language/One/HEAD/tmp/c-new/tests/42-architecture-sample.png -------------------------------------------------------------------------------- /tmp/c-new/tests/5-comment.et: -------------------------------------------------------------------------------- 1 | //this is a comment 2 | /* 3 | * this is a multi line comment 4 | */ 5 | /* Test */ 6 | void main(){} 7 | -------------------------------------------------------------------------------- /tmp/c-new/tests/59-function-define-call-print.et: -------------------------------------------------------------------------------- 1 | test(value) { 2 | return value * 10; 3 | } 4 | main { 5 | _ test(); 6 | } 7 | -------------------------------------------------------------------------------- /tmp/c-new/tests/8-file-delete.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | file.delete("sample.txt"); 4 | int result=file.delete("sample.txt"); 5 | } 6 | -------------------------------------------------------------------------------- /tmp/c-new/tests/13-inline-assembly-exit-i386.et: -------------------------------------------------------------------------------- 1 | //i386 2 | void main() 3 | { 4 | //32bit 5 | assembly("int $0x80"::"a"(1),"b"(0)); 6 | } 7 | -------------------------------------------------------------------------------- /tmp/c-new/tests/14-inline-assembly-exit-x86_64.et: -------------------------------------------------------------------------------- 1 | //x86_64 2 | void main() 3 | { 4 | //64bit 5 | assembly("syscall"::"a"(60),"D"(0)); 6 | } 7 | -------------------------------------------------------------------------------- /tmp/c-new/tests/60-function-define-with-type.et: -------------------------------------------------------------------------------- 1 | int8 test() { 2 | return 16; 3 | } 4 | void main() { 5 | _ test();//print 6 | } 7 | -------------------------------------------------------------------------------- /tmp/c-new/tests/58-function-call-print.et: -------------------------------------------------------------------------------- 1 | test() { 2 | return 1; 3 | } 4 | test();//only call without any print! 5 | _ test();//print value 6 | -------------------------------------------------------------------------------- /tmp/js/src/cli/io/index.js: -------------------------------------------------------------------------------- 1 | const { fileExists, fileReads } = require('./file'); 2 | 3 | module.exports = { 4 | fileExists, 5 | fileReads, 6 | }; 7 | -------------------------------------------------------------------------------- /tmp/c-new/tests/10-file-copy.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | file.copy("test.txt","../new.txt"); 4 | int result=file.copy("test.txt","../new.txt"); 5 | } 6 | -------------------------------------------------------------------------------- /tmp/c-new/tests/17-operator-test.et: -------------------------------------------------------------------------------- 1 | int main(int count) 2 | { 3 | print 5 == 2; 4 | print 5 === 2; 5 | print 5 ==== 2; 6 | return 1; 7 | } 8 | -------------------------------------------------------------------------------- /tmp/c-new/tests/36-math-cos.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | _ math.cos(0); 4 | _ "\n"; 5 | __ math.cos(45); 6 | print math.cos(90); 7 | _ "\n"; 8 | } 9 | -------------------------------------------------------------------------------- /tmp/c-new/tests/62-get-input-value.et: -------------------------------------------------------------------------------- 1 | void main() { 2 | //(int) this convert string to int! 3 | int age = (int) io.input(); 4 | __ age; 5 | } 6 | -------------------------------------------------------------------------------- /tmp/c-new/tests/11-file-set.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | file.set("example.txt","First Data\n"); 4 | int result=file.set("example.txt","First Data\n"); 5 | } 6 | -------------------------------------------------------------------------------- /tmp/c-new/tests/15-expression-test.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | print 5+5; 4 | print 10-5; 5 | print 5 . "hello!"; 6 | print "1" . 2; 7 | return 8; 8 | } 9 | -------------------------------------------------------------------------------- /tmp/c-new/tests/9-file-rename.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | file.rename("example.txt","new.txt"); 4 | int result=file.rename("example.txt","new.txt"); 5 | } 6 | -------------------------------------------------------------------------------- /tmp/c-new/tests/activity_error.et: -------------------------------------------------------------------------------- 1 | void activity_error() 2 | { 3 | //document=layout.render("here-is-custom-file-name"); 4 | document=layout.render(); 5 | } 6 | -------------------------------------------------------------------------------- /tmp/c-new/tests/activity_index.et: -------------------------------------------------------------------------------- 1 | void activity_index() 2 | { 3 | //document=layout.render("here-is-custom-file-name"); 4 | document=layout.render(); 5 | } 6 | -------------------------------------------------------------------------------- /tmp/c-new/tests/activity_login.et: -------------------------------------------------------------------------------- 1 | void activity_login() 2 | { 3 | //document=layout.render("here-is-custom-file-name"); 4 | document=layout.render(); 5 | } 6 | -------------------------------------------------------------------------------- /tmp/js/src/generator/commands/expression.js: -------------------------------------------------------------------------------- 1 | const genExpression = (expr) => { 2 | return expr; 3 | }; 4 | 5 | module.exports = { 6 | genExpression, 7 | }; 8 | -------------------------------------------------------------------------------- /tmp/c-new/tests/3-function-define.et: -------------------------------------------------------------------------------- 1 | void hello() 2 | { 3 | print "Hello World!"; 4 | } 5 | int main() 6 | { 7 | hello(); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tmp/c-new/tests/38-string-upper.et: -------------------------------------------------------------------------------- 1 | main() 2 | { 3 | //__ mean print with new line 4 | //_ mean print without new line 5 | __ string.upper("Hello!");//HELLO! 6 | } 7 | -------------------------------------------------------------------------------- /src/parser/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | gcc ../lexer/lexer.c ../lexer/tokenizer/token.c ../lexer/tokenizer/tokenizer.c ./*.c ../builtins/*.c ../ast/ast.c -o parser 4 | -------------------------------------------------------------------------------- /tmp/c-new/tests/18-operator-test.et: -------------------------------------------------------------------------------- 1 | int main(int count) 2 | { 3 | print 5 > 2; 4 | print 5 < 2; 5 | print 5 >= 2; 6 | print 5 <= 2; 7 | return 1; 8 | } 9 | -------------------------------------------------------------------------------- /tmp/c-new/tests/63-array-string.et: -------------------------------------------------------------------------------- 1 | void main() { 2 | string[] list={"Stephin","Max","Old","New"}; 3 | each item in list { 4 | _ "==> ",item; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | --- 8 | -------------------------------------------------------------------------------- /tmp/c/input.one: -------------------------------------------------------------------------------- 1 | //dfgdfg 2 | /* 3 | HELLO, World! 4 | */ 5 | 6 | 7 | 8 | main(i32 a){ 9 | # this have crash: ret -3 10 | ret 110 11 | ret 3 12 | } 13 | -------------------------------------------------------------------------------- /tmp/c-new/tests/22-loop-repeat.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int16 current=1; 4 | repeat(500) 5 | { 6 | print current; 7 | current++; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | - name: Automatic merge on approval 3 | conditions: 4 | - '#approved-reviews-by>=1' 5 | actions: 6 | merge: 7 | method: merge 8 | -------------------------------------------------------------------------------- /tmp/c-new/tests/23-loop-while.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int16 current=1; 4 | while(current <= 500) 5 | { 6 | print current; 7 | current++; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tmp/js/src/generator/commands/if.js: -------------------------------------------------------------------------------- 1 | const { emit } = require('../temp'); 2 | 3 | const genIf = () => { 4 | console.log('if'); 5 | }; 6 | 7 | module.exports = { 8 | genIf, 9 | }; 10 | -------------------------------------------------------------------------------- /src/ast/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | gcc ../lexer/lexer.c ../lexer/tokenizer/token.c ../lexer/tokenizer/tokenizer.c ./*.c ../builtins/*.c ../parser/parser.c ../parser/parser_token.c -o ast 4 | -------------------------------------------------------------------------------- /tmp/c-new/tests/65-array-char.et: -------------------------------------------------------------------------------- 1 | void main() { 2 | char[] list={'a','b','c','d','e','f','g','h',i''j,'k','l','m','n','o','p','q','r','s','t','u','v','w','x','u','z'}; 3 | _ list.size(); 4 | } 5 | -------------------------------------------------------------------------------- /tmp/js/src/generator/commands/for.js: -------------------------------------------------------------------------------- 1 | const { emit } = require('../temp'); 2 | 3 | const genFor = () => { 4 | console.log('for'); 5 | }; 6 | 7 | module.exports = { 8 | genFor, 9 | }; 10 | -------------------------------------------------------------------------------- /tmp/c-new/tests/56-function-call-return.et: -------------------------------------------------------------------------------- 1 | //auto detect return type! 2 | test { 3 | return 6; 4 | } 5 | main { 6 | //auto detect type! 7 | //$age=test(); 8 | auto age=test(); 9 | } 10 | -------------------------------------------------------------------------------- /tmp/c-new/tests/21-loop-for.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int16 total=500; 4 | int16 current; 5 | for(current=1;current<=total;++current) 6 | { 7 | print current; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tmp/js/src/generator/commands/print.js: -------------------------------------------------------------------------------- 1 | const { emit } = require('../temp'); 2 | 3 | const genPrint = () => { 4 | console.log('print'); 5 | }; 6 | 7 | module.exports = { 8 | genPrint, 9 | }; 10 | -------------------------------------------------------------------------------- /tmp/js/src/generator/commands/while.js: -------------------------------------------------------------------------------- 1 | const { emit } = require('../temp'); 2 | 3 | const genWhile = () => { 4 | console.log('while'); 5 | }; 6 | 7 | module.exports = { 8 | genWhile, 9 | }; 10 | -------------------------------------------------------------------------------- /tmp/js/src/generator/temp.js: -------------------------------------------------------------------------------- 1 | global.emits = ''; 2 | 3 | /* 4 | * emit 5 | */ 6 | const emit = (source) => { 7 | emits += source + '\n'; 8 | }; 9 | 10 | module.exports = { 11 | emit, 12 | }; 13 | -------------------------------------------------------------------------------- /tmp/c-new/tests/66-array-char.et: -------------------------------------------------------------------------------- 1 | void main() { 2 | char[] list={'a','b','c','d','e','f','g','h',i''j,'k','l','m','n','o','p','q','r','s','t','u','v','w','x','u','z'}; 3 | _ list.item(0);//get first value 4 | } 5 | -------------------------------------------------------------------------------- /tmp/c-new/tests/7-file-create.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | file.create("sample.et"); 4 | int result=file.create("sample.et"); 5 | file.create("sample.et",777); 6 | result=result=file.create("sample.et",777); 7 | } 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: check 2 | check: 3 | pre-commit run --all-files 4 | 5 | .PHONY: checkinstall 6 | checkinstall: 7 | pre-commit install 8 | 9 | .PHONY: checkupdate 10 | checkupdate: 11 | pre-commit autoupdate 12 | -------------------------------------------------------------------------------- /tmp/c-new/tests/61-get-input-value.et: -------------------------------------------------------------------------------- 1 | void main() { 2 | //(int) this convert string to int! 3 | int input = (int) io.input(); 4 | if input % 2 == 0 { 5 | _ "You enter the ",input,"!"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tmp/c-new/tests/67-operator.et: -------------------------------------------------------------------------------- 1 | float test() { 2 | //we can pass bool data as int or float data type! 3 | return false;//false mean 0 4 | } 5 | int main() { 6 | _ test() + 5;//will print 0+5 or 5 7 | return 1; 8 | } 9 | -------------------------------------------------------------------------------- /tmp/c-new/tests/24-if-else.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int16 number=1; 4 | if(number >= 0) 5 | { 6 | print "number >= 0"; 7 | } 8 | else 9 | { 10 | print "number < 0"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tmp/c-new/tests/25-if-else-odd-even.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int16 number=1; 4 | if(number % 2 == 0) 5 | { 6 | print "is even."; 7 | } 8 | else 9 | { 10 | print "is odd."; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tmp/c-new/tests/64-array-char.et: -------------------------------------------------------------------------------- 1 | void main() { 2 | char[] list={'a','b','c','d','e','f','g','h',i''j,'k','l','m','n','o','p','q','r','s','t','u','v','w','x','u','z'}; 3 | each item in list { 4 | _ "==> ",item; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tmp/c/src/scanner.c: -------------------------------------------------------------------------------- 1 | /** 2 | File: scanner.c 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | #include "scanner.h" 10 | #include "lexer.h" 11 | #include "token.h" 12 | -------------------------------------------------------------------------------- /.github/linters/.yaml-lint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # https://yamllint.readthedocs.io/en/stable/ 3 | # yamllint --strict -c .github/linters/.yaml-lint.yml . 4 | extends: default 5 | 6 | rules: 7 | document-start: disable 8 | line-length: disable 9 | truthy: false 10 | -------------------------------------------------------------------------------- /scripts/ci/pre-commit/sort-and-uniquify-codespell-wordlist.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CODESPELL_WORDLIST="codespell.txt" 4 | temp_file=$(mktemp) 5 | sort <"$CODESPELL_WORDLIST" | uniq >"$temp_file" 6 | cat "$temp_file" >"$CODESPELL_WORDLIST" 7 | rm "$temp_file" 8 | -------------------------------------------------------------------------------- /tmp/c-new2/value.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: value.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include "value.h" 13 | -------------------------------------------------------------------------------- /tmp/c-new/tests/26-loop-count-number.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int32 number=4173; 4 | int8 count = 0; 5 | while(number != 0) 6 | { 7 | number /= 10; 8 | ++count; 9 | } 10 | print "Number of digits: "; 11 | print count; 12 | } 13 | -------------------------------------------------------------------------------- /tmp/c/src/scanner.h: -------------------------------------------------------------------------------- 1 | /** 2 | File: scanner.h 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | #ifndef _SCANNER_H_ 10 | #define _SCANNER_H_ 11 | 12 | #include "one.h" 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /test/ast.test.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: ast.test.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "test.h" 12 | 13 | int main() 14 | { 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/parser.test.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: parser.test.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "test.h" 12 | 13 | int main() 14 | { 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tmp/c-new/tests/19-factorial.et: -------------------------------------------------------------------------------- 1 | //Algorithm : https://en.wikipedia.org/wiki/Factorial 2 | uint8 fact(uint8 number) 3 | { 4 | if(number == 1 || number == 0) 5 | { 6 | return 1; 7 | } 8 | return number*fact(number-1); 9 | } 10 | void main() 11 | { 12 | print fact(5); 13 | } 14 | -------------------------------------------------------------------------------- /test/argument.test.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: argument.test.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "test.h" 12 | 13 | int main() 14 | { 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tmp/js/src/generator/statements.js: -------------------------------------------------------------------------------- 1 | const { genStatement } = require('./statement'); 2 | 3 | const genStatements = (stmts) => { 4 | for (let stmt of stmts) { 5 | // console.log(stmt); 6 | genStatement(stmt); 7 | } 8 | }; 9 | 10 | module.exports = { 11 | genStatements, 12 | }; 13 | -------------------------------------------------------------------------------- /tmp/c-new/tests/40-architecture-sample.et: -------------------------------------------------------------------------------- 1 | style { 2 | list { 3 | color "red"; 4 | } 5 | list item { 6 | display "inline"; 7 | } 8 | } 9 | list { 10 | item { 11 | _ "Home"; 12 | } 13 | item { 14 | _ "About"; 15 | } 16 | item { 17 | _ "Contact Us"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tmp/c-new/src/one.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: one.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _ONE_H_ 12 | #define _ONE_H_ 13 | 14 | #define ONE_VERSION "0.1.0" 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /tmp/js/src/cli/commands/version.js: -------------------------------------------------------------------------------- 1 | const versionNumber = 100; 2 | const versionString = '1.0.0'; 3 | 4 | /* 5 | * version 6 | */ 7 | const version = (args) => { 8 | console.log(`One ${versionString}`); 9 | }; 10 | 11 | module.exports = { 12 | versionNumber, 13 | versionString, 14 | version, 15 | }; 16 | -------------------------------------------------------------------------------- /tmp/c-new2/repl.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: repl.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_REPL_H 12 | #define ONE_REPL_H 13 | 14 | static int repl(); 15 | 16 | #endif //ONE_REPL_H 17 | -------------------------------------------------------------------------------- /tmp/c-new/tests/57-function-call-return.et: -------------------------------------------------------------------------------- 1 | //auto detect return type! 2 | test(input) { 3 | if(input>0) 4 | { 5 | return 46.12; 6 | } 7 | return 6; 8 | } 9 | main { 10 | //auto detect type! 11 | //$age=test(1); 12 | auto age=test(1); 13 | //$age=test(-5); 14 | auto age=test(-5); 15 | } 16 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically 2 | version: 2 3 | updates: 4 | 5 | # Maintain dependencies for GitHub Actions 6 | - package-ecosystem: "github-actions" 7 | directory: "/" 8 | schedule: 9 | interval: "daily" 10 | -------------------------------------------------------------------------------- /tmp/c-new2/file.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: file.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_FILE_H 12 | #define ONE_FILE_H 13 | 14 | char* file_reads(const char* path); 15 | 16 | #endif //ONE_FILE_H 17 | -------------------------------------------------------------------------------- /tmp/js/src/cli/commands/run.js: -------------------------------------------------------------------------------- 1 | const { parseFile } = require('../../scanner/parser'); 2 | 3 | /* 4 | * run 5 | */ 6 | const run = (args) => { 7 | console.log('Run'); 8 | if (args.length === 0) { 9 | // Interactive environment 10 | return; 11 | } 12 | parseFile(args[0]); 13 | }; 14 | 15 | module.exports = { 16 | run, 17 | }; 18 | -------------------------------------------------------------------------------- /tmp/c-new2/one.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: one.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_ONE_H 12 | #define ONE_ONE_H 13 | 14 | #define ONE_PACKAGE_DEFAULT "main" 15 | 16 | #define ONE_VERSION "1.0.0" 17 | 18 | #endif //ONE_ONE_H 19 | -------------------------------------------------------------------------------- /tmp/js/input.ast: -------------------------------------------------------------------------------- 1 | { 2 | "functions": [ 3 | { 4 | "type": "function", 5 | "return": "int32", 6 | "return_default": true, 7 | "name": "main", 8 | "args": [], 9 | "stmts": [ 10 | { 11 | "type": "var_assignment", 12 | "varname": "a", 13 | "value": 4 14 | } 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tmp/js/src/generator/commands/function.js: -------------------------------------------------------------------------------- 1 | const { emit } = require('../temp'); 2 | const { genStatements } = require('../statements'); 3 | 4 | const genFunction = (command) => { 5 | console.log(command); 6 | emit(`${command.return} ${command.name}() {`); 7 | genStatements(command.stmts); 8 | emit(`}`); 9 | }; 10 | 11 | module.exports = { 12 | genFunction, 13 | }; 14 | -------------------------------------------------------------------------------- /tmp/c-new/tests/20-factorial-loop.et: -------------------------------------------------------------------------------- 1 | //Algorithm : https://en.wikipedia.org/wiki/Factorial 2 | uint64 fact(uint8 number) 3 | { 4 | if(number == 1 || number == 0) 5 | { 6 | return 1; 7 | } 8 | return number*fact(number-1); 9 | } 10 | void main() 11 | { 12 | int8 total=10; 13 | for(int8 current=1;current<=total;current++) 14 | { 15 | print fact(current); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | charset = utf-8 9 | end_of_line = lf 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.bat] 14 | end_of_line = crlf 15 | 16 | [{Makefile,*.one}] 17 | indent_style = tab 18 | -------------------------------------------------------------------------------- /tmp/c-new/tests/33-web-cgi.et: -------------------------------------------------------------------------------- 1 | //Sample Code For `Web CGI` : First Version 2 | void main() 3 | { 4 | while(cgi.accept()) 5 | { 6 | //cgi.type("text/html"); 7 | //cgi.format("html");//auto detect html is alias of `text/html` 8 | //cgi.charset("utf-8"); 9 | _ "content-type: text/html; charset=utf-8\r\n\r\n"; 10 | _ "Hello World!"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/file.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "test.h" 5 | 6 | int main() 7 | { 8 | bool res; 9 | size_t rows; 10 | size_t columns; 11 | 12 | const char* input = "\n!!!hello!!!!\n"; 13 | int index = 10; 14 | res = file_convert_index_to_rc(input, index, &rows, &columns); 15 | 16 | printf("==>%d, %zu:%zu\n", res == true ? 1 : 0, rows, columns); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tmp/c-new/src/file.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: file.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _FILE_H_ 12 | #define _FILE_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | char *fileReads(const char *, ErrorsContainer *); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /tmp/c-new2/interpret.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: interpret.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_INTERPRET_H 12 | #define ONE_INTERPRET_H 13 | 14 | int interpret_file(const char* path); 15 | 16 | int interpret_source(char* source, const char* path); 17 | 18 | #endif //ONE_INTERPRET_H 19 | -------------------------------------------------------------------------------- /tmp/js/src/generator/commands/variable-define.js: -------------------------------------------------------------------------------- 1 | const { emit } = require('../temp'); 2 | const { genExpression } = require('./expression'); 3 | 4 | const genVariableDefine = (command) => { 5 | console.log('variable'); 6 | const value = genExpression(command.value); 7 | // emit(`${command.varname};`); 8 | emit(`${command.varname} = ${value};`); 9 | }; 10 | 11 | module.exports = { 12 | genVariableDefine, 13 | }; 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # general 2 | cmake-build-debug 3 | node_modules 4 | one 5 | *.o 6 | out/* 7 | .idea 8 | .vscode 9 | 10 | # build 11 | build 12 | src/*.exe 13 | src/*/*.exe 14 | src/*/*/*.exe 15 | 16 | # lexer 17 | src/lexer/lexer 18 | src/lexer/log 19 | 20 | # parser 21 | src/parser/parser 22 | src/parser/log 23 | 24 | # ast 25 | src/ast/ast 26 | src/ast/log 27 | 28 | # test 29 | test/lexer 30 | test/parser 31 | test/argument 32 | test/ast 33 | -------------------------------------------------------------------------------- /input.one: -------------------------------------------------------------------------------- 1 | package max 2 | import math 3 | 4 | struct Cat { 5 | breed string 6 | } 7 | 8 | struct User { 9 | id int 10 | name string 11 | } 12 | 13 | struct Post { 14 | id int 15 | user_id int 16 | title string 17 | body string 18 | } 19 | 20 | fn main { 21 | _ 1 22 | _ 1_000_000 23 | /* 24 | _ 2, 4, 6, 8 25 | _ 5 + 8 26 | _ 1 27 | _ 110 28 | _ 123 29 | _ -1 30 | _ !4 31 | _ (2 + 15 * ( 25 - 13 ) / 1 - 4) + 10 / 2 32 | */ 33 | } 34 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: ['One-Language'] 4 | patreon: onelanguage 5 | open_collective: onelang 6 | ko_fi: onelang 7 | # tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | # community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: one 10 | issuehunt: One-Language 11 | otechie: one 12 | custom: ['https://www.buymeacoffee.com/onelang'] 13 | -------------------------------------------------------------------------------- /tmp/c-new/tests/28-if-else-which-largest.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int32 n1=941; 4 | int32 n2=960; 5 | int32 n3=15312; 6 | if(n1>=n2 && n1>=n3) 7 | { 8 | print n1; 9 | print " is the largest number."; 10 | } 11 | else if(n2>=n1 && n2>=n3) 12 | { 13 | print n2; 14 | print " is the largest number."; 15 | } 16 | else 17 | { 18 | print n3; 19 | print " is the largest number."; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/input.one: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import one.two.three 4 | import p0 as p { sin as s } 5 | import p1 6 | import p2 as m 7 | import p3 { sin as s } 8 | import p4 { sin as s, cos as c } 9 | import p5 { sin as s, cos as c ,} 10 | import p6 { 11 | sin as s 12 | cos as c 13 | } 14 | import p7 { sin as s cos as c } 15 | import p8 { one.two.three } 16 | 17 | fn 18 | main { 19 | if aaa {} 20 | if aaa {} 21 | if aaa { if aaa { if aaa {} 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tmp/js/src/cli/io/file.js: -------------------------------------------------------------------------------- 1 | const fs = require('mz/fs'); 2 | const path = require('path'); 3 | 4 | const fileExists = (filepath) => { 5 | return fs.existsSync(filepath); 6 | }; 7 | 8 | const fileSave = async (filepath, data) => { 9 | await fs.writeFile(filepath, data); 10 | }; 11 | 12 | const fileReads = async (filepath) => { 13 | return (await fs.readFile(filepath)).toString(); 14 | }; 15 | 16 | module.exports = { 17 | fileExists, 18 | fileReads, 19 | fileSave, 20 | }; 21 | -------------------------------------------------------------------------------- /tmp/c-new/tests/27-if-which-largest.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int32 n1=960; 4 | int32 n2=15312; 5 | int32 n3=941; 6 | if(n1>=n2 && n1>=n3) 7 | { 8 | print n1; 9 | print " is the largest number."; 10 | } 11 | if(n2>=n1 && n2>=n3) 12 | { 13 | print n2; 14 | print " is the largest number."; 15 | } 16 | if(n3>=n1 && n3>=n2) 17 | { 18 | print n3; 19 | print " is the largest number."; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tmp/c-new/src/array.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: array.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _ARRAY_H_ 12 | #define _ARRAY_H_ 13 | 14 | typedef struct 15 | { 16 | int count; 17 | int size; 18 | void **data; 19 | } Array; 20 | 21 | void arrayInit(Array *); 22 | void arrayPush(Array *, void *); 23 | void *arrayPop(Array *); 24 | void arrayFree(Array *); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /tmp/c/src/arg.h: -------------------------------------------------------------------------------- 1 | /** 2 | File: arg.h 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | #include "one.h" 10 | 11 | #ifndef _ARG_H_ 12 | #define _ARG_H_ 13 | 14 | typedef struct 15 | { 16 | bool help; 17 | bool version; 18 | bool debug; 19 | 20 | char **input_files; 21 | 22 | int argc; 23 | char **argv; 24 | char **env; 25 | } Args; 26 | 27 | void parseArgs(int argc, char **argv, char **env, Args *args); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /tmp/c-new/tests/41-architecture-sample.et: -------------------------------------------------------------------------------- 1 | style { 2 | * { 3 | margin 0; 4 | padding 0; 5 | } 6 | header { 7 | width "100%"; 8 | height "auto"; 9 | } 10 | list { 11 | color "red"; 12 | } 13 | list item { 14 | display "inline"; 15 | padding "10px"; 16 | background "yellow"; 17 | } 18 | } 19 | header { 20 | list { 21 | item { 22 | _ "Home"; 23 | } 24 | item { 25 | _ "About"; 26 | } 27 | item { 28 | _ "Contact Us"; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.github/linters/mlc_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "httpHeaders": [ 3 | { 4 | "urls": ["https://docs.github.com/"], 5 | "headers": { 6 | "Accept-Encoding": "zstd, br, gzip, deflate" 7 | } 8 | } 9 | ], 10 | "aliveStatusCodes": [200, 429], 11 | "ignorePatterns": [ 12 | { 13 | "pattern": "^https?://(?:www\\.)?twitter\\.com/.*" 14 | }, 15 | { 16 | "pattern": "^https?://(?:www\\.)?patreon\\.com/onelanguage" 17 | }, 18 | { 19 | "pattern": "^#" 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /tmp/c-new/tests/32-web-architecture.et: -------------------------------------------------------------------------------- 1 | //Sample Code For `Web Architecture` : First Version 2 | void index() 3 | { 4 | print "Main Page"; 5 | } 6 | void login() 7 | { 8 | print "Login Page"; 9 | } 10 | void register() 11 | { 12 | print "Register Page"; 13 | } 14 | void error() 15 | { 16 | print "404"; 17 | } 18 | void main() 19 | { 20 | web.routes.add("",index()); 21 | web.routes.add("login",login()); 22 | web.routes.add("register",register()); 23 | web.routes.add("*",error()); 24 | web.execute(); 25 | } 26 | -------------------------------------------------------------------------------- /tmp/c-new2/array.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: array.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_ARRAY_H 12 | #define ONE_ARRAY_H 13 | 14 | typedef struct 15 | { 16 | int count; 17 | int size; 18 | void **data; 19 | } Array; 20 | 21 | void array_init(Array *list); 22 | 23 | void array_push(Array *list, void *item); 24 | 25 | void *array_pop(Array *list); 26 | 27 | void array_free(Array *list); 28 | 29 | #endif //ONE_ARRAY_H 30 | -------------------------------------------------------------------------------- /tmp/c-new/tests/42-architecture-sample.et: -------------------------------------------------------------------------------- 1 | title "Name - Main"; 2 | description "Desc,..."; 3 | keyword "key,...,...,..."; 4 | style { 5 | * { 6 | margin 0; 7 | padding 0; 8 | } 9 | header { 10 | width "100%"; 11 | height "auto"; 12 | } 13 | list { 14 | color "red"; 15 | } 16 | list item { 17 | display "inline"; 18 | padding "10px"; 19 | background "yellow"; 20 | } 21 | } 22 | header { 23 | list { 24 | item { 25 | _ "Home"; 26 | } 27 | item { 28 | _ "About"; 29 | } 30 | item { 31 | _ "Contact Us"; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: Pull Request Labeler 2 | on: 3 | - pull_request_target 4 | 5 | permissions: # added using https://github.com/step-security/secure-workflows 6 | contents: read 7 | 8 | jobs: 9 | triage: 10 | permissions: 11 | contents: read # for actions/labeler to determine modified files 12 | pull-requests: write # for actions/labeler to add labels to PRs 13 | name: Triage 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/labeler@v6 17 | with: 18 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 19 | sync-labels: true 20 | -------------------------------------------------------------------------------- /tmp/c-new2/repl.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: repl.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include 13 | 14 | #include "interpret.h" 15 | 16 | #include "repl.h" 17 | 18 | static int repl() 19 | { 20 | int ret; 21 | char line[2048]; 22 | 23 | for (;;) 24 | { 25 | printf("> "); 26 | if (!fgets(line, sizeof line, stdin)) 27 | { 28 | printf("\n"); 29 | break; 30 | } 31 | ret = interpret_source(line, NULL); 32 | } 33 | 34 | return ret; 35 | } 36 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################### 2 | # Git Line Endings # 3 | ############################### 4 | 5 | # Set default behaviour to automatically normalize line endings. 6 | * text=auto 7 | 8 | # Force batch scripts to always use CRLF line endings so that if a repo is accessed 9 | # in Windows via a file share from Linux, the scripts will work. 10 | *.{cmd,[cC][mM][dD]} text eol=crlf 11 | *.{bat,[bB][aA][tT]} text eol=crlf 12 | 13 | # Force bash scripts to always use LF line endings so that if a repo is accessed 14 | # in Unix via a file share from Windows, the scripts will work. 15 | *.sh text eol=lf 16 | -------------------------------------------------------------------------------- /tmp/c-new/src/compile.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: compile.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _COMPILE_H_ 12 | #define _COMPILE_H_ 13 | 14 | typedef struct _errors ErrorsContainer; 15 | 16 | void link(Args *, ErrorsContainer *); 17 | 18 | int compileFile(char *, ErrorsContainer *); 19 | 20 | int compileFileString(char *, char *, ErrorsContainer *); 21 | 22 | int compileString(char *, ErrorsContainer *); 23 | 24 | int compileFile(char *, ErrorsContainer *); 25 | 26 | int compile(Args *, ErrorsContainer *); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /test/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | FLAGS="-o" 4 | FILES="../src/builtins/array.c ../src/builtins/error.c ../src/builtins/file.c ../src/ast/ast.c ../src/parser/parser.c ../src/parser/parser_token.c ../src/lexer/lexer.c ../src/lexer/tokenizer/token.c ../src/lexer/tokenizer/tokenizer.c -lLLVM-12 -D_ONE_TEST_" 5 | CC="clang" 6 | 7 | # compile argument 8 | "$CC" argument.test.c "$FLAGS" argument "$FILES" 9 | # compile lexer 10 | "$CC" lexer.test.c "$FLAGS" lexer "$FILES" 11 | # compile parser 12 | "$CC" parser.test.c "$FLAGS" parser "$FILES" 13 | # compiler ast 14 | "$CC" ast.test.c "$FLAGS" ast "$FILES" 15 | 16 | # run 17 | ./arguments 18 | ./lexer 19 | ./parser 20 | ./ast 21 | -------------------------------------------------------------------------------- /tmp/c-new/src/vm.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: vm.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _VM_H_ 12 | #define _VM_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "ast.h" 19 | 20 | void vmInit(AstRoot*); 21 | 22 | void vmLog(AstRoot*); 23 | 24 | void vmFree(AstRoot*); 25 | 26 | void vmFunction(AstFunction*); 27 | 28 | void vmStatement(AstStatement*); 29 | 30 | void vmStatements(AstStatements*); 31 | 32 | void vmBlock(AstBlock*); 33 | 34 | void print_tabs(size_t); 35 | 36 | #endif //_VM_H_ 37 | -------------------------------------------------------------------------------- /tmp/c-new/src/tree.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: tree.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _TREE_H_ 12 | #define _TREE_H_ 13 | 14 | #include "ast.h" 15 | 16 | void print_tabs(size_t); 17 | 18 | void treeLog(AstRoot*); 19 | 20 | void treeStatement(AstStatement*); 21 | 22 | void treeStatements(AstStatements*); 23 | 24 | void treeBlock(AstBlock*); 25 | 26 | void treeFunction(AstFunction*); 27 | 28 | void treeLog(AstRoot*); 29 | 30 | void treeExpression(AstExpression*); 31 | 32 | void treeExpressions(AstExpressions*); 33 | 34 | #endif //_TREE_H_ 35 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | --- 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 11 | 12 | **Describe the solution you'd like** 13 | A clear and concise description of what you want to happen. 14 | 15 | **Describe alternatives you've considered** 16 | A clear and concise description of any alternative solutions or features you've considered. 17 | 18 | **Additional context** 19 | Add any other context or screenshots about the feature request here. 20 | -------------------------------------------------------------------------------- /tmp/c-new/tests/16-operator-test.et: -------------------------------------------------------------------------------- 1 | int main(int count) 2 | { 3 | print 12345678900; 4 | print false; 5 | print true; 6 | print null; 7 | print 94; 8 | print 155555551; 9 | print 9999999992; 10 | print -94; 11 | print -15555555; 12 | print -9999999992; 13 | print +5; 14 | print (5); 15 | print (-5); 16 | print -(-5); 17 | print 5; 18 | print 5+5; 19 | print 10-5; 20 | print 5 . "hello!"; 21 | print "1" . 2; 22 | print 5 . 3; 23 | print 1 . 2 . 3; 24 | print -1; 25 | print +1; 26 | print -1+2; 27 | print 1+2; 28 | print -(1+2)*6 / 3; 29 | print 5 == 2; 30 | print -2 == 2; 31 | return 1; 32 | } 33 | -------------------------------------------------------------------------------- /tmp/c/src/parser.h: -------------------------------------------------------------------------------- 1 | /** 2 | File: parser.h 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | #ifndef _PARSER_H_ 10 | #define _PARSER_H_ 11 | 12 | #include "one.h" 13 | 14 | void parser(Lexer *); 15 | void parser_statement(Lexer *); 16 | void parser_statements(Lexer *); 17 | void parser_except(Lexer *, char); 18 | void parser_function(Lexer *); 19 | void parser_function_arguments(Lexer *); 20 | void parse_statement_return(Lexer *); 21 | void parse_expression(Lexer *); 22 | int parser_operator_precedence(int); 23 | int parser_bin_op_rhs(Lexer *, int, int); 24 | int parser_unary(Lexer *, int); 25 | int parser_expression(Lexer *); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /tmp/c-new/tests/34-architecture.et: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample Code For `Architecture` : Second Version 3 | * Target : 4 | * Web 5 | * Software 6 | * Mobile-Application (in the future) 7 | */ 8 | //load and import the activity pages! 9 | import "activity_index.et"; 10 | import "activity_login.et"; 11 | import "activity_error.et"; 12 | void main() 13 | { 14 | //the empty rule mean the first and main activity page! 15 | layout.set("",activity_index()); 16 | 17 | //`login` is the name and rule path! 18 | layout.set("login",activity_login()); 19 | 20 | //`*` mean the any other activity! such as : 404 error page. 21 | layout.set("*",activity_error()); 22 | 23 | //begin template engine 24 | layout.execute(); 25 | } 26 | -------------------------------------------------------------------------------- /tmp/c-new/src/lexer.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: lexer.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _LEXER_H_ 12 | #define _LEXER_H_ 13 | 14 | typedef struct _token Token; 15 | typedef struct _location Location; 16 | typedef struct _errors ErrorsContainer; 17 | 18 | typedef struct _lexer 19 | { 20 | Token **tokens; 21 | size_t token_count; 22 | 23 | char *filename; // filename (path) 24 | char *source; // source string 25 | Location location; 26 | } Lexer; 27 | 28 | Lexer *lexerInit(char *, char *, ErrorsContainer *); 29 | 30 | int lexerCheck(Lexer *, ErrorsContainer *); 31 | 32 | void lexerFree(Lexer *); 33 | 34 | void lexerLog(Lexer *); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /tmp/c-new2/one.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: one.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "repl.h" 16 | #include "interpret.h" 17 | #include "argument.h" 18 | #include "error.h" 19 | 20 | #include "one.h" 21 | 22 | #ifndef _ONE_TEST_ 23 | int main(int argc, char **argv, char **env) 24 | { 25 | debug("main"); 26 | 27 | Arguments args; 28 | 29 | argument_init(&args); 30 | argument_parse(argc, argv, env, &args); 31 | int ret = argument_run(&args); 32 | argument_free(&args); 33 | 34 | debug("main: return %d", ret); 35 | debug("main: end"); 36 | 37 | return ret; 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /tmp/js/src/cli/commands/help.js: -------------------------------------------------------------------------------- 1 | const helpMessage = `One is a General-purpose programming language. 2 | 3 | Usage: 4 | 5 | one [arguments] 6 | 7 | The commands are: 8 | 9 | build compile packages and dependencies 10 | install compile and install packages and dependencies 11 | run compile and run One program 12 | version print One version 13 | 14 | Use "one help " for more information about a command. 15 | 16 | `; 17 | 18 | /* 19 | * version 20 | */ 21 | const help = (args) => { 22 | console.log(helpMessage); 23 | }; 24 | 25 | const helpWrong = (args) => { 26 | console.log(`one ${args[0]}: unknown command`); 27 | console.log(`Run 'one help' for usage.`); 28 | }; 29 | 30 | module.exports = { 31 | helpMessage, 32 | help, 33 | helpWrong, 34 | }; 35 | -------------------------------------------------------------------------------- /tmp/c-new/tests/31-sort-char.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | char array[]="hello,hereiset-lang!howareyou?!"; 4 | char output[string.length(array)]; 5 | int32 count[256]; 6 | int32 current; 7 | memory.set(count,0,memory.size(count)); 8 | for(current=0;array[current];++current) 9 | { 10 | ++count[array[current]]; 11 | } 12 | for(current=1;current<=255;++current) 13 | { 14 | count[current]+=count[current-1]; 15 | } 16 | for(current=0;array[current];++current) 17 | { 18 | output[count[array[current]]-1]=array[current]; 19 | --count[array[current]]; 20 | } 21 | for(current=0;array[current];++current) 22 | { 23 | array[current]=output[current]; 24 | } 25 | print "Final Result: \n"; 26 | print array; 27 | print "\n"; 28 | } 29 | -------------------------------------------------------------------------------- /.github/linters/.markdown-lint.yml: -------------------------------------------------------------------------------- 1 | # https://github.com/DavidAnson/markdownlint#rules--aliases 2 | # markdownlint -c .github/linters/.markdown-lint.yml . 3 | 4 | # MD001/heading-increment/header-increment Heading levels should only increment by one level at a time 5 | MD001: false 6 | 7 | # MD013/line-length Line length 8 | MD013: false 9 | 10 | # MD025 single-title/single-h1 - Multiple top-level headings in the same document 11 | MD025: false 12 | 13 | # MD026/no-trailing-punctuation Trailing punctuation in heading 14 | MD026: false 15 | 16 | # MD033/no-inline-html Inline HTML 17 | MD033: false 18 | 19 | # MD040 fenced-code-language - Fenced code blocks should have a language specified 20 | MD040: false 21 | 22 | # MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading 23 | MD041: false 24 | -------------------------------------------------------------------------------- /tmp/c-new/tests/29-sort-bubble.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int32 temp; 4 | int32 count; 5 | int32 array[50]; 6 | int32 x; 7 | int32 y; 8 | print "Enter the size of array: "; 9 | scan count; 10 | print "Enter the array elements: \n"; 11 | for(x=0;x "; 14 | scan array[x]; 15 | } 16 | for(x=1;xarray[y+1]) 21 | { 22 | temp=array[y]; 23 | array[y]=array[y+1]; 24 | array[y+1]=temp; 25 | } 26 | } 27 | } 28 | print "\nFinal Result: \n"; 29 | for(x=0;x"; 32 | print array[x]; 33 | print "\n"; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tmp/c-new/unit-tests/lexer.test.c: -------------------------------------------------------------------------------- 1 | #include "unity.h" 2 | #include "token.h" 3 | #include "error.h" 4 | #include "lexer.h" 5 | #include "array.h" 6 | 7 | char *filename; 8 | char *input; 9 | ErrorsContainer *errors; 10 | Lexer *lex; 11 | 12 | void setUp(void) 13 | { 14 | // This is the initialization for the variables needed for the unit testing. 15 | // It can be updated 16 | filename = "tests/1-hello-world.et"; 17 | input = ""; 18 | ErrorsInit(errors); 19 | lex = lexerInit(filename, input, errors); 20 | } 21 | 22 | void tearDown(void) 23 | { 24 | lexerFree(lex); 25 | } 26 | 27 | void test_function_should_check_lex(void) 28 | { 29 | TEST_ASSERT_EQUAL_INT(EXIT_SUCCESS, lexerCheck(lex, errors)); 30 | } 31 | 32 | int main(void) 33 | { 34 | UNITY_BEGIN(); 35 | RUN_TEST(test_function_should_check_lex); 36 | return UNITY_END(); 37 | } 38 | -------------------------------------------------------------------------------- /tmp/js/src/generator/statement.js: -------------------------------------------------------------------------------- 1 | const { genIf } = require('./commands/if'); 2 | const { genWhile } = require('./commands/while'); 3 | const { genFor } = require('./commands/for'); 4 | const { genVariableDefine } = require('./commands/variable-define'); 5 | const { genPrint } = require('./commands/print'); 6 | 7 | const genStatement = (stmt) => { 8 | console.log(stmt); 9 | switch (stmt.type) { 10 | case 'if': 11 | return genVariableDefine(stmt); 12 | case 'while': 13 | return genWhile(stmt); 14 | case 'for': 15 | return genFor(stmt); 16 | case 'print': 17 | return genPrint(stmt); 18 | case 'var_assignment': 19 | return genVariableDefine(stmt); 20 | default: 21 | console.warn('Error: bad statement!'); 22 | return null; 23 | } 24 | }; 25 | 26 | module.exports = { 27 | genStatement, 28 | }; 29 | -------------------------------------------------------------------------------- /tmp/c-new2/value.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: value.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_VALUE_H 12 | #define ONE_VALUE_H 13 | 14 | typedef enum 15 | { 16 | VAL_BOOL, 17 | VAL_NIL, 18 | VAL_NUMBER, 19 | } ValueType; 20 | 21 | typedef struct 22 | { 23 | ValueType type; 24 | union 25 | { 26 | bool boolean; 27 | double number; 28 | } as; 29 | } Value; 30 | 31 | #define AS_BOOL(value) ((value).as.boolean) 32 | #define AS_NUMBER(value) ((value).as.number) 33 | 34 | #define BOOL_VAL(value) ((Value){VAL_BOOL, {.boolean = value}}) 35 | 36 | #define IS_BOOL(value) ((value).type == VAL_BOOL) 37 | #define IS_NIL(value) ((value).type == VAL_NIL) 38 | #define IS_NUMBER(value) ((value).type == VAL_NUMBER) 39 | 40 | #endif //ONE_VALUE_H 41 | -------------------------------------------------------------------------------- /tmp/c-new/src/arg.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: arg.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _ARG_H_ 12 | #define _ARG_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | typedef struct _errors ErrorsContainer; 20 | 21 | typedef struct _args 22 | { 23 | bool help; 24 | bool version; 25 | bool debug; 26 | 27 | char **input_files; 28 | unsigned int input_files_count; 29 | 30 | int argc; 31 | char **argv; 32 | char **env; 33 | } Args; 34 | 35 | void ArgsInit(Args *); 36 | 37 | void ArgsParse(int, char **, char **, Args *, ErrorsContainer *); 38 | 39 | void ArgsFree(Args *); 40 | 41 | void ArgsHelp(FILE *, Args *); 42 | 43 | void ArgsVersion(FILE *, Args *); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /tmp/js/src/generator/vm.js: -------------------------------------------------------------------------------- 1 | const { fileSave } = require('../cli/io/file'); 2 | const generator = require('../generator/'); 3 | 4 | const tempFilename = 'input.c'; 5 | const astFilename = 'input.ast'; 6 | 7 | const astToStr = (ast) => { 8 | return JSON.stringify(ast, null, 2); 9 | }; 10 | 11 | const saveAst = async (ast) => { 12 | const log = astToStr(ast); 13 | await fileSave(astFilename, log); 14 | 15 | // const jsCode = generateJS(ast, []); 16 | // await fs.writeFile(outputFilename, jsCode); 17 | }; 18 | 19 | const saveTemp = async () => { 20 | console.log(emits); 21 | console.log(tempFilename); 22 | await fileSave(tempFilename, emits); 23 | }; 24 | 25 | const parseAst = (ast) => { 26 | // console.log(ast); 27 | for (let func of ast.functions) { 28 | generator.genFunction(func); 29 | } 30 | saveAst(ast); 31 | saveTemp(); 32 | }; 33 | 34 | module.exports = { 35 | parseAst, 36 | }; 37 | -------------------------------------------------------------------------------- /tmp/c-new/tests/30-sort-shell.et: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int32 array[20]; 4 | int32 current; 5 | int32 count; 6 | print "Enter the size of array: "; 7 | scan count; 8 | print "Enter the array elements: \n"; 9 | for(current=0;current0;number/=2) 18 | { 19 | for(x=number;x=number && array[y-number]>temp;y-=number) 23 | { 24 | array[y]=array[y-number]; 25 | } 26 | array[y]=temp; 27 | } 28 | } 29 | print "\nFinal Result: \n"; 30 | for(x=0;x"; 33 | print array[x]; 34 | print "\n"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tmp/js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "onelang", 3 | "version": "1.0.0", 4 | "description": "The One System Programming Language.", 5 | "main": "src/one.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "gen-parser": "nearleyc src/scanner/one.grammar -o src/scanner/grammar.js", 9 | "lint:check": "prettier --check . && eslint .", 10 | "lint:fix": "prettier --write ." 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/One-Language/One.git" 15 | }, 16 | "keywords": [], 17 | "author": "Max Base", 18 | "contributors": [], 19 | "license": "GPL3", 20 | "bugs": { 21 | "url": "https://github.com/One-Language/One/issues" 22 | }, 23 | "homepage": "https://github.com/One-Language/One#readme", 24 | "dependencies": { 25 | "mz": "^2.7.0", 26 | "nearley": "^2.20.1", 27 | "path": "^0.12.7", 28 | "prettier": "^2.2.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tmp/c-new/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.19) 2 | project(One C) 3 | 4 | set(CMAKE_C_STANDARD 11) 5 | 6 | include_directories(src) 7 | include_directories(unit-tests) 8 | include_directories(unit-tests/unity) 9 | 10 | add_executable(One 11 | src/arg.c 12 | src/arg.h 13 | 14 | src/array.c 15 | src/array.h 16 | 17 | src/compile.c 18 | src/compile.h 19 | 20 | src/error.c 21 | src/error.h 22 | 23 | src/lexer.c 24 | src/lexer.h 25 | 26 | src/one.c 27 | src/one.h 28 | 29 | src/ast.c 30 | src/ast.h 31 | 32 | src/parser.c 33 | src/parser.h 34 | 35 | src/tree.c 36 | src/tree.h 37 | 38 | src/token.c 39 | src/token.h 40 | 41 | src/compile.c 42 | src/compile.h 43 | 44 | src/vm.c 45 | src/vm.h 46 | 47 | src/file.c 48 | src/file.h 49 | 50 | ) 51 | -------------------------------------------------------------------------------- /tmp/c-new/src/one.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: one.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "token.h" 12 | #include "arg.h" 13 | #include "compile.h" 14 | #include "error.h" 15 | 16 | int main(int argc, char **argv, char **env) 17 | { 18 | int ret = EXIT_SUCCESS; 19 | 20 | ErrorsContainer errors; 21 | ErrorsInit(&errors); 22 | 23 | Args args; 24 | ArgsInit(&args); 25 | ArgsParse(argc, argv, env, &args, &errors); 26 | 27 | if (args.help) 28 | { 29 | ArgsHelp(stderr, &args); 30 | } 31 | else if (args.version) 32 | { 33 | ArgsVersion(stderr, &args); 34 | } 35 | else if (args.input_files_count > 0) 36 | { 37 | ret = compile(&args, &errors); 38 | } 39 | else 40 | { 41 | ArgsHelp(stderr, &args); 42 | } 43 | 44 | ErrorsPrints(stderr, &errors); 45 | 46 | ArgsFree(&args); 47 | ErrorsFree(&errors); 48 | 49 | return ret; 50 | } 51 | -------------------------------------------------------------------------------- /test/test.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: test.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_TEST_H 12 | #define ONE_TEST_H 13 | 14 | // You have to define a macro at CLANG or C compiler: #define _ONE_TEST_ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "../src/builtins/array.h" 22 | #include "../src/builtins/error.h" 23 | 24 | #include "../src/builtins/file.h" 25 | 26 | #include "../src/lexer/lexer.h" 27 | #include "../src/parser/parser.h" 28 | 29 | typedef struct 30 | { 31 | char* source; 32 | Token* tokens[1024]; 33 | size_t token_count; 34 | } LexerTest; 35 | 36 | // Argument(s) 37 | 38 | // Lexer 39 | void test_lexer_log(const char* source, Token** tokens); 40 | bool test_lexer_item(LexerTest test); 41 | bool test_lexer(); 42 | 43 | // Parser 44 | 45 | // Ast 46 | 47 | #endif //ONE_TEST_H 48 | -------------------------------------------------------------------------------- /tmp/c/src/one.h: -------------------------------------------------------------------------------- 1 | /** 2 | File: one.h 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | #ifndef _ONE_H_ 10 | #define _ONE_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "arg.h" 18 | #include "sds.h" 19 | #include "vec.h" 20 | 21 | // typedef struct Args; 22 | 23 | #define DEBUG 24 | #define ONE_VERSION "0.4.0" 25 | 26 | #define log(format, params...) printf(format, params...); 27 | 28 | void error(char *format, ...); 29 | void help(Args *args); 30 | char *file_read(char *); 31 | void file_parse(char *); 32 | 33 | // int main(int argc, const char* const* argv, const char* const* env); 34 | int main(int argc, char **argv, char **env); 35 | 36 | // typedef enum { 37 | // FALSE, 38 | // TRUE 39 | // } bool; 40 | 41 | // enum _bool { 42 | // false = 0, 43 | // true = 1 44 | // }; 45 | // typedef enum _bool Bool; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /tmp/c-old/src/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #ifndef _IO_H_ 21 | #define _IO_H_ 22 | 23 | #include "one.h" 24 | 25 | char *read_file(char *filename); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /tmp/c-new/src/file.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: file.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "token.h" 12 | #include "error.h" 13 | #include "file.h" 14 | 15 | char *fileReads(const char *filename, ErrorsContainer *errors) 16 | { 17 | FILE *onefile = fopen(filename, "rb"); 18 | if (onefile == NULL) 19 | { 20 | return NULL; 21 | } 22 | fseek(onefile, 0L, SEEK_END); 23 | size_t onefilesize = ftell(onefile); 24 | rewind(onefile); 25 | char *onebuffer = (char *)malloc(onefilesize + 1); 26 | if (onebuffer == NULL) 27 | { 28 | error("error malloc onebuffer\n"); 29 | return NULL; 30 | } 31 | size_t onebytesread = fread(onebuffer, 1, onefilesize, onefile); 32 | if (onebytesread < onefilesize) 33 | { 34 | free(onebuffer); 35 | error("Could not read file.one\n"); 36 | return NULL; 37 | } 38 | onebuffer[onebytesread] = '\0'; 39 | fclose(onefile); 40 | return onebuffer; 41 | } 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | --- 8 | 9 | **Describe the bug** 10 | A clear and concise description of what the bug is. 11 | 12 | **To Reproduce** 13 | Steps to reproduce the behavior: 14 | 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | 28 | - OS: [e.g. iOS] 29 | - Browser [e.g. Chrome, Safari] 30 | - Version [e.g. 22] 31 | 32 | **Smartphone (please complete the following information):** 33 | 34 | - Device: [e.g. iPhone6] 35 | - OS: [e.g. iOS8.1] 36 | - Browser [e.g. stock browser, Safari] 37 | - Version [e.g. 22] 38 | 39 | **Additional context** 40 | Add any other context about the problem here. 41 | -------------------------------------------------------------------------------- /tmp/c-new/src/array.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: array.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | 13 | #include "array.h" 14 | 15 | void arrayInit(Array *list) 16 | { 17 | list->count = 0; 18 | list->size = 0; 19 | list->data = NULL; 20 | } 21 | 22 | void arrayPush(Array *list, void *item) 23 | { 24 | if (list->count == list->size) 25 | { 26 | // Set size of new array to 4, and double size if it's next... 27 | list->size = list->size == 0 ? 4 : 2 * list->size; 28 | list->data = (void **)realloc(list->data, list->size * sizeof(void *)); 29 | } 30 | list->data[list->count] = item; 31 | list->count++; 32 | } 33 | 34 | void *arrayPop(Array *list) 35 | { 36 | list->count--; 37 | void *ret = list->data[list->count]; 38 | return ret; 39 | } 40 | void arrayFree(Array *list) 41 | { 42 | free(list->data); // it's void** 43 | list->count = 0; 44 | list->size = 0; 45 | list->data = NULL; 46 | } 47 | -------------------------------------------------------------------------------- /tmp/c-old/src/lexer/lexer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #ifndef _LEXER_H_ 21 | #define _LEXER_H_ 22 | 23 | #include "../one.h" 24 | 25 | Token lexer_next(Source *src); 26 | void lexer_scan(Source *src); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /tmp/c-old/src/lexer/token.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #include "token.h" 21 | 22 | Token token_new(void) 23 | { 24 | Token t; 25 | t.line = 1; 26 | t.offset = 0; 27 | t.tok = 0; 28 | t.name = "None"; 29 | return t; 30 | } 31 | -------------------------------------------------------------------------------- /tmp/c-new2/lexer.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: lexer.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_LEXER_H 12 | #define ONE_LEXER_H 13 | 14 | typedef struct _token Token; 15 | typedef enum _token_type TokenType; 16 | 17 | typedef struct _location 18 | { 19 | int line; 20 | int column; 21 | } Location; 22 | 23 | typedef struct 24 | { 25 | const char* start; 26 | const char* current; 27 | Location loc; 28 | } Lexer; 29 | 30 | void lexer_init(char* source); 31 | 32 | Token* lexer_skip_whitespace(); 33 | 34 | Token* lexer_number(); 35 | 36 | Token* lexer_char(); 37 | 38 | Token* lexer_string(); 39 | 40 | Token* lexer_scan(); 41 | 42 | void lexer_free(); 43 | 44 | Token* lexer_skip_comment_inline(); 45 | 46 | Token* lexer_skip_comment_multiline(); 47 | 48 | TokenType lexer_check_keyword(int start, int length, const char* rest, TokenType type); 49 | 50 | TokenType lexer_identifier_type(); 51 | 52 | Token* lexer_identifier(); 53 | 54 | #endif //ONE_LEXER_H 55 | -------------------------------------------------------------------------------- /tmp/c/src/lexer.h: -------------------------------------------------------------------------------- 1 | /** 2 | File: lexer.h 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | typedef struct token Token; 10 | 11 | #ifndef _LEXER_H_ 12 | #define _LEXER_H_ 13 | 14 | #include "one.h" 15 | 16 | typedef struct _location 17 | { 18 | size_t t; // index of current token 19 | size_t i; // file source index' character 20 | size_t l; // line number: default is 1 21 | size_t c; // column number: default is 0 22 | } Location; 23 | 24 | typedef struct lexer 25 | { 26 | // Assembly *assembly; 27 | Token **tokens; 28 | 29 | char *f; // filename (path) 30 | char *s; // source string 31 | Location location; 32 | } Lexer; 33 | 34 | #include "scanner.h" 35 | 36 | Lexer *lexer_init(char *, char *); 37 | void lexer_prepare(Lexer *); 38 | void lexer_start(Lexer *); 39 | 40 | void lexer_next(Lexer *); 41 | Token *lexer_getnext(Lexer *); 42 | void lexer_prev(Lexer *); 43 | Token *lexer_getprev(Lexer *); 44 | Token *lexer_getcurrent(Lexer *); 45 | Token *lexer_get(Lexer *, size_t); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /.github/workflows/first-interaction.yml: -------------------------------------------------------------------------------- 1 | name: First Interaction 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | pull_request: 8 | types: 9 | - opened 10 | 11 | jobs: 12 | welcome: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: First Interaction 16 | uses: actions/first-interaction@v3 17 | with: 18 | repo-token: ${{ secrets.GITHUB_TOKEN }} 19 | issue-message: | 20 | Welcome to our open-source community, and thank you for opening your first issue! 🎉 21 | 22 | We're thrilled to have you here. If you have any questions or need assistance, feel free to ask. Your contributions are valued and appreciated. 23 | 24 | Happy coding! 🚀 25 | pr-message: | 26 | Hey there! 👋 Thanks for submitting your first pull request. We're excited to see your contribution to our project. 27 | 28 | If you have any questions, need help, or want feedback, please don't hesitate to reach out. Your efforts make our community stronger. 29 | 30 | Keep up the great work! 💪 31 | -------------------------------------------------------------------------------- /tmp/js/src/cli/index.js: -------------------------------------------------------------------------------- 1 | const { help, helpWrong } = require('./commands/help'); 2 | const { version } = require('./commands/version'); 3 | const { run } = require('./commands/run'); 4 | 5 | /* 6 | * main 7 | */ 8 | const main = (args) => { 9 | args.splice(0, 2); // [ '/usr/bin/node', '/home/maxb/Projects/One/src/one.js', 'run' ] 10 | 11 | // console.log(args); 12 | // console.log(args.length); 13 | 14 | if (args.length === 0) { 15 | help(args); 16 | } else { 17 | parseCLI(args); 18 | } 19 | }; 20 | 21 | /* 22 | * removeFirst 23 | * arguments: args (Array of string) 24 | */ 25 | const removeFirst = (args) => { 26 | args.splice(0, 1); 27 | return args; // Not required! 28 | }; 29 | 30 | /* 31 | * parseCLI 32 | * arguments: args (Array of string) 33 | * note: args.length is more then 0 34 | */ 35 | const parseCLI = (args) => { 36 | if (args[0] === 'run') { 37 | removeFirst(args); 38 | run(args); 39 | } else if (args[0] === 'version') { 40 | removeFirst(args); 41 | version(args); 42 | } else { 43 | helpWrong(args); 44 | } 45 | }; 46 | 47 | module.exports = { 48 | main, 49 | }; 50 | -------------------------------------------------------------------------------- /tmp/c-new/src/error.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: error.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _ERROR_H_ 12 | #define _ERROR_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | typedef struct _location Location; 20 | typedef struct _token Token; 21 | 22 | typedef enum 23 | { 24 | ERROR, 25 | WARNING, 26 | NOTE, 27 | } ErrorLevel; 28 | 29 | typedef struct _error 30 | { 31 | char *filename; 32 | char *message; 33 | Location location; 34 | ErrorLevel level; 35 | } Error; 36 | 37 | typedef struct _errors 38 | { 39 | int error_count; 40 | int error_capacity; 41 | Error *errors; 42 | } ErrorsContainer; 43 | 44 | void ErrorsInit(ErrorsContainer *); 45 | 46 | void ErrorsPrint(FILE *, Error *); 47 | 48 | void ErrorsPrints(FILE *, ErrorsContainer *); 49 | 50 | void ErrorsFree(ErrorsContainer *); 51 | 52 | void ErrorsAdd(ErrorsContainer *, ErrorLevel, Location, char *); 53 | 54 | void error(char *); 55 | 56 | char *ErrorLevelName(ErrorLevel); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /tmp/c-old/src/lexer/source.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #include "source.h" 21 | 22 | Source source_new(void) 23 | { 24 | Source s; 25 | s.data = NULL; 26 | s.line = 1; 27 | s.column = 0; 28 | return s; 29 | } 30 | 31 | Source source_new_data(char *data) 32 | { 33 | Source s = source_new(); 34 | s.data = data; 35 | return s; 36 | } 37 | -------------------------------------------------------------------------------- /tmp/c-new2/argument.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: argument.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_ARG_H 12 | #define ONE_ARG_H 13 | 14 | #include 15 | 16 | typedef struct 17 | { 18 | bool help; 19 | bool version; 20 | bool debug; 21 | 22 | char **input_files; 23 | int input_files_count; 24 | 25 | int argc; 26 | char **argv; 27 | char **env; 28 | } Arguments; 29 | 30 | typedef enum 31 | { 32 | ARGUMENT_HELP, 33 | ARGUMENT_VERSION, 34 | ARGUMENT_DEBUG, 35 | 36 | ARGUMENT_FILE, 37 | ARGUMENT_ERROR, 38 | } ArgumentType; 39 | 40 | void argument_init(Arguments *args); 41 | 42 | ArgumentType argument_type(char *value); 43 | 44 | void argument_parse(int argc, char **argv, char **env, Arguments *args); 45 | 46 | void argument_free(Arguments *args); 47 | 48 | void argument_help(FILE *file, Arguments *args); 49 | 50 | void argument_version(FILE *file, Arguments *args); 51 | 52 | int argument_run_files(Arguments *args); 53 | 54 | int argument_run(Arguments *args); 55 | 56 | char *argument_type_name(ArgumentType type); 57 | 58 | #endif //ONE_ARG_H 59 | -------------------------------------------------------------------------------- /tmp/c/src/arg.c: -------------------------------------------------------------------------------- 1 | /** 2 | File: arg.c 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | #include "arg.h" 10 | 11 | const Args default_args = { 12 | .help = false, 13 | .version = false, 14 | .debug = false, 15 | 16 | .input_files = NULL, 17 | 18 | .argc = 0, 19 | .argv = NULL, 20 | .env = NULL, 21 | }; 22 | 23 | void parseArgs(int argc, char **argv, char **env, Args *args) 24 | { 25 | args->argc = argc; 26 | args->argv = argv; 27 | args->env = env; 28 | 29 | *args = default_args; 30 | args->input_files = vector_create(); 31 | 32 | for (int i = 1; i < argc; i++) 33 | { 34 | if (argv[i][0] == '-') 35 | { 36 | if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) 37 | { 38 | args->help = true; 39 | } 40 | else if (strcmp(argv[i], "-v") == 0 || 41 | strcmp(argv[i], "--version") == 0) 42 | { 43 | args->version = true; 44 | } 45 | else if (strcmp(argv[i], "-g") == 0 || 46 | strcmp(argv[i], "--debug") == 0) 47 | { 48 | args->debug = true; 49 | } 50 | } 51 | else 52 | { 53 | vector_add(&args->input_files, argv[i]); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tmp/c-new2/array.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: array.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include 13 | 14 | #include "error.h" 15 | 16 | #include "array.h" 17 | 18 | void array_init(Array *list) 19 | { 20 | debug("array_init"); 21 | 22 | list->count = 0; 23 | list->size = 0; 24 | list->data = NULL; 25 | } 26 | 27 | void array_push(Array *list, void *item) 28 | { 29 | debug("array_push"); 30 | 31 | if (list->count == list->size) 32 | { 33 | // Set size of new array to 4, and double size if it's next... 34 | list->size = list->size == 0 ? 4 : 2 * list->size; 35 | list->data = (void **)realloc(list->data, list->size * sizeof(void *)); 36 | } 37 | list->data[list->count] = item; 38 | list->count++; 39 | } 40 | 41 | void *array_pop(Array *list) 42 | { 43 | debug("array_pop"); 44 | 45 | list->count--; 46 | void *ret = list->data[list->count]; 47 | return ret; 48 | } 49 | 50 | void array_free(Array *list) 51 | { 52 | debug("array_free"); 53 | 54 | free(list->data); // it's void** 55 | list->count = 0; 56 | list->size = 0; 57 | list->data = NULL; 58 | } 59 | -------------------------------------------------------------------------------- /tmp/c-new2/file.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: file.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include 13 | 14 | #include "error.h" 15 | 16 | #include "file.h" 17 | 18 | char* file_reads(const char* path) 19 | { 20 | debug("file_reads"); 21 | debug("file_reads: %s", path); 22 | 23 | FILE* file = fopen(path, "rb"); 24 | if (file == NULL) 25 | { 26 | error_panic("Could not open file \"%s\".", path); 27 | exit(74); 28 | } 29 | 30 | fseek(file, 0L, SEEK_END); 31 | size_t fileSize = ftell(file); 32 | debug("file_reads: fileSize is %zu", fileSize); 33 | rewind(file); 34 | 35 | char* buffer = (char*)malloc(fileSize + 1); 36 | if (buffer == NULL) 37 | { 38 | error_panic("Not enough memory to read \"%s\".", path); 39 | exit(74); 40 | } 41 | size_t bytesRead = fread(buffer, sizeof(char), fileSize, file); 42 | debug("file_reads: bytesRead is %zu", bytesRead); 43 | if (bytesRead < fileSize) 44 | { 45 | error_panic("Could not read the \"%s\".", path); 46 | exit(74); 47 | } 48 | 49 | buffer[bytesRead] = '\0'; 50 | 51 | fclose(file); 52 | return buffer; 53 | } 54 | -------------------------------------------------------------------------------- /tmp/c-new2/interpret.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: interpret.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include 13 | 14 | #include "array.h" 15 | #include "error.h" 16 | #include "lexer.h" 17 | #include "token.h" 18 | #include "ast.h" 19 | #include "parser.h" 20 | #include "file.h" 21 | 22 | #include "interpret.h" 23 | 24 | extern Parser parser; 25 | 26 | int interpret_source(char* source, const char* path) 27 | { 28 | debug("interpret_source"); 29 | debug("interpret_source: %s", source); 30 | 31 | // https://www.freebsd.org/cgi/man.cgi?query=sysexits&apropos=0&sektion=0&manpath=FreeBSD+4.3-RELEASE&format=html 32 | int ret = EXIT_SUCCESS; 33 | 34 | lexer_init(source); 35 | 36 | parser_init(); 37 | parser.path = path; 38 | parser_scan(); 39 | lexer_free(); 40 | 41 | parser_start(); 42 | parser_free(); 43 | 44 | return ret; 45 | } 46 | 47 | int interpret_file(const char* path) 48 | { 49 | debug("interpret_file"); 50 | debug("interpret_file: %s", path); 51 | 52 | char* source = file_reads(path); 53 | int ret = interpret_source(source, path); 54 | free(source); 55 | return ret; 56 | } 57 | -------------------------------------------------------------------------------- /tmp/c-old/Makefile: -------------------------------------------------------------------------------- 1 | build: out one 2 | 3 | out: 4 | mkdir -p out 5 | mkdir -p out/lexer 6 | mkdir -p out/parser 7 | mkdir -p out/buffer 8 | mkdir -p out/compiler 9 | 10 | out/buffer/sds.o: src/buffer/sds.c src/buffer/sds.h src/buffer/sdsalloc.h src/buffer/testhelp.h 11 | gcc -c src/buffer/sds.c -o out/buffer/sds.o -Wall -Wextra 12 | 13 | out/lexer/token.o: src/lexer/token.c src/lexer/token.h 14 | gcc -c src/lexer/token.c -o out/lexer/token.o -Wall -Wextra 15 | 16 | out/lexer/source.o: src/lexer/source.c src/lexer/source.h 17 | gcc -c src/lexer/source.c -o out/lexer/source.o -Wall -Wextra 18 | 19 | out/lexer/lexer.o: src/lexer/lexer.c src/lexer/lexer.h 20 | gcc -c src/lexer/lexer.c -o out/lexer/lexer.o -Wall -Wextra 21 | 22 | out/one.o: out/buffer/sds.o src/one.c out/io.o out/lexer/token.o out/lexer/source.o out/lexer/lexer.o 23 | gcc \ 24 | src/one.c \ 25 | out/io.o \ 26 | out/buffer/sds.o \ 27 | out/lexer/lexer.o \ 28 | out/lexer/token.o \ 29 | out/lexer/source.o \ 30 | -o out/one.o -Wall -Wextra 31 | 32 | out/io.o: src/io.c src/io.h 33 | gcc -c src/io.c -o out/io.o -Wall -Wextra 34 | 35 | one: out/one.o 36 | mv out/one.o one 37 | 38 | clean: 39 | -rm -rf out/*/*.o 40 | -rm -rf out/*.o 41 | -rm -f one 42 | -rm -f src/*.o 43 | -rm -f src/*/*.o 44 | -------------------------------------------------------------------------------- /.github/workflows/super-linter.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: [pull_request] 4 | 5 | permissions: # added using https://github.com/step-security/secure-workflows 6 | contents: read 7 | 8 | jobs: 9 | build: 10 | permissions: 11 | contents: read # for actions/checkout to fetch code 12 | statuses: write # for super-linter/super-linter/slim to mark status of each linter run 13 | name: Super-Linter 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" 17 | uses: actions/checkout@v6 18 | with: 19 | # Full git history is needed to get a proper list of changed files within `super-linter` 20 | fetch-depth: 0 21 | - uses: super-linter/super-linter/slim@v8.3.0 22 | env: 23 | DEFAULT_BRANCH: main 24 | # VALIDATE_EDITORCONFIG: true 25 | VALIDATE_CLANG_FORMAT: true 26 | VALIDATE_DOCKERFILE_HADOLINT: true 27 | VALIDATE_GITHUB_ACTIONS: true 28 | VALIDATE_GITLEAKS: true 29 | VALIDATE_HTML: true 30 | VALIDATE_JSON: true 31 | VALIDATE_MARKDOWN: true 32 | VALIDATE_YAML: true 33 | VALIDATE_ALL_CODEBASE: true 34 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 35 | -------------------------------------------------------------------------------- /tmp/c-new/tests/4-print.et: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | print 1+(5)+((((((1)+40)+1)))); 4 | print 5*2-1; 5 | print "\n"; 6 | print 5*(2-1); 7 | print "\n"; 8 | print 5*(2-1); 9 | print "\n"; 10 | print (5+5)+1; 11 | //print 5; 12 | print "hel"; 13 | print "\n"; 14 | print true; 15 | print "\n"; 16 | print false; 17 | print "\n"; 18 | print 110; 19 | print "\n"; 20 | print 456.2; 21 | print "\n"; 22 | print 19.75; 23 | print "\n"; 24 | print null; 25 | print "\n"; 26 | print 9451673.16420; 27 | print "\n"; 28 | print 9451673; 29 | print "\n"; 30 | print 94516.16420; 31 | print "\n"; 32 | print 5+5; 33 | print "\n"; 34 | print 5+1; 35 | print "\n"; 36 | print null+null; 37 | print "\n"; 38 | print null+2; 39 | print "\n"; 40 | print false+5; 41 | print "\n"; 42 | print true+5; 43 | print "\n"; 44 | print 5*5; 45 | print "\n"; 46 | print 5+5+1; 47 | print "\n"; 48 | print 1+5*5*2*2; 49 | print "\n"; 50 | print 2+1; 51 | print "\n"; 52 | print 2+(3-1); 53 | print "\n"; 54 | print (((1))); 55 | print "\n"; 56 | print (1+((((((((2*3)-1)+3)/2)))))); 57 | print "\n"; 58 | print 5+5; 59 | return 9; 60 | } 61 | -------------------------------------------------------------------------------- /tmp/c-old/src/lexer/token.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #ifndef _TOKEN_H_ 21 | #define _TOKEN_H_ 22 | 23 | typedef struct 24 | { 25 | // LOG 26 | int line; 27 | int offset; 28 | 29 | // DATA 30 | unsigned int tok; 31 | char *name; 32 | char *value; 33 | } Token; 34 | 35 | #include "../one.h" 36 | 37 | enum one_token 38 | { 39 | TOK_START = 255 40 | #define DEF(id, str) , id 41 | #include "tokens.h" 42 | #undef DEF 43 | }; 44 | 45 | Token token_new(void); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Dockerize One Programming language 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | paths: 7 | - '.dockerignore' 8 | - '.github/workflows/docker-image.yml' 9 | - 'Dockerfile' 10 | - 'docker-compose.yml' 11 | 12 | permissions: # added using https://github.com/step-security/secure-workflows 13 | contents: read 14 | 15 | jobs: 16 | build-deploy: 17 | if: github.repository == 'One-Language/One' 18 | name: Build and Publish Docker image 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" 22 | uses: actions/checkout@v6 23 | - name: Set up QEMU 24 | uses: docker/setup-qemu-action@v3 25 | - name: Set up Docker Buildx 26 | uses: docker/setup-buildx-action@v3 27 | - name: Login to DockerHub 28 | uses: docker/login-action@v3 29 | with: 30 | username: ${{secrets.DOCKER_HUB_USERNAME}} 31 | password: ${{secrets.DOCKER_HUB_PASSWORD}} 32 | - name: Build and Push to DockerHub 33 | uses: docker/build-push-action@v6 34 | with: 35 | context: . 36 | push: true 37 | tags: onelangorg/one:latest 38 | cache-from: type=registry,ref=onelangorg/one:latest 39 | cache-to: type=inline 40 | -------------------------------------------------------------------------------- /src/builtins/string.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: builtins/string.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _ONE_BUILTINS_STRING_H_ 12 | #define _ONE_BUILTINS_STRING_H_ 13 | 14 | #include 15 | #include 16 | 17 | #define STRING_SIZE_INIT 16 18 | 19 | typedef struct 20 | { 21 | char* str; // a null terminated C string 22 | char* end; // a pointer to the null byte, to be able to repeatedly append 23 | // without using strlen() every time. 24 | size_t size; // currently allocated size for *str, so we know when we 25 | // need to grow. 26 | } string; 27 | 28 | /* 29 | * @function: string_new 30 | * @desctipion: Creates a new string, 31 | if there is not enough memory, will return a null pointer instead. 32 | * @arguments: nothing 33 | * @return: mallocated string 34 | */ 35 | string* string_new(); 36 | 37 | /* 38 | * @function: string_append 39 | * @description: Append to a string string, growing the allocated memory if needed 40 | on error, will return the longest string possible, which may truncate the suffix. 41 | * @arguments: string target, char* value want to be added 42 | * @return: void 43 | */ 44 | void string_append(string* ss, char* suffix); 45 | 46 | #endif // _ONE_BUILTINS_STRING_H_ 47 | -------------------------------------------------------------------------------- /src/builtins/array.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: builtins/array.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _ONE_BUILTINS_ARRAY_H_ 12 | #define _ONE_BUILTINS_ARRAY_H_ 13 | 14 | #include 15 | #include 16 | 17 | #include "error.h" 18 | 19 | typedef struct 20 | { 21 | int count; 22 | int size; 23 | void** data; 24 | } Array; 25 | 26 | /* 27 | * @function: array_init 28 | * @description: if you want to init the default value of a Array struct, you have to use this function. 29 | * @arguments: a pointer to Array 30 | * @return: void 31 | */ 32 | void array_init(Array* list); 33 | 34 | /* 35 | * @function: array_push 36 | * @description: if you want to add a item to your list 37 | * @arguments: a pointer to Array, a void-pointer of new value 38 | * @return: void 39 | */ 40 | void array_push(Array* list, void* item); 41 | 42 | /* 43 | * @function: array_push 44 | * @description: remove last value from your list 45 | * @arguments: a pointer to Array 46 | * @return: void 47 | */ 48 | void* array_pop(Array* list); 49 | 50 | /* 51 | * @function: array_free 52 | * @description: free your list 53 | * @arguments: a pointer to Array 54 | * @return: void 55 | */ 56 | void array_free(Array* list); 57 | 58 | #endif // _ONE_BUILTINS_ARRAY_H_ 59 | -------------------------------------------------------------------------------- /src/parser/lexer/lexer.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: parser/lexer/lexer.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _ONE_LEXER_LEXER_H_ 12 | #define _ONE_LEXER_LEXER_H_ 13 | 14 | #include "token.h" 15 | 16 | // typedef struct _token Token; 17 | // typedef enum _token_type TokenType; 18 | // typedef struct _location Location; 19 | 20 | typedef struct 21 | { 22 | Location pos; 23 | Location pos_end; 24 | 25 | const char* start; 26 | const char* current; 27 | 28 | int temp_column; 29 | } Lexer; 30 | 31 | extern Lexer lexer; 32 | 33 | /* 34 | * @function: lexer_init 35 | * @description: Set default value for the global `lexer` variable 36 | * @arguments: char*; input of One source-code program 37 | * @return: void; nothing 38 | */ 39 | void lexer_init(char* source); 40 | 41 | /* 42 | Move to the next token 43 | */ 44 | void advance(); 45 | 46 | /* 47 | Check if the current token is of type t 48 | */ 49 | bool peekFor(TokenType); 50 | 51 | /* 52 | * @function: lexer_free 53 | * @description: Free allocated memory for the lexer stage! TODO 54 | Only we have to check it's a user-defined variable or a registered Keyword refer to `keywords` variable 55 | * @arguments: nothing 56 | * @return: nothing, void 57 | */ 58 | void lexer_free(); 59 | 60 | #endif // _ONE_LEXER_LEXER_H_ 61 | -------------------------------------------------------------------------------- /tmp/c-new2/generator.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: generator.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_GENERATOR_H 12 | #define ONE_GENERATOR_H 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | LLVMModuleRef generator_init(AstRoot* root); 27 | 28 | bool generator_root(AstRoot* ast, char* file, LLVMMetadataRef file_meta, LLVMModuleRef module, LLVMDIBuilderRef dibuilder, LLVMBuilderRef builder); 29 | 30 | void generator_free(); 31 | 32 | LLVMMetadataRef generateTypeMeta(LLVMDIBuilderRef dibuilder, LLVMTypeRef type, LLVMMetadataRef file); 33 | 34 | bool generateFunctionBody(AstFunction* ast, LLVMModuleRef module, LLVMDIBuilderRef dibuilder, LLVMBuilderRef builder); 35 | 36 | bool generateFunctionShell(AstFunction* ast, char* file, LLVMModuleRef module, LLVMDIBuilderRef dibuilder, LLVMBuilderRef builder); 37 | 38 | LLVMValueRef generateValueInFunction(AstStatement* ast, LLVMDIBuilderRef dibuilder, LLVMBuilderRef builder); 39 | 40 | #endif //ONE_GENERATOR_H 41 | -------------------------------------------------------------------------------- /tmp/c-old/src/lexer/source.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #include "../one.h" 21 | 22 | #ifndef _SOURCE_H_ 23 | #define _SOURCE_H_ 24 | 25 | typedef struct 26 | { 27 | // if path equal to NULL, so current location 28 | char *path; 29 | 30 | // probably like to `input.one` 31 | char *filename; 32 | 33 | // content string 34 | char *data; 35 | 36 | // line number of current token 37 | int line; 38 | 39 | // column number of current token 40 | int column; // TODO: start_column, and end_column 41 | } Source; 42 | 43 | Source source_new(void); 44 | Source source_new_data(char *data); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /tmp/c-new/src/vm.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: vm.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "token.h" 12 | #include "vm.h" 13 | 14 | void vmInit(AstRoot* root) 15 | { 16 | root->functions = (Array*)malloc(sizeof(Array)); 17 | root->package = (char*)malloc(sizeof(char) * 1024); 18 | // strcpy(root->package,"max"); 19 | // printf("-->%s\n", root->package); 20 | } 21 | 22 | void vmStatement(AstStatement* stmt) 23 | { 24 | printf("[STMT] %s\n", astStatementName(stmt->type)); 25 | } 26 | void vmStatements(AstStatements* stmts) 27 | { 28 | for (size_t i = 0; i < stmts->count; i++) 29 | { 30 | vmStatement(stmts->data[i]); 31 | } 32 | } 33 | 34 | void vmBlock(AstBlock* block) 35 | { 36 | vmStatements(block->statements); 37 | } 38 | 39 | void vmFunction(AstFunction* func) 40 | { 41 | printf("[FUNC] %s\n", func->name); 42 | 43 | vmBlock(func->block); 44 | } 45 | 46 | void vmLog(AstRoot* root) 47 | { 48 | if (root->package == NULL || strlen(root->package) == 0 || strcmp(root->package, "") == 0) 49 | { 50 | root->package = "main"; 51 | } 52 | printf("=============== VM ===============\n"); 53 | 54 | printf("Package: %s\n", root->package); 55 | 56 | for (size_t i = 0; i < root->functions->count; i++) 57 | { 58 | vmFunction(root->functions->data[i]); 59 | } 60 | } 61 | 62 | void vmFree(AstRoot* root) 63 | { 64 | } 65 | -------------------------------------------------------------------------------- /src/parser/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: parser/main.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include 13 | 14 | #include "parser.h" 15 | 16 | int main(int argc, char** argv) 17 | { 18 | char* data; 19 | char* input_file; 20 | char* output_file; 21 | Token** tokens = NULL; 22 | 23 | if (argc == 2) 24 | { 25 | // printf("Error: pass the arguments correctly!\n"); 26 | // printf("./parser input.one output\n"); 27 | // return 1; 28 | input_file = "input"; 29 | data = argv[1]; 30 | tokens = tokenizer_string(data); 31 | } 32 | else if (argc == 3) 33 | { 34 | input_file = argv[1]; 35 | output_file = argv[2]; 36 | 37 | printf("Input file is: %s\n", input_file); 38 | printf("Output file is: %s\n", output_file); 39 | 40 | data = file_reads(input_file); 41 | tokens = tokenizer_string(data); 42 | } 43 | else 44 | { 45 | printf("Error: arguments are not correct!\n"); 46 | printf("./parser input.one output\n"); 47 | printf("./parser \"your input here as string\"\n"); 48 | return 1; 49 | } 50 | 51 | if (tokens != NULL) 52 | { 53 | lexer_trace(stdout, data, tokens); 54 | 55 | parser_init(input_file, data, tokens); 56 | 57 | AstFile* ast = parser_scan(); 58 | 59 | parser_trace(stdout, data, tokens, ast); 60 | 61 | parser_free(); 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /tmp/c-new2/error.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: error.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "lexer.h" 16 | #include "token.h" 17 | #include "array.h" 18 | #include "ast.h" 19 | #include "parser.h" 20 | 21 | #include "error.h" 22 | 23 | extern Parser parser; 24 | 25 | void error(ErrorType type, const char* format, ...) 26 | { 27 | debug("error"); 28 | 29 | va_list args; 30 | va_start(args, format); 31 | // TODO: Show error type with another custom color! 32 | fprintf(stderr, "%s: ", error_name(type)); 33 | vfprintf(stderr, format, args); 34 | va_end(args); 35 | 36 | Token* current_token = (*parser.tokens); 37 | fprintf(stderr, " at %s:%d:%d", parser.path == NULL ? "REPL" : parser.path, current_token->loc.line, current_token->loc.column); 38 | fputs("\n", stderr); 39 | 40 | if (type != ERROR_WARNING) 41 | { 42 | exit(1); 43 | } 44 | } 45 | 46 | char* error_name(ErrorType type) 47 | { 48 | debug("error_name"); 49 | 50 | switch (type) 51 | { 52 | case ERROR_TREE: 53 | return "TREE"; 54 | case ERROR_WARNING: 55 | return "WARNING"; 56 | case ERROR_PANIC: 57 | return "ERROR"; 58 | case ERROR_TOKEN: 59 | return "TOKEN ERROR"; 60 | case ERROR_PARSER: 61 | return "PARSER ERROR"; 62 | default: 63 | return "UNKNOWN ERROR"; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/builtins/file.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: builtins/file.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _ONE_BUILTINS_FILE_H_ 12 | #define _ONE_BUILTINS_FILE_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #include "error.h" 21 | 22 | /* 23 | * @function: file_reads 24 | * @description: read whole of a filepath 25 | * @arguments: const char* filepath 26 | * @return: char* 27 | */ 28 | char* file_reads(const char* filepath); 29 | 30 | /* 31 | * @function: file_convert_index_to_rc 32 | * @description: We get index of a position and point in string and looking to find its rows and column number and we will pass new value throw argument 33 | * @arguments: const char* input, int index, int* rows, int* columns 34 | * @return: bool / True or False; does that index exists or no. maybe current index is out of the file and filelength is less that `index` value! 35 | */ 36 | bool file_convert_index_to_rc(const char* input, int index, size_t* rows, size_t* columns); 37 | 38 | /* 39 | * @function: file_get_parent 40 | * @description: If you want to get directory path from a full-file path, this function will be useful and can return the directory path for you. 41 | * @arguments: const char* path 42 | * @return: char* 43 | */ 44 | char* file_get_parent(const char* path); 45 | 46 | #endif // _ONE_BUILTINS_FILE_H_ 47 | -------------------------------------------------------------------------------- /tmp/c-new2/tree.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: tree.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_TREE_H 12 | #define ONE_TREE_H 13 | 14 | void tree_show(FILE* f, AstRoot* root); 15 | 16 | void tree_show_functions(FILE* f, AstFunctions fns); 17 | 18 | void tree_show_function(FILE* f, AstFunction* fn); 19 | 20 | void tree_show_arguments(FILE* f, AstArguments args); 21 | 22 | void tree_show_block(FILE* f, AstBlock* block); 23 | 24 | void tree_show_statement(FILE* f, AstStatement* stmts); 25 | 26 | void tree_show_statements(FILE* f, AstStatements stmts); 27 | 28 | void tree_show_statement_print(FILE* f, AstStatement* stmt); 29 | 30 | void tree_show_statement_printnl(FILE* f, AstStatement* stmt); 31 | 32 | void tree_show_statement_printdb(FILE* f, AstStatement* stmt); 33 | 34 | void tree_show_statement_printdbnl(FILE* f, AstStatement* stmt); 35 | 36 | void tree_show_statement_while(FILE* f, AstStatement* stmt); 37 | 38 | void tree_show_statement_do(FILE* f, AstStatement* stmt); 39 | 40 | void tree_show_statement_for(FILE* f, AstStatement* stmt); 41 | 42 | void tree_show_statement_ret(FILE* f, AstStatement* stmt); 43 | 44 | void tree_show_statement_variable(FILE* f, AstStatement* stmt); 45 | 46 | void tree_show_statement_expression(FILE* f, AstStatement* stmt); 47 | 48 | void tree_show_expression(FILE* f, AstExpression* exprs); 49 | 50 | void tree_show_expressions(FILE* f, AstExpressions exprs); 51 | 52 | #endif //ONE_TREE_H 53 | -------------------------------------------------------------------------------- /tmp/js/src/scanner/parser.js: -------------------------------------------------------------------------------- 1 | const nearley = require('nearley'); 2 | const grammar = require('./grammar'); 3 | const fs = require('mz/fs'); 4 | const path = require('path'); 5 | const { fileExists, fileReads } = require('../cli/io/file'); 6 | const { parseAst } = require('../generator/vm'); 7 | 8 | const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar)); 9 | 10 | parser.reportError = function (token) { 11 | var tokenDisplay = token.type ? token.type + ' token: ' : ''; // + JSON.stringify(token.value !== undefined ? token.value : token); 12 | var lexerMessage = this.lexer.formatError(token, 'Syntax error'); 13 | // return `${lexerMessage}\n${tokenDisplay}`; 14 | return this.reportErrorCommon(lexerMessage, tokenDisplay); 15 | }; 16 | 17 | const parseFile = async (filepath) => { 18 | if (fileExists(filepath) === true) { 19 | const code = await fileReads(filepath); 20 | console.log(code); 21 | console.log('----------------------------------'); 22 | parseString(code); 23 | } else { 24 | console.warn(`Error: input source '${filepath}' is not readable!`); 25 | } 26 | }; 27 | 28 | const parseString = async (code) => { 29 | try { 30 | // parser.feed("a:=3.14"); 31 | parser.feed(code); 32 | 33 | const ast = parser.results[0]; 34 | 35 | console.log('Parse succeeded.'); 36 | // console.log(parser.results); 37 | 38 | parseAst(ast); 39 | } catch (e) { 40 | // console.log(e); 41 | console.log(`Parse failed: '${e.message}'`); 42 | } 43 | }; 44 | 45 | module.exports = { 46 | parser, 47 | parseFile, 48 | parseString, 49 | }; 50 | -------------------------------------------------------------------------------- /src/ast/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: ast/main.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include 13 | 14 | #include "ast.h" 15 | 16 | #include "../parser/parser.h" 17 | 18 | int main(int argc, char** argv) 19 | { 20 | char* data; 21 | char* input_file; 22 | char* output_file; 23 | Token** tokens = NULL; 24 | 25 | if (argc == 2) 26 | { 27 | // printf("Error: pass the arguments correctly!\n"); 28 | // printf("./parser input.one output\n"); 29 | // return 1; 30 | input_file = "input"; 31 | data = argv[1]; 32 | tokens = tokenizer_string(data); 33 | } 34 | else if (argc == 3) 35 | { 36 | input_file = argv[1]; 37 | output_file = argv[2]; 38 | 39 | printf("Input file is: %s\n", input_file); 40 | printf("Output file is: %s\n", output_file); 41 | 42 | data = file_reads(input_file); 43 | tokens = tokenizer_string(data); 44 | } 45 | else 46 | { 47 | printf("Error: arguments are not correct!\n"); 48 | printf("./parser input.one output\n"); 49 | printf("./parser \"your input here as string\"\n"); 50 | return 1; 51 | } 52 | 53 | if (tokens != NULL) 54 | { 55 | lexer_trace(stdout, data, tokens); 56 | 57 | parser_init(input_file, data, tokens); 58 | 59 | AstFile* ast = parser_scan(); 60 | 61 | parser_trace(stdout, data, tokens, ast); 62 | 63 | ast_init(input_file, data, tokens, ast); 64 | 65 | ast_trace(stdout, ast); 66 | 67 | ast_free(); 68 | 69 | parser_free(); 70 | } 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /tmp/c-new/src/lexer.test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct TestFunction 6 | { 7 | const char *name; 8 | 9 | int (*function)(void); 10 | }; 11 | 12 | int lexer_test1() 13 | { 14 | return 0; 15 | } 16 | int lexer_test2() 17 | { 18 | return 1; 19 | } 20 | int lexer_test3() 21 | { 22 | return 1; 23 | } 24 | int lexer_test4() 25 | { 26 | return 1; 27 | } 28 | int lexer_test5() 29 | { 30 | return 1; 31 | } 32 | int lexer_test6() 33 | { 34 | return 1; 35 | } 36 | int lexer_test7() 37 | { 38 | return 1; 39 | } 40 | int lexer_test8() 41 | { 42 | return 0; 43 | } 44 | int lexer_test9() 45 | { 46 | return 0; 47 | } 48 | int lexer_test10() 49 | { 50 | return 1; 51 | } 52 | 53 | struct TestFunction lexer_functions[] = { 54 | {"test1", lexer_test1}, 55 | {"test2", lexer_test2}, 56 | {"test3", lexer_test3}, 57 | {"test4", lexer_test4}, 58 | {"test5", lexer_test5}, 59 | {"test6", lexer_test6}, 60 | {"test7", lexer_test7}, 61 | {"test8", lexer_test8}, 62 | {"test9", lexer_test9}, 63 | {"test10", lexer_test10}, 64 | }; 65 | enum 66 | { 67 | LEXER_TEST_COUNT = sizeof(lexer_functions) / sizeof(lexer_functions[0]) 68 | }; 69 | 70 | void run_tests() 71 | { 72 | int res[LEXER_TEST_COUNT]; 73 | for (size_t i = 0; i < LEXER_TEST_COUNT; i++) 74 | { 75 | printf("[Test %d] ", i); 76 | res[i] = lexer_functions[i].function(); 77 | printf("%s: ", lexer_functions[i].name); 78 | if (res[i] == 1) 79 | { 80 | printf("Test Success.\n"); 81 | } 82 | else 83 | { 84 | printf("Test Failed!\n"); 85 | } 86 | } 87 | } 88 | 89 | int main() 90 | { 91 | run_tests(); 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /tmp/c-old/src/io.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #include "io.h" 21 | 22 | char *read_file(char *filename) 23 | { 24 | FILE *onefile = fopen(filename, "rb"); 25 | 26 | if (onefile == NULL) 27 | { 28 | return NULL; 29 | } 30 | 31 | fseek(onefile, 0L, SEEK_END); 32 | size_t onefilesize = ftell(onefile); 33 | rewind(onefile); 34 | char *onebuffer = (char *)malloc(onefilesize + 1); 35 | 36 | if (onebuffer == NULL) 37 | { 38 | error("error malloc onebuffer\n"); 39 | return NULL; 40 | } 41 | 42 | size_t onebytesread = fread(onebuffer, 1, onefilesize, onefile); 43 | if (onebytesread < onefilesize) 44 | { 45 | free(onebuffer); 46 | error("Could not read file.one\n"); 47 | return NULL; 48 | } 49 | 50 | onebuffer[onebytesread] = '\0'; 51 | 52 | fclose(onefile); 53 | return onebuffer; 54 | } 55 | -------------------------------------------------------------------------------- /tmp/c-old/src/lexer/lexer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #include "lexer.h" 21 | 22 | Token lexer_next(Source *src) 23 | { 24 | Token t = token_new(); 25 | 26 | while (*src->data != '\0') 27 | { 28 | t.offset++; 29 | if (*src->data == '\n') 30 | { 31 | printf("-->NEW LINE\n"); 32 | src->line++; 33 | } 34 | else 35 | { 36 | printf("-->%c\n", *src->data); 37 | if (*src->data >= 'a' && *src->data <= 'z') 38 | { 39 | *src->data++; 40 | 41 | t.tok = 1; 42 | t.name = "Char"; 43 | return t; 44 | } 45 | } 46 | *src->data++; 47 | } 48 | 49 | return t; 50 | } 51 | 52 | void lexer_scan(Source *src) 53 | { 54 | // printf("%s\n", data); 55 | Token t; 56 | while (1) 57 | { 58 | t = lexer_next(src); 59 | if (t.tok == 0) 60 | { 61 | break; 62 | } 63 | printf("-->%s\n", t.name); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tmp/c-old/src/one.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #ifndef _ONE_H_ 21 | #define _ONE_H_ 22 | 23 | // glibc, runtime library 24 | #include // NULL 25 | #include // printf, fopen, fclose 26 | #include // malloc, free 27 | #include // strcmp 28 | 29 | #define printf printf 30 | #define print printf 31 | 32 | // own inside library 33 | #include "io.h" 34 | #include "lexer/lexer.h" 35 | #include "lexer/source.h" 36 | #include "lexer/token.h" 37 | 38 | // primary data 39 | #define VERSION "0.3.0" 40 | #define ARCH "linux/amd64" 41 | 42 | // functions 43 | void error(char *message); 44 | void main_help(void); 45 | void main_badcommand(int argc, char *argv[]); 46 | void main_badparam(void); 47 | void main_badflag(void); 48 | void main_version(int argc); 49 | void main_parse(int argc, char *argv[]); 50 | int main(int argc, char *argv[]); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /tmp/c-new/input.one: -------------------------------------------------------------------------------- 1 | // Hello, World 2 | 3 | package main 4 | 5 | /** 6 | The One Programming Language 7 | _ _ 8 | / \ |\ | |_ Max Base 9 | \_/ | \| |_ Copyright 2021; One Language Contributors 10 | 11 | **/ 12 | 13 | // any global_var 14 | // const global_int = 110 15 | // const i32 global_int2 = 110 16 | 17 | i8 test1 { 18 | _ 4 19 | _ 4+3 20 | _ 5+1-2+6 21 | _ 5.5 - 0.1 * 5.2 + 6 / 24 22 | _ (2 + 15 * ( 25 - 13 ) / 1 - 4) + 10 / 2 23 | _ -3 24 | _ +4 25 | } 26 | 27 | /* 28 | i8 test2{ 29 | } 30 | 31 | i8 main { 32 | // _ 33 | _ 1 34 | __ 2 35 | !_ 3 36 | !__ 4 37 | __ 8, 9, 10 38 | } 39 | 40 | i8 ret_num { 41 | ret 54 42 | } 43 | 44 | i8 ret_my_num (i8 a) { 45 | ret a, 1, 10, 100, 1000 46 | } 47 | 48 | */ 49 | 50 | 51 | 52 | 53 | /* 54 | test() { 55 | u8 u_age = 32 56 | 57 | age = 5 58 | 59 | const c_police = 110 // You cannot change the value of this variable anymore! 60 | 61 | final c_my_phone 62 | c_my_phone = 91240405555 // You cannot change the value of this variable anymore! 63 | 64 | final c_my_phone2 = 912404011111 // You cannot change the value of this variable anymore! 65 | 66 | name = "Max" 67 | name = "Max!" 68 | 69 | string s_name = "Max" 70 | s_name = "Max?" 71 | 72 | // 5 73 | // 5.64.4 74 | // if 75 | 76 | if 5 > 4 { 77 | _ "Yes\n" 78 | // equal to 79 | __ "Yes" 80 | } 81 | 82 | names = ["Max", "Ali", "John"] 83 | string[] sa_names = ["Max", "Ali", "John"] 84 | for name in names { 85 | _ name 86 | } 87 | _ "Hello, World!" 88 | _ 1, 2, 3, 4, 5 89 | _ ret_num() 90 | _ ret_my_num(40) 91 | _ ret_my_num(10) 92 | } 93 | */ 94 | -------------------------------------------------------------------------------- /tmp/c-new/src/error.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: error.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "token.h" 12 | #include "error.h" 13 | 14 | void ErrorsInit(ErrorsContainer *errors) 15 | { 16 | errors->error_count = 0; 17 | errors->error_capacity = 10; 18 | } 19 | 20 | char *ErrorLevelName(ErrorLevel level) 21 | { 22 | switch (level) 23 | { 24 | case ERROR: 25 | return "ERROR"; 26 | break; 27 | case WARNING: 28 | return "WARNING"; 29 | break; 30 | case NOTE: 31 | return "NOTE"; 32 | break; 33 | default: 34 | return "UNKNOWN"; 35 | } 36 | } 37 | 38 | void ErrorsPrint(FILE *f, Error *error) 39 | { 40 | char *message; 41 | Location position; 42 | ErrorLevel level; 43 | printf("[%s] %s", ErrorLevelName(error->level), error->message); 44 | 45 | if (error->location.line != 0 && error->location.column != 0) 46 | { 47 | printf(" at line %d:%d", error->location.line, error->location.column); 48 | } 49 | 50 | if (error->filename != NULL) 51 | { 52 | printf(" file %s", error->filename); 53 | } 54 | 55 | printf("\n"); 56 | } 57 | 58 | void ErrorsPrints(FILE *f, ErrorsContainer *errors) 59 | { 60 | for (int i = 0; i < errors->error_count; i++) 61 | { 62 | ErrorsPrint(f, &errors->errors[i]); 63 | } 64 | } 65 | 66 | void ErrorsAdd(ErrorsContainer *errors, ErrorLevel level, Location location, char *message) 67 | { 68 | // error_count; 69 | // error_capacity; 70 | } 71 | 72 | void ErrorsFree(ErrorsContainer *errors) 73 | { 74 | } 75 | 76 | void error(char *message) 77 | { 78 | // TODO: this function will remove and ErrorsAdd() will be use! 79 | printf("[Error]: %s", message); 80 | } 81 | -------------------------------------------------------------------------------- /tmp/c/src/token.h: -------------------------------------------------------------------------------- 1 | /** 2 | File: token.h 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | typedef struct lexer Lexer; 10 | 11 | #ifndef _TOKEN_H_ 12 | #define _TOKEN_H_ 13 | 14 | #include "one.h" 15 | 16 | typedef enum tokenType 17 | { 18 | tok_eof = -1, 19 | 20 | tok_def = -2, 21 | tok_extern = -3, 22 | 23 | tok_identifier = -4, 24 | tok_number = -5, 25 | tok_string = -6, 26 | 27 | tok_define = -8, // '==' 28 | tok_div_int = -9, // '//' 29 | 30 | tok_type_i8 = -10, 31 | tok_type_i16 = -11, 32 | tok_type_i32 = -12, 33 | tok_type_i64 = -13, 34 | 35 | tok_type_u8 = -14, 36 | tok_type_u16 = -15, 37 | tok_type_u32 = -16, 38 | tok_type_u64 = -17, 39 | 40 | tok_type_f32 = -18, 41 | tok_type_f64 = -19, 42 | 43 | tok_type_bool = -20, 44 | tok_type_char = -21, 45 | tok_type_string = -22, 46 | 47 | tok_ret = -23, 48 | 49 | } TokenType; 50 | 51 | typedef struct token 52 | { 53 | TokenType type; 54 | size_t l; // line number: default is 1 55 | size_t c; // column number: default is 0 56 | 57 | int vint; 58 | sds vstring; 59 | } Token; 60 | 61 | void token_init(Lexer *); 62 | 63 | bool token_is_space(char); 64 | bool token_is_alpha(char); 65 | bool token_is_number(char); 66 | bool token_is_digit(char); 67 | bool token_is_ident(char); 68 | bool token_is_end(Lexer *); 69 | 70 | char token_nextchar(Lexer *); 71 | char token_prevchar(Lexer *); 72 | 73 | // Token* token_get(Lexer*); 74 | // Token* token_getnext(Lexer*); 75 | 76 | Token *token_next(Lexer *); 77 | Token *token_prev(Lexer *); 78 | 79 | void token_free(Token *); 80 | char *token_name(Token *); 81 | void token_log(Token *); 82 | Token *token_get(Lexer *); 83 | bool token_is_operator(Token *); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | documentation: 2 | - any: 3 | - changed-files: 4 | - any-glob-to-any-file: 5 | - docs/**/* 6 | - CONTRIBUTING.md 7 | - CONTRIBUTORS.md 8 | - LICENSE 9 | - MISSION_STATEMENT.md 10 | - README.md 11 | - README_DOCKER.md 12 | 13 | examples: 14 | - any: 15 | - changed-files: 16 | - any-glob-to-any-file: 17 | - example/**/* 18 | 19 | github: 20 | - any: 21 | - changed-files: 22 | - any-glob-to-any-file: 23 | - .github/**/* 24 | 25 | license-templates: 26 | - any: 27 | - changed-files: 28 | - any-glob-to-any-file: 29 | - license-templates/**/* 30 | 31 | scripts: 32 | - any: 33 | - changed-files: 34 | - any-glob-to-any-file: 35 | - scripts/**/* 36 | 37 | src: 38 | - any: 39 | - changed-files: 40 | - any-glob-to-any-file: 41 | - src/**/* 42 | 43 | tests: 44 | - any: 45 | - changed-files: 46 | - any-glob-to-any-file: 47 | - .clang-format 48 | - .dockerignore 49 | - .editorconfig 50 | - .gitattributes 51 | - .gitignore 52 | - .hound.yml 53 | - .mergify.yml 54 | - .pre-commit-config.yaml 55 | - CMakeLists.txt 56 | - CODEOWNERS 57 | - Dockerfile 58 | - Makefile 59 | - codespell.txt 60 | - docker-compose.yml 61 | - mlc_config.json 62 | - test/**/* 63 | 64 | tmp: 65 | - any: 66 | - changed-files: 67 | - any-glob-to-any-file: 68 | - tmp/**/* 69 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: [pull_request] 4 | 5 | permissions: # added using https://github.com/step-security/secure-workflows 6 | contents: read 7 | 8 | jobs: 9 | pre-commit: 10 | name: Run pre-commit # https://pre-commit.com/ 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" 14 | uses: actions/checkout@v6 15 | - uses: actions/setup-python@v6 # https://www.python.org/ 16 | with: 17 | python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax 18 | architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified 19 | - name: Install dependencies # https://pip.pypa.io/en/stable/ 20 | run: | 21 | python -m pip install --upgrade pip 22 | pip install pre-commit 23 | - name: Set PY 24 | run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> "$GITHUB_ENV" 25 | - uses: actions/cache@v5 26 | with: 27 | path: ~/.cache/pre-commit 28 | key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} 29 | - name: Run pre-commit 30 | run: pre-commit run --all-files 31 | test-git-clone: 32 | timeout-minutes: 10 33 | name: "Test git clone on ${{ matrix.os }}" 34 | runs-on: "${{ matrix.os }}" 35 | strategy: 36 | fail-fast: false 37 | matrix: 38 | include: 39 | - {os: ubuntu-latest} 40 | - {os: ubuntu-20.04} 41 | - {os: macos-latest} 42 | - {os: windows-latest} 43 | steps: 44 | - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" 45 | uses: actions/checkout@v6 46 | with: 47 | fetch-depth: 0 48 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/join_doc_team.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Join the Documentation Team 3 | about: I want to join the Documentation Team. 4 | title: "[Join] Documentation team" 5 | labels: Join 6 | assignees: BaseMax 7 | --- 8 | 9 | Hi, One Language Team; 10 | I'm here to tell you I'm interested in this compiler project and want to help and participate in this open-source project. 11 | 12 | ## Introduction 13 | 14 | 15 | ## Your correct role 16 | 17 | I'm a Bachelor's student of computer science at the University of Cambridge. 18 | And I have a part-time job as a QA Engineer at X company in Thailand. 19 | 20 | ## Timezone 21 | 22 | Brisbane, Australia; UTC/GMT +10 hours 23 | 24 | ## Language Proficiency 25 | 26 | List of languages you know with their proficiency level (Beginner, Intermediate, Expert): 27 | 28 | 29 | - **Spanish**: Expert (Native) 30 | - **English**: Expert 31 | - **Tibetan**: Intermediate 32 | 33 | ## Programming/IT knowledge 34 | 35 | Tell us more about your Programming/IT knowledge: 36 | 37 | E.g. - I have written basic programs in Java during my graduation. I have installed Linux and Windows OS on my laptop, I have some knowledge of computer hardware etc.. 38 | 39 | Tell us your opinion about "One Language" and creating a new language: 40 | 41 | 42 | ----------- 43 | 44 | 47 | 48 | Best Regards; 49 | -------------------------------------------------------------------------------- /src/builtins/array.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: builtins/array.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "array.h" 12 | 13 | /* 14 | * @function: array_init 15 | * @description: if you want to init the default value of a Array struct, you have to use this function. 16 | * @arguments: a pointer to Array 17 | * @return: void 18 | */ 19 | void array_init(Array *list) 20 | { 21 | debug_builtins("array_init"); 22 | 23 | list->count = 0; 24 | list->size = 0; 25 | list->data = NULL; 26 | } 27 | 28 | /* 29 | * @function: array_push 30 | * @description: if you want to add a item to your list 31 | * @arguments: a pointer to Array, a void-pointer of new value 32 | * @return: void 33 | */ 34 | void array_push(Array *list, void *item) 35 | { 36 | debug_builtins("array_push"); 37 | 38 | if (list->count == list->size) 39 | { 40 | // Set size of new array to 4, and double size if it's next... 41 | list->size = list->size == 0 ? 4 : 2 * list->size; 42 | list->data = (void **)realloc(list->data, list->size * sizeof(void *)); 43 | } 44 | list->data[list->count] = item; 45 | list->count++; 46 | } 47 | 48 | /* 49 | * @function: array_push 50 | * @description: remove last value from your list 51 | * @arguments: a pointer to Array 52 | * @return: void 53 | */ 54 | void *array_pop(Array *list) 55 | { 56 | debug_builtins("array_pop"); 57 | 58 | list->count--; 59 | void *ret = list->data[list->count]; 60 | return ret; 61 | } 62 | 63 | /* 64 | * @function: array_free 65 | * @description: free your list 66 | * @arguments: a pointer to Array 67 | * @return: void 68 | */ 69 | void array_free(Array *list) 70 | { 71 | debug_builtins("array_free"); 72 | 73 | free(list->data); // it's void** 74 | list->count = 0; 75 | list->size = 0; 76 | list->data = NULL; 77 | } 78 | -------------------------------------------------------------------------------- /tmp/c/src/one.c: -------------------------------------------------------------------------------- 1 | /** 2 | File: one.c 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | #include "one.h" 10 | #include "arg.h" 11 | #include "lexer.h" 12 | #include "parser.h" 13 | #include "scanner.h" 14 | #include "token.h" 15 | 16 | void error(char *format, ...) 17 | { 18 | // fprintf(stderr, message); 19 | va_list ap; 20 | va_start(ap, format); 21 | (void)vfprintf(stderr, format, ap); 22 | va_end(ap); 23 | } 24 | 25 | void help(Args *args) 26 | { 27 | puts("./one filename.one"); 28 | puts("One version: " ONE_VERSION); 29 | } 30 | 31 | char *file_read(char *filename) 32 | { 33 | FILE *onefile = fopen(filename, "rb"); 34 | if (onefile == NULL) 35 | { 36 | return NULL; 37 | } 38 | fseek(onefile, 0L, SEEK_END); 39 | size_t onefilesize = ftell(onefile); 40 | rewind(onefile); 41 | char *onebuffer = (char *)malloc(onefilesize + 1); 42 | if (onebuffer == NULL) 43 | { 44 | error("error malloc onebuffer\n"); 45 | return NULL; 46 | } 47 | size_t onebytesread = fread(onebuffer, 1, onefilesize, onefile); 48 | if (onebytesread < onefilesize) 49 | { 50 | free(onebuffer); 51 | error("Could not read file.one\n"); 52 | return NULL; 53 | } 54 | onebuffer[onebytesread] = '\0'; 55 | fclose(onefile); 56 | return onebuffer; 57 | } 58 | 59 | void file_parse(char *filename) 60 | { 61 | char *input = file_read(filename); 62 | Lexer *lex = lexer_init(filename, input); 63 | lexer_start(lex); 64 | } 65 | 66 | int main(int argc, char **argv, char **env) 67 | { 68 | int ret = EXIT_SUCCESS; 69 | Args args; 70 | parseArgs(argc, argv, env, &args); 71 | 72 | if (args.help) 73 | { 74 | help(&args); 75 | } 76 | else if (args.version) 77 | { 78 | fprintf(stderr, "Version: %s\n", ONE_VERSION); 79 | } 80 | else if (vector_size(args.input_files) > 0) 81 | { 82 | file_parse(argv[1]); 83 | ret = EXIT_SUCCESS; // TODO 84 | } 85 | 86 | return ret; 87 | } 88 | -------------------------------------------------------------------------------- /tmp/c-new/src/parser.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: parser.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _PARSER_H_ 12 | #define _PARSER_H_ 13 | 14 | typedef struct _token Token; 15 | typedef struct _location Location; 16 | typedef struct _errors ErrorsContainer; 17 | typedef struct _lexer Lexer; 18 | typedef struct _ast_expression AstExpression; 19 | 20 | typedef struct _parser 21 | { 22 | Lexer *lex; 23 | } Parser; 24 | 25 | Parser *parserInit(Lexer *, ErrorsContainer *); 26 | 27 | int parserCheck(Parser *, ErrorsContainer *); 28 | 29 | void parserFree(Parser *); 30 | 31 | bool tokenIsUserType(Parser *, ErrorsContainer *); 32 | 33 | bool tokenIsPrimaryType(Parser *, ErrorsContainer *); 34 | 35 | bool parserExceptTokenGo(Parser *, TokenType, ErrorsContainer *); 36 | 37 | bool parserExceptToken(Parser *, TokenType, ErrorsContainer *); 38 | 39 | bool parserHasToken(Parser *, TokenType, ErrorsContainer *); 40 | 41 | AstExpression *parseExpression_1(Parser *, ErrorsContainer *); 42 | AstExpression *parseExpression_2(Parser *, ErrorsContainer *); 43 | AstExpression *parseExpression_3(Parser *, ErrorsContainer *); 44 | AstExpression *parseExpression_4(Parser *, ErrorsContainer *); 45 | AstExpression *parseExpression_5(Parser *, ErrorsContainer *); 46 | AstExpression *parseExpression_6(Parser *, ErrorsContainer *); 47 | AstExpression *parseExpression_7(Parser *, ErrorsContainer *); 48 | AstExpression *parseExpression_8(Parser *, ErrorsContainer *); 49 | AstExpression *parseExpression_9(Parser *, ErrorsContainer *); 50 | AstExpression *parseExpression_10(Parser *, ErrorsContainer *); 51 | AstExpression *parseExpression_11(Parser *, ErrorsContainer *); 52 | AstExpression *parseExpression_12(Parser *, ErrorsContainer *); 53 | AstExpression *parseExpression_13(Parser *, ErrorsContainer *); 54 | AstExpression *parseExpression(Parser *, ErrorsContainer *); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/parser/lexer/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: parser/lexer/main.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "lexer.h" 17 | extern Token* current; 18 | 19 | int main(int argc, char** argv) 20 | { 21 | char* input_file; 22 | char* output_file; 23 | FILE* file_out = stdout; 24 | 25 | if (argc == 1) 26 | { 27 | printf("Error: arguments are not correct!\n"); 28 | printf("./lexer input.one output.tokens\n"); 29 | printf("./lexer \"your input here as string\"\n"); 30 | return 1; 31 | } 32 | else if (argc == 2) 33 | { 34 | input_file = argv[1]; 35 | } 36 | else if (argc == 3) 37 | { 38 | input_file = argv[1]; 39 | output_file = argv[2]; 40 | file_out = fopen(output_file, "wa+"); 41 | 42 | if (!file_out) 43 | { 44 | fprintf(stderr, "Error: it's unable to write output to %s file!\n", output_file); 45 | exit(1); 46 | } 47 | } 48 | 49 | char* data = file_reads(input_file); 50 | lexer_init(data); 51 | 52 | // Lexer Tracer for debugging 53 | while (!peekFor(TOKEN_EOF)) 54 | { 55 | char* t_name = token_name(current->type); 56 | 57 | bool has1 = file_convert_index_to_rc(data, current->pos.index, ¤t->pos.line, ¤t->pos.column); 58 | bool has2 = file_convert_index_to_rc(data, current->pos_end.index, ¤t->pos_end.line, ¤t->pos_end.column); 59 | 60 | fprintf(file_out, "[%zu:%zu] [%zu:%zu - %zu:%zu] %s", current->pos.tokens, current->length, current->pos.line, current->pos.column, current->pos_end.line, current->pos_end.column, t_name); 61 | 62 | if (current->value != NULL) 63 | { 64 | fprintf(file_out, ": \"%s\"", current->value); 65 | } 66 | fprintf(file_out, "\n"); 67 | 68 | advance(); 69 | } 70 | 71 | assert(current->type == TOKEN_EOF); 72 | free(current); 73 | lexer_free(); 74 | free(data); 75 | if (file_out != stdout) fclose(file_out); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /src/builtins/error.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: builtins/error.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include 12 | 13 | #include "error.h" 14 | 15 | // Global variable(s) 16 | extern Lexer lexer; 17 | 18 | /* 19 | * @function: error 20 | * @description: Occur a error/warning at the runtime, If that was not a warning so we will exit the program immediately 21 | * @arguments: ErrorType, int line, const char* file, const char* function, const char* format varg... 22 | * @return: void; nothing 23 | */ 24 | void error(ErrorType type, int line, const char* file, const char* function, const char* format, ...) 25 | { 26 | debug("error"); 27 | 28 | va_list args; 29 | va_start(args, format); 30 | // TODO: Show error type with another custom color! 31 | fprintf(stderr, "%s: ", error_name(type)); 32 | vfprintf(stderr, format, args); 33 | va_end(args); 34 | 35 | // fprintf(stderr, "[at %s line %d in %s]", file, line, function); 36 | 37 | Location loc; 38 | char* path = NULL; 39 | 40 | #ifdef _ONE_PARSER_ 41 | Token* current_token = (*parser.tokens); 42 | loc = current_token->pos; 43 | path = parser.path; 44 | #elif defined _ONE_LEXER_ 45 | loc = lexer.loc; 46 | #endif 47 | 48 | path = (path == NULL) ? "REPL" : path; 49 | fprintf(stderr, " at %s:%zu:%zu", path, loc.line, loc.column); 50 | fputs("\n", stderr); 51 | 52 | if (type != ERROR_WARNING) 53 | { 54 | exit(1); 55 | } 56 | } 57 | 58 | /* 59 | * @function: error_name 60 | * @description: Convert a ErrorType value to char*, mapping to its name 61 | * @arguments: ErrorType 62 | * @return: char* 63 | */ 64 | char* error_name(ErrorType type) 65 | { 66 | debug("error_name"); 67 | 68 | switch (type) 69 | { 70 | case ERROR_TREE: 71 | return "TREE"; 72 | case ERROR_WARNING: 73 | return "WARNING"; 74 | case ERROR_PANIC: 75 | return "ERROR"; 76 | case ERROR_TOKEN: 77 | return "TOKEN ERROR"; 78 | case ERROR_PARSER: 79 | return "PARSER ERROR"; 80 | default: 81 | return "UNKNOWN ERROR"; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | LABEL name="The One Programming Language" 3 | 4 | # LLVM version 5 | ARG LLVM_VERSION=12.0.1 6 | 7 | # LLVM dependencies 8 | RUN apk --no-cache add \ 9 | autoconf \ 10 | automake \ 11 | cmake \ 12 | freetype-dev \ 13 | g++ \ 14 | gcc \ 15 | libxml2-dev \ 16 | linux-headers \ 17 | make \ 18 | musl-dev \ 19 | ncurses-dev \ 20 | python3 py3-pip \ 21 | git 22 | 23 | # Build and install LLVM 24 | RUN wget -q "https://github.com/llvm/llvm-project/archive/llvmorg-${LLVM_VERSION}.tar.gz" || { echo "Error downloading LLVM version ${LLVM_VERSION}" ; exit 1; } 25 | 26 | RUN tar zxf llvmorg-${LLVM_VERSION}.tar.gz && rm llvmorg-${LLVM_VERSION}.tar.gz 27 | 28 | RUN cd llvm-project-llvmorg-${LLVM_VERSION} && mkdir build 29 | 30 | WORKDIR /llvm-project-llvmorg-${LLVM_VERSION}/build 31 | 32 | RUN cmake ../llvm \ 33 | -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD="X86" \ 34 | -DLLVM_ENABLE_PROJECTS="clang;lld" \ 35 | -DCMAKE_BUILD_TYPE=MinSizeRel \ 36 | || { echo 'Error running CMake for LLVM' ; exit 1; } 37 | 38 | RUN make -j$(nproc) || { echo 'Error building LLVM' ; exit 1; } 39 | RUN make install || { echo 'Error installing LLVM' ; exit 1; } 40 | RUN cd ../.. && rm -rf llvm-project-llvmorg-${LLVM_VERSION} 41 | 42 | ENV CXX=clang++ 43 | ENV CC=clang 44 | 45 | # pre-commit installation 46 | RUN pip install --no-cache-dir pre-commit 47 | 48 | # Work directory setup 49 | COPY . /One 50 | WORKDIR /One 51 | 52 | # CMake configuration & building 53 | RUN mkdir build 54 | RUN cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ -H/One -B/One/build -G "Unix Makefiles" 55 | RUN cmake --build ./build --config Debug --target all -j 6 -- 56 | 57 | # Change directory to build 58 | WORKDIR /One/build 59 | 60 | # Running example input.one 61 | RUN ./lexer ../src/input.one log 62 | RUN cat log 63 | 64 | # Running tests 65 | RUN ./lexer_test 66 | RUN ./parser_test 67 | RUN ./argument_test 68 | 69 | # Tests Dashboard 70 | CMD ctest --output-on-failure 71 | -------------------------------------------------------------------------------- /tmp/c-new/src/compile.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: compile.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "arg.h" 12 | #include "file.h" 13 | #include "token.h" 14 | #include "lexer.h" 15 | #include "parser.h" 16 | #include "error.h" 17 | #include "compile.h" 18 | #include "parser.h" 19 | 20 | void link(Args *args, ErrorsContainer *errors) 21 | { 22 | // TODO, link all object file(s) and create final executable file! 23 | } 24 | 25 | int compileFileString(char *filename, char *input, ErrorsContainer *errors) 26 | { 27 | Lexer *lex = lexerInit(filename, input, errors); 28 | int res = lexerCheck(lex, errors); // start to pars all of tokens 29 | 30 | if (res == EXIT_SUCCESS) 31 | { 32 | lexerLog(lex); // Display log list of tokens 33 | 34 | Parser *pars = parserInit(lex, errors); 35 | res = parserCheck(pars, errors); 36 | 37 | lexerFree(lex); // free and remove Lexer object 38 | parserFree(pars); // free and remove Parser object 39 | 40 | if (res == EXIT_SUCCESS) 41 | { 42 | // TODO: Ast Tree 43 | // TODO: Code generation 44 | // Ast *ast = astInit(pars, errors); 45 | // res = astCheck(ast, errors); 46 | // astFree(ast); 47 | } 48 | } 49 | 50 | return res; 51 | } 52 | 53 | int compileString(char *input, ErrorsContainer *errors) 54 | { 55 | return compileFileString(NULL, input, errors); 56 | } 57 | 58 | int compileFile(char *filename, ErrorsContainer *errors) 59 | { 60 | char *input = fileReads(filename, errors); 61 | return compileFileString(filename, input, errors); 62 | } 63 | 64 | int compile(Args *args, ErrorsContainer *errors) 65 | { 66 | if (args->input_files_count == 0) 67 | return EXIT_FAILURE; 68 | 69 | int res = EXIT_SUCCESS; 70 | for (int i = 0; i < args->input_files_count; i++) 71 | { 72 | printf("-->%s\n", args->input_files[i]); 73 | int res_now = compileFile(args->input_files[i], errors); 74 | 75 | if (res_now != EXIT_SUCCESS) 76 | { 77 | res = res_now; 78 | break; // TODO: stop to parse other files or no? 79 | } 80 | } 81 | 82 | link(args, errors); 83 | 84 | return EXIT_SUCCESS; 85 | } 86 | -------------------------------------------------------------------------------- /tmp/c/src/sdsalloc.h: -------------------------------------------------------------------------------- 1 | /* SDSLib 2.0 -- A C dynamic strings library 2 | * 3 | * Copyright (c) 2006-2015, Salvatore Sanfilippo 4 | * Copyright (c) 2015, Oran Agra 5 | * Copyright (c) 2015, Redis Labs, Inc 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * * Neither the name of Redis nor the names of its contributors may be used 17 | * to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | /* SDS allocator selection. 34 | * 35 | * This file is used in order to change the SDS allocator at compile time. 36 | * Just define the following defines to what you want to use. Also add 37 | * the include of your alternate allocator if needed (not needed in order 38 | * to use the default libc allocator). */ 39 | 40 | #define s_malloc malloc 41 | #define s_realloc realloc 42 | #define s_free free 43 | -------------------------------------------------------------------------------- /tmp/c-old/src/buffer/sdsalloc.h: -------------------------------------------------------------------------------- 1 | /* SDSLib 2.0 -- A C dynamic strings library 2 | * 3 | * Copyright (c) 2006-2015, Salvatore Sanfilippo 4 | * Copyright (c) 2015, Oran Agra 5 | * Copyright (c) 2015, Redis Labs, Inc 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * * Neither the name of Redis nor the names of its contributors may be used 17 | * to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | /* SDS allocator selection. 34 | * 35 | * This file is used in order to change the SDS allocator at compile time. 36 | * Just define the following defines to what you want to use. Also add 37 | * the include of your alternate allocator if needed (not needed in order 38 | * to use the default libc allocator). */ 39 | 40 | #define s_malloc malloc 41 | #define s_realloc realloc 42 | #define s_free free 43 | -------------------------------------------------------------------------------- /tmp/c/src/lexer.c: -------------------------------------------------------------------------------- 1 | /** 2 | File: lexer.c 3 | _ _ 4 | / \ |\ | |_ Author: Max Base 5 | \_/ | \| |_ Copyright 2021; One Language Contributors 6 | 7 | **/ 8 | 9 | #include "lexer.h" 10 | #include "parser.h" 11 | #include "scanner.h" 12 | #include "token.h" 13 | 14 | Lexer *lexer_init(char *filename, char *input) 15 | { 16 | #ifdef DEBUG 17 | printf("[lexer_init]\n"); 18 | #endif 19 | 20 | Lexer *lex = (Lexer *)malloc(sizeof(Lexer)); 21 | lex->f = filename; 22 | lex->s = input; 23 | lex->tokens = vector_create(); 24 | lex->location.t = 0; 25 | lex->location.i = 0; 26 | lex->location.l = 0; 27 | lex->location.c = 0; 28 | 29 | #ifdef DEBUG 30 | // printf("-->%s\n", lex->s); 31 | // printf("-->%s\n", lex->f); 32 | // printf("\n"); 33 | #endif 34 | 35 | return lex; 36 | } 37 | 38 | void lexer_prepare(Lexer *lex) 39 | { 40 | #ifdef DEBUG 41 | printf("[lexer_prepare]\n"); 42 | #endif 43 | 44 | token_init(lex); 45 | 46 | Token *t; 47 | while (token_is_end(lex) != true) 48 | { 49 | // printf("===>\n"); 50 | t = token_next(lex); 51 | vector_add(&lex->tokens, t); 52 | 53 | #ifdef DEBUG 54 | printf("[lexer_prepare]"); 55 | token_log(t); 56 | #endif 57 | } 58 | 59 | // Adding tok_eof at end of tokens vector 60 | t = token_next(lex); 61 | if (token_is_end(lex) == true) 62 | vector_add(&lex->tokens, t); 63 | 64 | // exit(1); 65 | 66 | #ifdef DEBUG 67 | printf("[lexer_prepare] End\n\n"); 68 | #endif 69 | } 70 | 71 | void lexer_start(Lexer *lex) 72 | { 73 | #ifdef DEBUG 74 | printf("[lexer_start]\n"); 75 | #endif 76 | 77 | lexer_prepare(lex); 78 | parser(lex); 79 | } 80 | 81 | void lexer_next(Lexer *lex) 82 | { 83 | lex->location.t++; 84 | } 85 | 86 | Token *lexer_getnext(Lexer *lex) 87 | { 88 | lexer_next(lex); 89 | return lex->tokens[lex->location.t]; 90 | } 91 | 92 | void lexer_prev(Lexer *lex) 93 | { 94 | lex->location.t--; 95 | } 96 | 97 | Token *lexer_getprev(Lexer *lex) 98 | { 99 | lexer_prev(lex); 100 | return lex->tokens[lex->location.t]; 101 | } 102 | 103 | Token *lexer_getcurrent(Lexer *lex) 104 | { 105 | return lex->tokens[lex->location.t]; 106 | } 107 | 108 | Token *lexer_get(Lexer *lex, size_t index) 109 | { 110 | return lex->tokens[index]; 111 | } 112 | -------------------------------------------------------------------------------- /tmp/c/src/vec.h: -------------------------------------------------------------------------------- 1 | // 2 | // vec.h 3 | // 4 | // Created by Mashpoe on 2/26/19. 5 | // 6 | 7 | #ifndef vec_h 8 | #define vec_h 9 | 10 | #include 11 | #include 12 | 13 | typedef void *vector; // you can't use this to store vectors, it's just used 14 | // internally as a generic type 15 | typedef size_t vec_size_t; // stores the number of elements 16 | typedef unsigned char vec_type_t; // stores the number of bytes for a type 17 | 18 | typedef int *vec_int; 19 | typedef char *vec_char; 20 | 21 | #ifndef _MSC_VER 22 | 23 | // shortcut defines 24 | 25 | // vec_addr is a vector* (aka type**) 26 | #define vector_add_asg(vec_addr) \ 27 | ((typeof(*vec_addr))(_vector_add((vector *)vec_addr, sizeof(**vec_addr)))) 28 | #define vector_insert_asg(vec_addr, pos) \ 29 | ((typeof(*vec_addr))(_vector_insert((vector *)vec_addr, sizeof(**vec_addr), pos))) 30 | 31 | #define vector_add(vec_addr, value) (*vector_add_asg(vec_addr) = value) 32 | #define vector_insert(vec_addr, pos, value) \ 33 | (*vector_insert_asg(vec_addr, pos) = value) 34 | 35 | #else 36 | 37 | #define vector_add_asg(vec_addr, type) \ 38 | ((type *)_vector_add((vector *)vec_addr, sizeof(type))) 39 | #define vector_insert_asg(vec_addr, type, pos) \ 40 | ((type *)_vector_insert((vector *)vec_addr, sizeof(type), pos)) 41 | 42 | #define vector_add(vec_addr, type, value) \ 43 | (*vector_add_asg(vec_addr, type) = value) 44 | #define vector_insert(vec_addr, type, pos, value) \ 45 | (*vector_insert_asg(vec_addr, type, pos) = value) 46 | 47 | #endif 48 | 49 | // vec is a vector (aka type*) 50 | #define vector_erase(vec, pos, len) \ 51 | (_vector_erase((vector *)vec, sizeof(*vec), pos, len)) 52 | #define vector_remove(vec, pos) \ 53 | (_vector_remove((vector *)vec, sizeof(*vec), pos)) 54 | 55 | #define vector_copy(vec) (_vector_copy((vector *)vec, sizeof(*vec))) 56 | 57 | vector vector_create(void); 58 | 59 | void vector_free(vector vec); 60 | 61 | vector _vector_add(vector *vec_addr, vec_type_t type_size); 62 | 63 | vector _vector_insert(vector *vec_addr, vec_type_t type_size, vec_size_t pos); 64 | 65 | void _vector_erase(vector *vec_addr, vec_type_t type_size, vec_size_t pos, vec_size_t len); 66 | 67 | void _vector_remove(vector *vec_addr, vec_type_t type_size, vec_size_t pos); 68 | 69 | void vector_pop(vector vec); 70 | 71 | vector _vector_copy(vector vec, vec_type_t type_size); 72 | 73 | vec_size_t vector_size(vector vec); 74 | 75 | vec_size_t vector_get_alloc(vector vec); 76 | 77 | #endif /* vec_h */ 78 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | AccessModifierOffset: '-4' 3 | AlignAfterOpenBracket: DontAlign 4 | AlignConsecutiveAssignments: 'false' 5 | AlignConsecutiveDeclarations: 'false' 6 | AlignEscapedNewlinesLeft: 'true' 7 | AlignOperands: 'false' 8 | AlignTrailingComments: 'false' 9 | AllowAllParametersOfDeclarationOnNextLine: 'true' 10 | AllowShortBlocksOnASingleLine: 'true' 11 | AllowShortCaseLabelsOnASingleLine: 'true' 12 | AllowShortFunctionsOnASingleLine: None 13 | AllowShortIfStatementsOnASingleLine: 'true' 14 | AllowShortLoopsOnASingleLine: 'true' 15 | AlwaysBreakAfterDefinitionReturnType: None 16 | AlwaysBreakAfterReturnType: None 17 | AlwaysBreakBeforeMultilineStrings: 'false' 18 | AlwaysBreakTemplateDeclarations: 'true' 19 | BinPackArguments: 'false' 20 | BinPackParameters: 'false' 21 | BreakBeforeBinaryOperators: None 22 | BreakBeforeBraces: Allman 23 | BraceWrapping: 24 | AfterClass: true 25 | AfterControlStatement: true 26 | AfterEnum: true 27 | AfterFunction: true 28 | AfterNamespace: true 29 | AfterObjCDeclaration: true 30 | AfterStruct: true 31 | AfterUnion: true 32 | AfterExternBlock: true 33 | BeforeCatch: true 34 | BeforeElse: true 35 | IndentBraces: false 36 | SplitEmptyFunction: true 37 | SplitEmptyRecord: true 38 | SplitEmptyNamespace: true 39 | BreakBeforeTernaryOperators: 'false' 40 | BreakConstructorInitializersBeforeComma: 'true' 41 | BreakStringLiterals: 'false' 42 | ColumnLimit: '0' 43 | ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' 44 | ConstructorInitializerIndentWidth: '4' 45 | ContinuationIndentWidth: '5' 46 | Cpp11BracedListStyle: 'true' 47 | ExperimentalAutoDetectBinPacking: 'false' 48 | IndentCaseLabels: 'true' 49 | IndentWidth: '4' 50 | IndentWrappedFunctionNames: 'true' 51 | KeepEmptyLinesAtTheStartOfBlocks: 'false' 52 | Language: Cpp 53 | NamespaceIndentation: Inner 54 | PenaltyBreakComment: '500' 55 | PenaltyBreakFirstLessLess: '400' 56 | PenaltyBreakString: '600' 57 | PenaltyExcessCharacter: '50' 58 | PenaltyReturnTypeOnItsOwnLine: '300' 59 | PointerAlignment: 'Left' 60 | ReflowComments: 'false' 61 | SortIncludes: 'false' 62 | SpaceAfterCStyleCast: 'false' 63 | SpaceAfterTemplateKeyword: 'true' 64 | SpaceBeforeAssignmentOperators: 'true' 65 | SpaceBeforeParens: ControlStatements 66 | SpaceInEmptyParentheses: 'false' 67 | SpacesInAngles: 'false' 68 | SpacesInCStyleCastParentheses: 'false' 69 | SpacesInParentheses: 'false' 70 | SpacesInSquareBrackets: 'false' 71 | Standard: Cpp11 72 | TabWidth: '4' 73 | UseTab: Always 74 | DerivePointerAlignment: 'true' 75 | -------------------------------------------------------------------------------- /tmp/c-new2/parser.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: parser.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_PARSER_H 12 | #define ONE_PARSER_H 13 | 14 | typedef struct _token Token; 15 | 16 | typedef struct 17 | { 18 | const char* package; 19 | const char* path; 20 | 21 | Token** tokens; 22 | size_t tokens_index; 23 | size_t tokens_count; 24 | } Parser; 25 | 26 | void parser_init(); 27 | 28 | void parser_scan(); 29 | 30 | void parser_start(); 31 | 32 | void parser_push(Token* t); 33 | 34 | AstRoot* parser_check(); 35 | 36 | void parser_free(); 37 | 38 | bool parser_expect(TokenType expected); 39 | 40 | bool parser_has(TokenType expected); 41 | 42 | AstGlobalStatenent* parser_parse(); 43 | 44 | void parser_parse_package(); 45 | 46 | AstFunction* parser_parse_fn(); 47 | 48 | AstBlock* parser_parse_block(); 49 | 50 | AstBlock* parser_parse_statements(); 51 | 52 | AstStatement* parser_parse_statement(); 53 | 54 | AstStatement* parser_parse_statement_prints(); 55 | 56 | AstStatement* parser_parse_statement_print(); 57 | 58 | AstStatement* parser_parse_statement_printnl(); 59 | 60 | AstStatement* parser_parse_statement_printdb(); 61 | 62 | AstStatement* parser_parse_statement_printdbnl(); 63 | 64 | AstExpressions parser_parse_expressions(); 65 | 66 | AstExpression* parser_parse_expression(); 67 | 68 | void parser_next(); 69 | 70 | void parser_prev(); 71 | 72 | void parser_tokens_log(); 73 | 74 | typedef void (*ParseFn)(bool canAssign); 75 | 76 | typedef int Precedence; 77 | 78 | /* 79 | * typedef enum 80 | { 81 | PREC_ASSIGNMENT, // = 82 | PREC_OR, // or 83 | PREC_AND, // and 84 | PREC_EQUALITY, // == != 85 | PREC_COMPARISON, // < > <= >= 86 | PREC_TERM, // + - 87 | PREC_FACTOR, // * / 88 | PREC_UNARY, // ! - 89 | PREC_CALL, // . () 90 | PREC_PRIMARY, 91 | PREC_NONE, // non operators! 92 | } Precedence; 93 | */ 94 | 95 | /* 96 | char* precedence_name(Precedence type); 97 | 98 | typedef struct 99 | { 100 | ParseFn prefix; 101 | ParseFn infix; 102 | Precedence precedence; 103 | } ParseRule; 104 | */ 105 | 106 | AstExpression* parser_parse_expression_primary(); 107 | 108 | void parser_preapre(); 109 | 110 | AstImport* parser_parse_import(); 111 | 112 | AstStruct* parser_parse_struct(); 113 | 114 | AstTypeDef* parser_parse_type(); 115 | 116 | AstStatement* parser_parse_statement_if(); 117 | 118 | #endif //ONE_PARSER_H 119 | -------------------------------------------------------------------------------- /tmp/js/src/generator/index.js: -------------------------------------------------------------------------------- 1 | const { genIf } = require('./commands/if'); 2 | const { genWhile } = require('./commands/while'); 3 | const { genFor } = require('./commands/for'); 4 | const { genFunction } = require('./commands/function'); 5 | const { genVariableDefine } = require('./commands/variable-define'); 6 | // const { parseAst } = require("./vm"); 7 | 8 | // function generateJSExpression(expression) { 9 | // // console.log(expression); 10 | 11 | // const oepratorMap = { 12 | // "+": "+", 13 | // "-": "-", 14 | // "*": "*", 15 | // "/": "/", 16 | // ">=": ">=", 17 | // "<=": "<=", 18 | // ">": ">", 19 | // "<": "<", 20 | // "=": "==", 21 | // }; 22 | 23 | // if (typeof expression === "object") { 24 | // if (expression.type === "binary_expression") { 25 | // const left = generateJSExpression(expression.left); 26 | // const right = generateJSExpression(expression.right); 27 | // const operator = oepratorMap[expression.operator]; 28 | // return `${left} ${operator} ${right}`; 29 | // } 30 | // } else { 31 | // // identifier or number 32 | // return expression; 33 | // } 34 | // } 35 | 36 | // function generateJS(statements, declaredVariables) { 37 | // // console.log(declaredVariables); 38 | 39 | // const lines = []; 40 | // for (let statement of statements) { 41 | // if (statement.type === "var_assignment") { 42 | // const value = generateJSExpression(statement.value); 43 | // if (declaredVariables.indexOf(statement.varname) === -1) { 44 | // lines.push(`let ${statement.varname} = ${value};`); 45 | // declaredVariables.push(statement.varname); 46 | // } else { 47 | // lines.push(`${statement.varname} = ${value};`); 48 | // } 49 | // } else if (statement.type === "while_loop") { 50 | // const condition = generateJSExpression(statement.condition); 51 | // const body = generateJS(statement.body, declaredVariables) 52 | // .split("\n") 53 | // .map((line) => " " + line) 54 | // .join("\n"); 55 | // lines.push(`while(${condition}) {\n${body}\n}`); 56 | // } else if (statement.type === "print_statement") { 57 | // const expression = generateJSExpression(statement.expression); 58 | // lines.push(`console.log(${expression});`); 59 | // } 60 | // } 61 | // return lines.join("\n"); 62 | // // return "console.log('Hello, World!');"; 63 | // } 64 | 65 | module.exports = { 66 | genIf, 67 | genWhile, 68 | genFor, 69 | genFunction, 70 | genVariableDefine, 71 | // parseAst, 72 | }; 73 | -------------------------------------------------------------------------------- /src/builtins/string.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: builtins/string.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "string.h" 12 | 13 | /* 14 | * @function: string_new 15 | * @desctipion: Creates a new string, 16 | if there is not enough memory, will return a null pointer instead. 17 | * @arguments: nothing 18 | * @return: mallocated string 19 | */ 20 | string* string_new() 21 | { 22 | // allocate space for the string struct 23 | string* ss = malloc(sizeof(string)); 24 | // quit if no memory 25 | if (NULL == ss) goto string_new_fail; 26 | 27 | // allocate space for the string itself 28 | ss->str = malloc(STRING_SIZE_INIT); 29 | // quit and cleanup if this failed 30 | if (NULL == ss->str) goto string_new_fail; 31 | 32 | // set up the other bits of the string string 33 | ss->end = ss->str; 34 | *ss->end = '\0'; 35 | ss->size = STRING_SIZE_INIT; 36 | 37 | return ss; 38 | string_new_fail: 39 | free(ss); 40 | return NULL; 41 | } 42 | 43 | /* 44 | * @function: string_append 45 | * @description: Append to a string string, growing the allocated memory if needed 46 | on error, will return the longest string possible, which may truncate the suffix. 47 | * @arguments: string target, char* value want to be added 48 | * @return: void 49 | */ 50 | void string_append(string* ss, char* suffix) 51 | { 52 | // iterate through suffix by character. Could be more efficient by using 53 | // memcopy or similar, but the idea is the same. 54 | while (*suffix != '\0') 55 | { 56 | // Check to see if the string needs to grow or not. 57 | // also make sure we leave space for the null-termination byte at the end 58 | if (!((ss->end - ss->str) < (ss->size - 1))) 59 | { 60 | // store the offset, since the end ptr will not be valid if realloc 61 | // moves our memory block 62 | size_t offset = ss->end - ss->str; 63 | // allocate bigger space, grows by doubling (good amortization) 64 | char* newstr = realloc(ss->str, (ss->size * 2)); 65 | // if we're out of memory, we bail out. 66 | if (NULL == newstr) 67 | { 68 | ss->end--; 69 | break; 70 | } 71 | // reset the string string's internal to reflect the new size and 72 | // possible memory block 73 | ss->str = newstr; 74 | ss->size = ss->size * 2; 75 | ss->end = ss->str + offset; 76 | } 77 | //append chars to the string 78 | *(ss->end) = *suffix; 79 | suffix++; 80 | ss->end++; 81 | } 82 | // make sure we're always null terminated correctly. 83 | *(ss->end) = '\0'; 84 | } 85 | -------------------------------------------------------------------------------- /tmp/c-new/src/arg.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: arg.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "token.h" 12 | #include "lexer.h" 13 | #include "array.h" 14 | #include "error.h" 15 | #include "one.h" 16 | 17 | #include "arg.h" 18 | 19 | void ArgsInit(Args *args) 20 | { 21 | } 22 | 23 | void ArgsParse(int argc, char **argv, char **env, Args *args, ErrorsContainer *errors) 24 | { 25 | args->argv = argv; 26 | 27 | Array files; 28 | arrayInit(&files); 29 | 30 | for (int i = 1; i < argc; i++) 31 | { 32 | if (argv[i][0] == '-') 33 | { 34 | if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0 || 35 | strcmp(argv[i], "help")) 36 | { 37 | args->help = true; 38 | } 39 | else if (strcmp(argv[i], "-g") == 0 || 40 | strcmp(argv[i], "--debug") == 0) 41 | { 42 | args->debug = true; 43 | } 44 | else if (strcmp(argv[i], "-v") == 0 || 45 | strcmp(argv[i], "--version") == 0) 46 | { 47 | args->version = true; 48 | } 49 | } 50 | else 51 | { 52 | arrayPush(&files, (void *)argv[i]); 53 | } 54 | } 55 | 56 | args->input_files_count = files.count; 57 | args->input_files = (char **)files.data; 58 | } 59 | 60 | void ArgsFree(Args *args) 61 | { 62 | // free argc 63 | for (int i = 0; i < args->argc; i++) 64 | free(args->argv[i]); 65 | 66 | // free input_files 67 | // TODO 68 | // for (int i = 0; i < args->input_files_count; i++) { 69 | // printf("free %d\n", i); 70 | // free(args->input_files[i]); 71 | // } 72 | 73 | // free env 74 | // TODO 75 | } 76 | 77 | void ArgsHelp(FILE *file, Args *args) 78 | { 79 | fprintf(file, "Usage: %s [options] file...\n", args->argv[0]); 80 | fprintf(file, "Options:\n"); 81 | fprintf(file, " -h, --help Print out this help text.\n"); 82 | fprintf(file, " -g, --debug Include debug information in " 83 | "the build.\n"); 84 | fprintf( 85 | file, 86 | " -o, --output FILE Output the result to the given file.\n"); 87 | fprintf(file, 88 | " -v, --version Print out the compiler version\n"); 89 | fprintf(file, "\n"); 90 | } 91 | 92 | void ArgsVersion(FILE *file, Args *args) 93 | { 94 | fprintf(file, " _ _ \n"); 95 | fprintf(file, " / \\ |\\ | |_ Max Base\n"); 96 | fprintf(file, " \\_/ | \\| |_ Copyright 2021; One Language Contributors\n"); 97 | fprintf(file, "\n"); 98 | fprintf(file, ONE_VERSION); 99 | } 100 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/join_web_team.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Join the Website Team (Front-end developer or designer) 3 | about: I want to join the Website Team. 4 | title: "[Join] Website team" 5 | labels: Join 6 | assignees: BaseMax 7 | --- 8 | 9 | Hi, One Language Team; 10 | I'm here to tell you I'm interested in this compiler project and want to help and participate in this open-source project. 11 | 12 | ## Introduction 13 | 14 | 15 | ## Your correct role 16 | 17 | I'm a Bachelor's student of computer science at the University of Cambridge. 18 | And I have a part-time job as a Front-end developer at X company in India and I work as a JS programmer. 19 | 20 | ## Timezone 21 | 22 | Brisbane, Australia; UTC/GMT +10 hours 23 | 24 | ## Programming experience 25 | 26 | List of languages with experience level: 27 | 28 | 29 | 30 | - **HTML5**: 3 years experience 31 | - **CSS3**: 1 years experience 32 | - **Vanilla JS**: Just for fun to write 3-5 scripts without professional experience (And tell us about libraries you have worked on. e.g: Axios, and every library you worked on in JS.) 33 | - **ReactJS**: Just for personal needs (and tell us about libraries you have worked on) 34 | - **VueJS**: Just for personal needs (and tell us about libraries you have worked on) 35 | 36 | ## Front-end experience 37 | 38 | Tell us about your experience or your fun projects about website design or programming: 39 | 40 | 41 | 42 | Do you know about ReactJS and VueJS? 43 | 44 | 45 | Do you know about NextJS? 46 | 47 | 48 | Do you know about PureJS ES6? 49 | 50 | 51 | Do you know about jQuery? 52 | 53 | 54 | Are you able to design the UI of the website pages? 55 | 56 | 57 | What design software you are familiar with and can open and use? 58 | 59 | 60 | Tell us your opinion about "One Language" and creating a new language: 61 | 62 | 63 | ----------- 64 | 65 | 68 | 69 | Best Regards; 70 | -------------------------------------------------------------------------------- /tmp/c-new/src/tree.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: tree.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "token.h" 12 | #include "tree.h" 13 | #include "vm.h" 14 | 15 | size_t ident = 0; 16 | 17 | void print_tabs(size_t n) 18 | { 19 | for (size_t i = 0; i < n; i++) 20 | { 21 | printf(" "); 22 | } 23 | } 24 | 25 | void treeExpression(AstExpression* expr) 26 | { 27 | print_tabs(ident); 28 | printf("[EXPR] %s ", astOperatorName(expr->operator)); 29 | if (expr->operator== TOKEN_OPERATOR_DIRECT) 30 | { 31 | // printf("%d", expr->vint); 32 | printf("%s", expr->vstring); 33 | } 34 | else 35 | { 36 | printf("\n"); 37 | ident++; 38 | print_tabs(ident); 39 | 40 | printf("Left:\n"); 41 | ident++; 42 | treeExpression(expr->left); 43 | ident--; 44 | 45 | if (expr->right != NULL) 46 | { 47 | print_tabs(ident); 48 | printf("Right:\n"); 49 | ident++; 50 | treeExpression(expr->right); 51 | ident--; 52 | } 53 | 54 | ident--; 55 | } 56 | printf("\n"); 57 | } 58 | 59 | void treeExpressions(AstExpressions* expressions) 60 | { 61 | ident++; 62 | print_tabs(ident); 63 | printf("[EXPRESSIONS] %d expression(s)\n", expressions->count); 64 | ident++; 65 | for (size_t i = 0; i < expressions->count; i++) 66 | { 67 | treeExpression(expressions->data[i]); 68 | } 69 | ident--; 70 | ident--; 71 | } 72 | 73 | void treeStatement(AstStatement* stmt) 74 | { 75 | printf("[STMT] %s\n", astStatementName(stmt->type)); 76 | if (stmt->type == AST_STATEMENT_PRINT || stmt->type == AST_STATEMENT_PRINTNL || stmt->type == AST_STATEMENT_PRINTDB || stmt->type == AST_STATEMENT_PRINTDBNL || stmt->type == AST_STATEMENT_RETURN) 77 | treeExpressions(stmt->expressions); 78 | } 79 | 80 | void treeStatements(AstStatements* stmts) 81 | { 82 | ident++; 83 | for (size_t i = 0; i < stmts->count; i++) 84 | { 85 | print_tabs(ident); 86 | treeStatement(stmts->data[i]); 87 | } 88 | ident--; 89 | } 90 | 91 | void treeBlock(AstBlock* block) 92 | { 93 | treeStatements(block->statements); 94 | } 95 | 96 | void treeFunction(AstFunction* func) 97 | { 98 | printf("\n"); 99 | print_tabs(ident); 100 | printf("[FUNC] %s\n", func->name); 101 | 102 | treeBlock(func->block); 103 | } 104 | 105 | void treeLog(AstRoot* root) 106 | { 107 | if (root->package == NULL || strlen(root->package) == 0 || strcmp(root->package, "") == 0) 108 | { 109 | root->package = "main"; 110 | } 111 | printf("=============== TREE ===============\n"); 112 | 113 | printf("Package: %s\n", root->package); 114 | 115 | for (size_t i = 0; i < root->functions->count; i++) 116 | { 117 | treeFunction(root->functions->data[i]); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: CodeQL 13 | 14 | on: [pull_request] 15 | 16 | permissions: # added using https://github.com/step-security/secure-workflows 17 | contents: read 18 | 19 | jobs: 20 | analyze: 21 | permissions: 22 | actions: read # for github/codeql-action/init to get workflow details 23 | contents: read # for actions/checkout to fetch code 24 | security-events: write # for github/codeql-action/autobuild to send a status report 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | language: ['javascript'] 32 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 33 | # Learn more: 34 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 35 | 36 | steps: 37 | - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" 38 | uses: actions/checkout@v6 39 | 40 | # Initializes the CodeQL tools for scanning. 41 | - name: Initialize CodeQL 42 | uses: github/codeql-action/init@v4 43 | with: 44 | languages: ${{ matrix.language }} 45 | # If you wish to specify custom queries, you can do so here or in a config file. 46 | # By default, queries listed here will override any specified in a config file. 47 | # Prefix the list here with "+" to use these queries and those in the config file. 48 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 49 | 50 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 51 | # If this step fails, then you should remove it and run the build manually (see below) 52 | - name: Autobuild 53 | uses: github/codeql-action/autobuild@v4 54 | 55 | # ℹ️ Command-line programs to run using the OS shell. 56 | # 📚 https://git.io/JvXDl 57 | 58 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 59 | # and modify them (or add more) to build your code if your project 60 | # uses a compiled language 61 | 62 | # - run: | 63 | # make bootstrap 64 | # make release 65 | 66 | - name: Perform CodeQL Analysis 67 | uses: github/codeql-action/analyze@v4 68 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/join_core_team.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Join the Core Team (C programmer or Embedded programmer) 3 | about: I want to join the Core Team. 4 | title: "[Join] Core team" 5 | labels: Join 6 | assignees: BaseMax 7 | --- 8 | 9 | Hi, One Language Team; 10 | I'm here to tell you I'm interested in this compiler project and want to help and participate in this open-source project. 11 | 12 | ## Introduction 13 | 14 | 15 | ## Your correct role 16 | 17 | I'm a Bachelor's student of computer science at the University of Cambridge. 18 | And Have a part-time job at an embedded system company in India and I work as a C programmer. 19 | 20 | ## Timezone 21 | 22 | Brisbane, Australia; UTC/GMT +10 hours 23 | 24 | ## Programming experience 25 | 26 | List of languages with experience level: 27 | 28 | 29 | 30 | - **C**: 3 years experience (And tell us about libraries you have worked on. e.g: libcurl, OpenSSL and every library you worked in at C.) 31 | - **C++**: 1 year experience 32 | - **Python**: Just for fun to write 3-5 scripts without professional experience 33 | - **Batch/Bash**: Just for personal needs 34 | 35 | ## Operating Systems 36 | 37 | 38 | List of Operating systems with your experience level: 39 | 40 | 41 | - **Windows**: Windows 7 or 10 (I have a PC, or I have it in a virtual machine) 42 | - **Linux**: CentOS or Ubuntu or Arch, etc. (Primary OS on laptop or desktop) 43 | 44 | ## Compiler experience 45 | 46 | Tell us about your experience at University or your fun projects about Compilers and Interpreters: 47 | 48 | 49 | 50 | Do you know about Flex and Bison/Yacc? 51 | 52 | 53 | Do you know about JIT Compilers? 54 | 55 | 56 | Do you know about LLVM? 57 | 58 | 59 | Tell us your opinion about "One Language" and creating a new language: 60 | 61 | 62 | Has it happened when you are programming and you are dissatisfied with a feature, and you think you can inject such ideas into the project so that we can make a better product? What do you think: 63 | 64 | 65 | ----------- 66 | 67 | 70 | 71 | Best Regards; 72 | -------------------------------------------------------------------------------- /tmp/c-new/src/ast.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: ast.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _AST_H_ 12 | #define _AST_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "array.h" 20 | 21 | typedef Array AstArguments; 22 | typedef Array AstStatements; 23 | typedef Array AstFunctions; 24 | typedef Array AstExpressions; 25 | 26 | typedef struct _ast_expression AstExpression; 27 | //typedef struct _token_type TokenType; 28 | 29 | typedef enum 30 | { 31 | AST_TYPE_I8, 32 | AST_TYPE_I16, 33 | AST_TYPE_I32, 34 | AST_TYPE_I64, 35 | 36 | AST_TYPE_U8, 37 | AST_TYPE_U16, 38 | AST_TYPE_U32, 39 | AST_TYPE_U64, 40 | } AstValueType; 41 | 42 | typedef enum 43 | { 44 | AST_STATEMENT_PRINT, 45 | AST_STATEMENT_PRINTNL, 46 | AST_STATEMENT_PRINTDB, 47 | AST_STATEMENT_PRINTDBNL, 48 | 49 | AST_STATEMENT_RETURN, 50 | } AstStatementType; 51 | 52 | /* 53 | typedef enum 54 | { 55 | AST_OPERATOR_DIRECT, // without an operator! 56 | 57 | AST_OPERATOR_PLUS, 58 | AST_OPERATOR_MINUS, 59 | AST_OPERATOR_MUL, 60 | AST_OPERATOR_DIV, 61 | AST_OPERATOR_POW, 62 | 63 | TOKEN_OPERATOR_IF, // ? : 64 | TOKEN_OPERATOR_IFIF, // ?? 65 | // TODO: adding more operators! 66 | } AstOperatorType; 67 | */ 68 | 69 | typedef struct _ast_statement 70 | { 71 | AstStatementType type; 72 | AstExpressions* expressions; 73 | AstExpression* expression; 74 | } AstStatement; 75 | 76 | typedef struct _ast_block 77 | { 78 | AstStatements* statements; 79 | } AstBlock; 80 | 81 | typedef struct _ast_type 82 | { 83 | int type; 84 | bool hasArray; 85 | } AstType; 86 | 87 | typedef struct _ast_expression 88 | { 89 | // AstOperatorType operator; 90 | TokenType operator; 91 | 92 | int vint; 93 | float vfloat; 94 | char* vstring; 95 | bool vbool; 96 | 97 | AstExpression* left; 98 | AstExpression* right; 99 | AstExpression* third; 100 | } AstExpression; 101 | 102 | typedef struct _ast_argument 103 | { 104 | char* name; 105 | AstType* type; 106 | } AstArgument; 107 | 108 | typedef struct _ast_function 109 | { 110 | char* name; 111 | AstArguments* arguments; 112 | AstBlock* block; 113 | } AstFunction; 114 | 115 | typedef struct _ast_root 116 | { 117 | char* package; 118 | AstFunctions* functions; 119 | } AstRoot; 120 | 121 | AstType* astType(int, bool); 122 | 123 | AstBlock* astBlock(AstStatements*); 124 | 125 | AstArgument* astArgument(char*, AstType*); 126 | 127 | AstFunction* astFunction(char*, AstArguments*, AstBlock*); 128 | 129 | AstRoot* astRoot(char*, AstFunctions*); 130 | 131 | AstStatement* astStatement(AstStatementType); 132 | 133 | char* astOperatorName(TokenType); 134 | 135 | char* astStatementName(AstStatementType); 136 | 137 | AstExpression* astExpression(TokenType, int, float, char*, bool, AstExpression*, AstExpression*); 138 | 139 | AstExpression* astExpression3(TokenType, int, float, char*, bool, AstExpression*, AstExpression*, AstExpression*); 140 | 141 | #endif //_AST_H_ 142 | -------------------------------------------------------------------------------- /tmp/c-new/src/lexer.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: lexer.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "token.h" 12 | #include "error.h" 13 | #include "lexer.h" 14 | #include "array.h" 15 | 16 | Lexer *lexerInit(char *filename, char *input, ErrorsContainer *errors) 17 | { 18 | Lexer *lex = (Lexer *)malloc(sizeof(Lexer)); 19 | lex->tokens = NULL; 20 | lex->token_count = 0; 21 | lex->filename = filename; 22 | lex->source = input; 23 | lex->location.line = 0; 24 | lex->location.column = 0; 25 | return lex; 26 | } 27 | 28 | void lexerLog(Lexer *lex) 29 | { 30 | printf("=============== Tokenizer ===============\n"); 31 | 32 | Token *t; 33 | for (size_t i = 0; i < lex->token_count; i++) 34 | { 35 | t = lex->tokens[i]; 36 | 37 | printf("LexerLog==>%s", tokenName(t->type)); 38 | if (t->type == TOKEN_VALUE_IDENTIFIER || t->type == TOKEN_VALUE_STRING || t->type == TOKEN_VALUE_NUMBER) 39 | printf(" (%s)", t->vstring); 40 | printf("\n"); 41 | } 42 | } 43 | 44 | int lexerCheck(Lexer *lex, ErrorsContainer *errors) 45 | { 46 | token_init(lex); 47 | printf("=============== Source ===============\n"); 48 | printf("%s\n", lex->source); 49 | 50 | Array tokens; 51 | arrayInit(&tokens); 52 | 53 | bool has_error = false; // we need this value to make sure we can add EOF token at end of tokens list or no. 54 | // for example: Maybe we need to detect we tokenizer whole of the file or no, we face to a error and so we break and not tokiziers whole of the source! 55 | 56 | Token *t; 57 | while (tokenEOF(lex) == false) 58 | { 59 | // printf("%c\n", *lex->source); 60 | // tokenNextChar(lex); 61 | t = tokenNext(lex); 62 | if (t->type == TOKEN_UNKNOWM) 63 | { 64 | has_error = true; // change error status from false to true... 65 | // TODO: raise a error via ErrorAppend(...) 66 | break; 67 | } 68 | 69 | arrayPush(&tokens, t); 70 | // printf("==>%s\n", tokenName(t->type)); 71 | // if(t->type == TOKEN_VALUE_IDENTIFIER || t->type == TOKEN_VALUE_STRING || t->type == TOKEN_VALUE_NUMBER) 72 | // printf("\t%s\n", t->vstring); 73 | } 74 | 75 | // Why in some case when we put newline and free space at end of file, we not see a EOF token there! 76 | if (has_error == false) 77 | { // if we not have any errors in tokinizering source 78 | if (tokens.count == 0 || ( // if tokens list is empty 79 | tokens.count > 0 && ((Token *)tokens.data[tokens.count - 1])->type != TOKEN_EOF) // otherwise, if tokens list is not empty and at last item of tokens we not have a EOF token... 80 | ) 81 | { 82 | Token *t_eof = (Token *)malloc(sizeof(Token)); // create a token value just for adding EOF token. 83 | t_eof->type = TOKEN_EOF; // set type of new token as TOKEN_EOF 84 | arrayPush(&tokens, t_eof); // push and add t-eof token at list of token! 85 | // free(t_eof); // free t_eof from memory! 86 | } 87 | } 88 | 89 | lex->tokens = (Token **)tokens.data; 90 | lex->token_count = tokens.count; 91 | return EXIT_SUCCESS; 92 | } 93 | 94 | void lexerFree(Lexer *lex) 95 | { 96 | // arrayFree(lex->tokens); 97 | } 98 | -------------------------------------------------------------------------------- /src/ast/ast-structure.txt: -------------------------------------------------------------------------------- 1 | File: 2 | char* package 3 | Array imports 4 | Array blocks 5 | 6 | Import: 7 | Array names = [math], [parentLib, childLib], [file] 8 | Array as = [pc, cr] 9 | Array symbols = [sin], [sin, cos], [create] 10 | ``` 11 | import math // math.sin(), math.cos() 12 | import math { sin } // sin() 13 | import math { sin, cos } // sin(), cos() 14 | import parentLib.childLib // childLib.functionName() 15 | import parentLib.childLib as pc // pc.functionName() 16 | import parentLib {childLib.functionName as a_fn} // a_fn() 17 | import file // file.create() 18 | import file { create } // create() 19 | import file { create as cr } // cr() 20 | ``` 21 | 22 | Block: 23 | BlockType type 24 | Function function 25 | DefineStruct define_struct 26 | DefineType define_type 27 | Statement statement 28 | 29 | BlockType: 30 | BLOCK_FUNCTION 31 | BLOCK_STRUCT 32 | BLOCK_TYPE 33 | BLOCK_STATEMENT 34 | 35 | DefineType: 36 | char* name = Name, Number 37 | Array types = [string], [int, float] 38 | bool is_public 39 | ``` 40 | type Name = string 41 | type Number = int | float 42 | type Func = fn (int) float 43 | type Funcs = fn (int) float | fn (float) int 44 | pub type AnyString = string 45 | ``` 46 | 47 | Type: 48 | char* name // If it's a custom data-type, otherwise NULL 49 | TypeType type 50 | Array argumentTypes 51 | Type return 52 | ``` 53 | string 54 | int 55 | float 56 | fn (int) float 57 | fn (float) int 58 | fn (string) string 59 | fn (string) Name 60 | fn (string) Number 61 | ``` 62 | 63 | DataType: 64 | TYPE_I8 65 | TYPE_U8 66 | TYPE_I16 67 | TYPE_U16 68 | TYPE_I32 69 | TYPE_U32 70 | TYPE_I64 71 | TYPE_U64 72 | TYPE_I128 73 | TYPE_U128 74 | TYPE_POINTER_VOID, 75 | ... 76 | TYPE_FUNC 77 | 78 | DefineStruct: 79 | char* name 80 | Array mut_fields 81 | Array imut_fields 82 | Array pub_mut_fields 83 | Array pub_imut_fields 84 | bool is_public 85 | bool is_mut 86 | bool is_global 87 | ``` 88 | struct Programmer { 89 | github string 90 | name string 91 | } 92 | struct Designer { 93 | dribbble string 94 | name string 95 | } 96 | pub struct Designer { 97 | dribbble string 98 | name string 99 | } 100 | ``` 101 | 102 | Argument: 103 | char* name 104 | Type type 105 | bool is_mut 106 | bool is_variable 107 | ``` 108 | github string 109 | name string 110 | own Number 111 | func fn (string) string 112 | mut index int 113 | numbers ...int 114 | ``` 115 | 116 | Function: 117 | char* name 118 | Array generics 119 | Array arguments 120 | Type return 121 | bool has_error = true, false, false, ... 122 | Array statements 123 | bool is_public 124 | ``` 125 | fn request(url string) ?string { } 126 | fn simple_equal(x int, y int) bool { } 127 | fn equal(x X, y X) bool { } 128 | fn equal(x X, y Y) bool { } 129 | pub fn sum(a int, b int) int {} 130 | ``` 131 | 132 | Statement: 133 | StatementType type 134 | 135 | StatementType: 136 | STATEMENT_EXPRESSION 137 | STATEMENT_IF 138 | STATEMENT_FOR 139 | STATEMENT_MATCH 140 | STATEMENT_RET 141 | STATEMENT_DEFER 142 | STATEMENT_ 143 | -------------------------------------------------------------------------------- /src/builtins/file.c: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: builtins/file.c 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #include "file.h" 12 | 13 | /* 14 | * @function: file_reads 15 | * @description: read whole of a filepath 16 | * @arguments: const char* filepath 17 | * @return: char* 18 | */ 19 | char* file_reads(const char* filepath) 20 | { 21 | debug("file_reads"); 22 | debug("file_reads: %s", filepath); 23 | 24 | FILE* file = fopen(filepath, "rb"); 25 | if (file == NULL) 26 | { 27 | error_panic("Could not open file \"%s\".", filepath); 28 | exit(74); 29 | } 30 | 31 | fseek(file, 0L, SEEK_END); 32 | size_t fileSize = ftell(file); 33 | debug("file_reads: fileSize is %zu", fileSize); 34 | rewind(file); 35 | 36 | char* buffer = (char*)malloc(fileSize + 1); 37 | if (buffer == NULL) 38 | { 39 | error_panic("Not enough memory to read \"%s\".", filepath); 40 | exit(74); 41 | } 42 | 43 | size_t bytesRead = fread(buffer, sizeof(char), fileSize, file); 44 | debug("file_reads: bytesRead is %zu", bytesRead); 45 | if (bytesRead < fileSize) 46 | { 47 | error_panic("Could not read the \"%s\".", filepath); 48 | exit(74); 49 | } 50 | 51 | buffer[bytesRead] = '\0'; 52 | 53 | fclose(file); 54 | return buffer; 55 | } 56 | 57 | /* 58 | * @function: file_convert_index_to_rc 59 | * @description: We get index of a position and point in string and looking to find its rows and column number and we will pass new value throw argument 60 | * @arguments: const char* input, int index, size_t* rows, size_t* columns 61 | * @return: bool / True or False; does that index exists or no. maybe current index is out of the file and filelength is less that `index` value! 62 | */ 63 | bool file_convert_index_to_rc(const char* input, int index, size_t* rows, size_t* columns) 64 | { 65 | int row = 1, col = 0; 66 | 67 | for (int i = 0; i < index; i++) 68 | { 69 | char ch = input[i]; 70 | // printf("-->%d,'%c'\n", i, ch); 71 | 72 | if (ch == '\0') return false; // Stop loop and return false as function return-value 73 | 74 | if (ch == '\r') 75 | { 76 | // Skip the optional \n 77 | if (i + 1 < index && input[i + 1] == '\n') 78 | { 79 | i++; 80 | } 81 | 82 | row++; 83 | col = 0; 84 | } 85 | else if (ch == '\n') 86 | { 87 | row++; 88 | col = 0; 89 | } 90 | else 91 | { 92 | col++; 93 | } 94 | } 95 | 96 | *rows = row; 97 | *columns = col; 98 | 99 | return true; 100 | } 101 | 102 | /* 103 | * @function: file_get_parent 104 | * @description: If you want to get directory path from a full-file path, this function will be useful and can return the directory path for you. 105 | * @arguments: const char* path 106 | * @return: char* 107 | */ 108 | char* file_get_parent(const char* path) 109 | { 110 | int parentLen; 111 | char* parent = malloc(sizeof(path)); 112 | char* last = strrchr(path, '/'); // TODO: What about if users use \\ or that is windows OS? 113 | 114 | if (last != NULL) 115 | { 116 | parentLen = strlen(path) - strlen(last + 1); 117 | strncpy(parent, path, parentLen); 118 | } 119 | 120 | return parent; 121 | } 122 | -------------------------------------------------------------------------------- /tmp/c-old/src/lexer/tokens.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | DEF(TOK_OP_AND1, "and") 21 | DEF(TOK_OP_OR1, "or") 22 | DEF(TOK_OP_ADD, "+") 23 | DEF(TOK_OP_MIN, "-") 24 | DEF(TOK_OP_POW1, "^") 25 | DEF(TOK_OP_POW2, "**") 26 | DEF(TOK_OP_MUL, "*") 27 | DEF(TOK_OP_DIV, "/") 28 | DEF(TOK_OP_BITWISE_OR, "|") 29 | DEF(TOK_OP_BITWISE_AND, "&") 30 | DEF(TOK_OP_G, ">") 31 | DEF(TOK_OP_L, "<") 32 | DEF(TOK_OP_OR2, "||") 33 | DEF(TOK_OP_AND2, "&&") 34 | DEF(TOK_OP_SHIFT_LEFT, ">>") 35 | DEF(TOK_OP_SHIFT_RIGHT, "<<") 36 | DEF(TOK_OP_NOT1, "!") 37 | DEF(TOK_OP_NOT2, "not") 38 | DEF(TOK_OP_GE, ">=") 39 | DEF(TOK_OP_LE, "<=") 40 | DEF(TOK_OP_NEQ, "!=") 41 | DEF(TOK_OP_NEQT, "!==") 42 | DEF(TOK_OP_DEFINE, "=") 43 | DEF(TOK_OP_EQ, "==") 44 | DEF(TOK_OP_EQT, "===") 45 | DEF(TOK_END_OPERATION, "\ntokendoperation") 46 | DEF(TOK_I8, "i8") 47 | DEF(TOK_I16, "i16") 48 | DEF(TOK_I32, "i32") 49 | DEF(TOK_I64, "i64") 50 | DEF(TOK_I128, "i128") 51 | DEF(TOK_UI8, "ui8") 52 | DEF(TOK_UI16, "ui16") 53 | DEF(TOK_UI32, "ui32") 54 | DEF(TOK_UI64, "ui64") 55 | DEF(TOK_F32, "f32") 56 | DEF(TOK_F64, "f64") 57 | DEF(TOK_BOOL, "bool") 58 | DEF(TOK_ACHAR, "achar") 59 | DEF(TOK_CHAR, "char") 60 | DEF(TOK_STRING, "string") 61 | DEF(TOK_NULL, "null") 62 | DEF(TOK_END_VARIABLE_TYPE, "\ntokendvariabletype") 63 | DEF(TOK_START_BLOCK_COMMENT, "/*") 64 | DEF(TOK_END_BLOCK_COMMENT, "*/") 65 | DEF(TOK_LINE_COMMENT, "//") 66 | DEF(TOK_SHIELD, "\\") 67 | DEF(TOK_COLONCOLON, "::") 68 | DEF(TOK_COLON, ":") 69 | DEF(TOK_DOT, ".") 70 | DEF(TOK_DOTDOT, "..") 71 | DEF(TOK_DOTDOTDOT, "...") 72 | DEF(TOK_SEMICOLON, ";") 73 | DEF(TOK_VIRGOL, ",") 74 | DEF(TOK_PARENT_LEFT, "(") 75 | DEF(TOK_PARENT_RIGHT, ")") 76 | DEF(TOK_BRACKET_LEFT, "[") 77 | DEF(TOK_BRACKET_RIGHT, "]") 78 | DEF(TOK_SECTION_LEFT, "{") 79 | DEF(TOK_SECTION_RIGHT, "}") 80 | DEF(TOK_CHOICE, "?") 81 | DEF(TOK_IF, "if") 82 | DEF(TOK_ELSE, "else") 83 | DEF(TOK_AS, "as") 84 | DEF(TOK_BREAK, "break") 85 | DEF(TOK_CONTINUE, "continue") 86 | DEF(TOK_SWITCH, "switch") 87 | DEF(TOK_MATCH, "match") 88 | DEF(TOK_CASE, "case") 89 | DEF(TOK_DEFAULT, "default") 90 | DEF(TOK_STRUCT, "struct") 91 | DEF(TOK_ENUM, "enum") 92 | DEF(TOK_UNION, "union") 93 | DEF(TOK_IMPORT, "import") 94 | DEF(TOK_DO, "do") 95 | DEF(TOK_WHILE, "while") 96 | DEF(TOK_REPEAT, "repeat") 97 | DEF(TOK_FOREACH, "foreach") 98 | DEF(TOK_FOR, "for") 99 | DEF(TOK_RET, "ret") 100 | DEF(TOK_PRINT, "_") 101 | DEF(TOK_PRINTLN, "__") 102 | DEF(TOK_END_KEYWORD, "\ntokendokeyword") 103 | -------------------------------------------------------------------------------- /src/parser/parser_token.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: parser/parser_token.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef _ONE_PARSER_PARSER_TOKEN_H_ 12 | #define _ONE_PARSER_PARSER_TOKEN_H_ 13 | 14 | #include "parser.h" 15 | 16 | /* 17 | * @function: parser_token_skip 18 | * @description: skip current tokens if these are token_is_skip we will skip from all of these. 19 | * @arguments: nothing 20 | * @return: bool, true mean we skipped some whitespace, false mean nothing to skip! 21 | */ 22 | bool parser_token_skip(); 23 | 24 | /* 25 | * @function: parser_token_skip_get 26 | * @description: skip current tokens if these are token_is_skip we will skip from all of these and return next token. 27 | * @arguments: nothing 28 | * @return: Token* 29 | */ 30 | Token* parser_token_skip_get(); 31 | 32 | /* 33 | * @function: parser_token_expect 34 | * @description: if type of current token is equal to `t` we will skip it. 35 | * @arguments: TokenType t 36 | * @return: void 37 | */ 38 | void parser_token_expect(TokenType type); 39 | 40 | /* 41 | * @function: parser_token_expect_get 42 | * @description: if type of current token is equal to `t` we will return it and skip. 43 | * @arguments: TokenType t 44 | * @return: Token* 45 | */ 46 | Token* parser_token_expect_get(TokenType type); 47 | 48 | /* 49 | * @function: parser_token_has 50 | * @description: if type of current token is equal to `t` we will skip it and return true, otherwise we return false. 51 | * @arguments: TokenType t 52 | * @return: bool, true or false 53 | */ 54 | bool parser_token_has(TokenType type); 55 | 56 | /* 57 | * @function: parser_token_is 58 | * @description: if type of current token is equal to `t` return true, otherwise we will return false. 59 | * @arguments: TokenType t 60 | * @return: bool 61 | */ 62 | bool parser_token_is(TokenType type); 63 | 64 | /* 65 | * @function: parser_token_next 66 | * @description: go to next token and return its 67 | * @arguments: nothing 68 | * @return: Token* 69 | */ 70 | Token* parser_token_next(); 71 | 72 | /* 73 | * @function: parser_token_previous 74 | * @description: go to prev token and return its 75 | * @arguments: nothing 76 | * @return: Token* 77 | */ 78 | Token* parser_token_previous(); 79 | 80 | /* 81 | * @function: parser_token_get 82 | * @description: get the current token and return its 83 | * @arguments: nothing 84 | * @return: Token* 85 | */ 86 | Token* parser_token_get(); 87 | 88 | /* 89 | * @function: parser_token_get_type 90 | * @description: get type of current token and return its type 91 | * @arguments: nothing 92 | * @return: TokenType 93 | */ 94 | TokenType parser_token_get_type(); 95 | 96 | /* 97 | * @function: parser_token_at 98 | * @description: get the Token* at `index`th and return its 99 | * @arguments: nothing 100 | * @return: Token* 101 | */ 102 | Token* parser_token_at(size_t index); 103 | 104 | /* 105 | * @function: parser_token_at_type 106 | * @description: get type of Token* at `index`th and return its type 107 | * @arguments: nothing 108 | * @return: TokenType 109 | */ 110 | TokenType parser_token_at_type(size_t index); 111 | 112 | #endif // _ONE_PARSER_PARSER_TOKEN_H_ 113 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # ONE CONTRIBUTORS 2 | 3 | ## Core Team 4 | 5 | 6 | 7 | 8 | 14 | 20 | 21 |
9 | 10 | Max Base
11 | Max Base 12 |

13 |
15 | 16 | John Bampton
17 | John Bampton 18 |

19 |
22 | 23 | ## Developers 24 | 25 | 26 | 27 | 33 |
28 | 29 | Kotbi Abderrahmane
30 | Kotbi Abderrahmane 31 |

32 |
34 | 35 | ## Influential People 36 | 37 | 38 | 39 | 45 | 51 | 52 |
40 | 41 | Jas
42 | Jas 43 |

44 |
46 | 47 | Ahmad Yoosofan
48 | Ahmad Yoosofan 49 |

50 |
53 | 54 | ## Documentation & Translation 55 | 56 | 57 | 58 | 64 | 70 | 76 |
59 | 60 | basalumutgazi
61 | Umut Gazi BAŞAL 62 |

63 |
65 | 66 | Mujahid Majalian
67 | Majalian 68 |

69 |
71 | 72 | amir-shiati
73 | Amir 74 |

75 |
77 | 78 | ## Discord Moderators 79 | 80 | 81 | 82 | 88 | 89 |
83 | 84 | Ayush Rana
85 | Ayush Rana 86 |

87 |
90 | 91 | --- 92 | 93 | Thanks to all the contributors!! 94 | 95 | --- 96 | 97 | Your name and/or your organization can be here... 98 | 99 | Send your message for sponsorship and to support us. (MaxBaseCode {[@]} Gmail {[DOT]} Com) 100 | 101 | --- 102 | 103 | Created By Max and John, developed by the `One` Language Team @ 2023 104 | -------------------------------------------------------------------------------- /tmp/c-old/src/one.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021; One Language Contributors - Max Base, 3 | * This file is part of One Programming Language. 4 | * 5 | * one-language is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * one-language is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with one-language. If not, see . 17 | * 18 | */ 19 | 20 | #include "one.h" 21 | 22 | void error(char *message) 23 | { 24 | fprintf(stderr, message); 25 | } 26 | 27 | void main_help(void) 28 | { 29 | print("One is a programming language and its here to manage your One " 30 | "programs.\n" 31 | "\n" 32 | "Usage:\n" 33 | "\n" 34 | " one [arguments]\n" 35 | "\n" 36 | "The commands are:\n" 37 | "\n" 38 | " build compile packages and dependencies\n" 39 | " run compile and run One program\n" 40 | " version print One version\n" 41 | "\n"); 42 | } 43 | 44 | void main_badcommand(int argc, char *argv[]) 45 | { 46 | if (argc > 1) 47 | { 48 | printf("one %s: unknown command\n", argv[1]); 49 | printf("Run 'one help' for usage.\n"); 50 | } 51 | } 52 | void main_badparam(void) 53 | { 54 | print("parameter flag provided but not supported!\n"); 55 | } 56 | 57 | void main_badflag(void) 58 | { 59 | print("argument flag provided but not supported!\n"); 60 | } 61 | 62 | void main_version(int argc) 63 | { 64 | if (argc > 2) 65 | { 66 | main_badflag(); 67 | } 68 | print("One version one" VERSION " " ARCH "\n"); 69 | } 70 | 71 | void main_build(int argc, char *argv[]) 72 | { 73 | if (argc <= 2) 74 | { 75 | main_badflag(); 76 | print("Please enter your one filename program!\n"); 77 | return; 78 | } 79 | char *data = read_file(argv[2]); 80 | if (data == NULL) 81 | { 82 | error("We cannot read your input file, probably it's not available or it's " 83 | "OS-permission problem!\n"); 84 | return; 85 | } 86 | 87 | Source s = source_new_data(data); 88 | printf("%s\n------------------\n", s.data); 89 | lexer_scan(&s); 90 | } 91 | 92 | void main_run(int argc, char *argv[]) 93 | { 94 | main_build(argc, argv); 95 | } 96 | 97 | void main_parse(int argc, char *argv[]) 98 | { 99 | // printf("-->%d\n", argc); 100 | // for(int i=0; i 9 | #include 10 | 11 | typedef struct vector_data vector_data; 12 | 13 | struct vector_data 14 | { 15 | vec_size_t alloc; // stores the number of bytes allocated 16 | vec_size_t length; 17 | char buff[]; // use char to store bytes of an unknown type 18 | }; 19 | 20 | vector_data *vector_alloc(vec_size_t alloc, vec_size_t size) 21 | { 22 | vector_data *v_data = malloc(sizeof(vector_data) + alloc * size); 23 | v_data->alloc = alloc; 24 | return v_data; 25 | } 26 | 27 | vector_data *vector_get_data(vector vec) 28 | { 29 | return &((vector_data *)vec)[-1]; 30 | } 31 | 32 | vector vector_create(void) 33 | { 34 | vector_data *v = malloc(sizeof(vector_data)); 35 | v->alloc = 0; 36 | v->length = 0; 37 | 38 | return &v->buff; 39 | } 40 | 41 | void vector_free(vector vec) 42 | { 43 | free(vector_get_data(vec)); 44 | } 45 | 46 | vec_size_t vector_size(vector vec) 47 | { 48 | return vector_get_data(vec)->length; 49 | } 50 | 51 | vec_size_t vector_get_alloc(vector vec) 52 | { 53 | return vector_get_data(vec)->alloc; 54 | } 55 | 56 | vector_data *vector_realloc(vector_data *v_data, vec_type_t type_size) 57 | { 58 | vec_size_t new_alloc = (v_data->alloc == 0) ? 1 : v_data->alloc * 2; 59 | vector_data *new_v_data = 60 | realloc(v_data, sizeof(vector_data) + new_alloc * type_size); 61 | new_v_data->alloc = new_alloc; 62 | return new_v_data; 63 | } 64 | 65 | bool vector_has_space(vector_data *v_data) 66 | { 67 | return v_data->alloc - v_data->length > 0; 68 | } 69 | 70 | void *_vector_add(vector *vec_addr, vec_type_t type_size) 71 | { 72 | vector_data *v_data = vector_get_data(*vec_addr); 73 | 74 | if (!vector_has_space(v_data)) 75 | { 76 | v_data = vector_realloc(v_data, type_size); 77 | *vec_addr = v_data->buff; 78 | } 79 | 80 | return (void *)&v_data->buff[type_size * v_data->length++]; 81 | } 82 | 83 | void *_vector_insert(vector *vec_addr, vec_type_t type_size, vec_size_t pos) 84 | { 85 | vector_data *v_data = vector_get_data(*vec_addr); 86 | 87 | vec_size_t new_length = v_data->length + 1; 88 | 89 | // make sure there is enough room for the new element 90 | if (!vector_has_space(v_data)) 91 | { 92 | v_data = vector_realloc(v_data, type_size); 93 | } 94 | memmove(&v_data->buff[(pos + 1) * type_size], &v_data->buff[pos * type_size], 95 | (v_data->length - pos) * type_size); // move trailing elements 96 | 97 | v_data->length = new_length; 98 | 99 | return &v_data->buff[pos * type_size]; 100 | } 101 | 102 | void _vector_erase(vector *vec_addr, vec_type_t type_size, vec_size_t pos, vec_size_t len) 103 | { 104 | vector_data *v_data = vector_get_data(*vec_addr); 105 | // anyone who puts in a bad index can face the consequences on their own 106 | memmove(&v_data->buff[pos * type_size], 107 | &v_data->buff[(pos + len) * type_size], 108 | (v_data->length - pos - len) * type_size); 109 | 110 | v_data->length -= len; 111 | } 112 | 113 | void _vector_remove(vector *vec_addr, vec_type_t type_size, vec_size_t pos) 114 | { 115 | _vector_erase(vec_addr, type_size, pos, 1); 116 | } 117 | 118 | void vector_pop(vector vec) 119 | { 120 | --vector_get_data(vec)->length; 121 | } 122 | 123 | vector _vector_copy(vector vec, vec_type_t type_size) 124 | { 125 | vector_data *vec_data = vector_get_data(vec); 126 | size_t alloc_size = sizeof(vector_data) + vec_data->length * type_size; 127 | vector_data *v = malloc(alloc_size); 128 | memcpy(v, vec_data, alloc_size); 129 | return (void *)&v->buff; 130 | } 131 | -------------------------------------------------------------------------------- /tmp/c-new2/error.h: -------------------------------------------------------------------------------- 1 | /** 2 | The One Programming Language 3 | 4 | File: error.h 5 | _ _ 6 | / \ |\ | |_ Max Base 7 | \_/ | \| |_ Copyright 2021; One Language Contributors 8 | 9 | **/ 10 | 11 | #ifndef ONE_ERROR_H 12 | #define ONE_ERROR_H 13 | 14 | typedef enum 15 | { 16 | ERROR_WARNING, 17 | ERROR_PANIC, 18 | ERROR_TOKEN, 19 | ERROR_PARSER, 20 | ERROR_TREE, 21 | } ErrorType; // TODO 22 | 23 | #define RESET "\033[0m" 24 | #define BLACK "\033[30m" /* Black */ 25 | #define RED "\033[31m" /* Red */ 26 | #define GREEN "\033[32m" /* Green */ 27 | #define YELLOW "\033[33m" /* Yellow */ 28 | #define BLUE "\033[34m" /* Blue */ 29 | #define MAGENTA "\033[35m" /* Magenta */ 30 | #define CYAN "\033[36m" /* Cyan */ 31 | #define WHITE "\033[37m" /* White */ 32 | #define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ 33 | #define BOLDRED "\033[1m\033[31m" /* Bold Red */ 34 | #define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ 35 | #define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ 36 | #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ 37 | #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ 38 | #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ 39 | #define BOLDWHITE "\033[1m\033[37m" /* Bold White */ 40 | 41 | //#define check(format, args...) \ 42 | // printf(GREEN "Check: " format "\n" RESET, ##args); 43 | 44 | //#define check(format, args...) 45 | 46 | #ifndef _ONE_TEST_ 47 | #define debug(format, args...) \ 48 | printf(WHITE "Debug: " format "\n" RESET, ##args); 49 | 50 | #define debug_token(format, args...) \ 51 | printf(YELLOW "Token Debug: " format "\n" RESET, ##args); 52 | 53 | #define debug_lexer(format, args...) \ 54 | printf(CYAN "Lexer Debug: " format "\n" RESET, ##args); 55 | 56 | //#define debug_tree(format, args...) \ 57 | // printf(BLUE "Tree INFO: " format "\n" RESET, ##args); 58 | 59 | #define debug_tree(format, args...) 60 | 61 | #define debug_parser(format, args...) \ 62 | printf(GREEN "Parser Debug: " format "\n" RESET, ##args); 63 | 64 | #define info(format, args...) \ 65 | printf(BOLDWHITE "INFO: " format "\n" RESET, ##args); 66 | 67 | #define info_token(format, args...) \ 68 | printf(BOLDYELLOW "Token INFO: " format "\n" RESET, ##args); 69 | 70 | #define info_tree(format, args...) \ 71 | printf(BOLDBLUE "Tree INFO: " format "\n" RESET, ##args); 72 | 73 | #define info_lexer(format, args...) \ 74 | printf(BOLDCYAN "Lexer INFO: " format "\n" RESET, ##args); 75 | 76 | #define info_parser(format, args...) \ 77 | printf(BOLDGREEN "Parser INFO: " format "\n" RESET, ##args); 78 | 79 | #else 80 | #define debug(format, args...) 81 | 82 | #define debug_token(format, args...) 83 | 84 | #define debug_lexer(format, args...) 85 | 86 | #define debug_tree(format, args...) 87 | 88 | #define debug_tree(format, args...) 89 | 90 | #define debug_parser(format, args...) 91 | 92 | #define info(format, args...) 93 | 94 | #define info_token(format, args...) 95 | 96 | #define info_tree(format, args...) 97 | 98 | #define info_lexer(format, args...) 99 | 100 | #define info_parser(format, args...) 101 | 102 | #endif 103 | 104 | void error(ErrorType type, const char* format, ...); 105 | 106 | char* error_name(ErrorType type); 107 | 108 | #define error_tree(format, args...) error(ERROR_TREE, format, ##args) 109 | 110 | #define error_panic(format, args...) error(ERROR_PANIC, format, ##args) 111 | 112 | #define error_warning(format, ...) error(ERROR_WARNING, format, ##args) 113 | 114 | #define error_token(format, args...) error(ERROR_TOKEN, format, ##args) 115 | 116 | #define error_parser(format, args...) error(ERROR_PARSER, format, ##args) 117 | 118 | #endif //ONE_ERROR_H 119 | -------------------------------------------------------------------------------- /tmp/c-old/src/buffer/testhelp.h: -------------------------------------------------------------------------------- 1 | /* This is a really minimal testing framework for C. 2 | * 3 | * Example: 4 | * 5 | * test_cond("Check if 1 == 1", 1==1) 6 | * test_cond("Check if 5 > 10", 5 > 10) 7 | * test_report() 8 | * 9 | * ---------------------------------------------------------------------------- 10 | * 11 | * Copyright (c) 2010-2012, Salvatore Sanfilippo 12 | * All rights reserved. 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions are met: 16 | * 17 | * * Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * * Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * * Neither the name of Redis nor the names of its contributors may be used 23 | * to endorse or promote products derived from this software without 24 | * specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef __TESTHELP_H 40 | #define __TESTHELP_H 41 | 42 | int __failed_tests = 0; 43 | int __test_num = 0; 44 | #define test_cond(descr, _c) \ 45 | do \ 46 | { \ 47 | __test_num++; \ 48 | printf("%d - %s: ", __test_num, descr); \ 49 | if (_c) \ 50 | printf("PASSED\n"); \ 51 | else \ 52 | { \ 53 | printf("FAILED\n"); \ 54 | __failed_tests++; \ 55 | } \ 56 | } while (0); 57 | #define test_report() \ 58 | do \ 59 | { \ 60 | printf("%d tests, %d passed, %d failed\n", __test_num, __test_num - __failed_tests, __failed_tests); \ 61 | if (__failed_tests) \ 62 | { \ 63 | printf("=== WARNING === We have failed tests here...\n"); \ 64 | exit(1); \ 65 | } \ 66 | } while (0); 67 | 68 | #endif 69 | --------------------------------------------------------------------------------