From 516d41cee8660ab0b53ad5b23bb61f1c1ed5f86a Mon Sep 17 00:00:00 2001 From: RobbyV2 Date: Fri, 12 Apr 2024 16:37:53 -0500 Subject: [PATCH] Init --- .gitignore | 3 + Cargo.lock | 775 ++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 22 ++ LICENSE | 21 ++ Pseudolang-Logo.png | Bin 0 -> 4935 bytes Pseudolang.md | 212 +++++++++++ build_release.sh | 5 + examples/hello_world.pc | 1 + readme.md | 70 ++++ src/interpreter.rs | 6 + src/lexer.rs | 159 +++++++++ src/main.rs | 60 ++++ src/parser.rs | 10 + 13 files changed, 1344 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 Pseudolang-Logo.png create mode 100644 Pseudolang.md create mode 100644 build_release.sh create mode 100644 examples/hello_world.pc create mode 100644 readme.md create mode 100644 src/interpreter.rs create mode 100644 src/lexer.rs create mode 100644 src/main.rs create mode 100644 src/parser.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..10b5b5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.vscode +*.exe +/target \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..4ca598f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,775 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "cc" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + +[[package]] +name = "clap" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +dependencies = [ + "atty", + "bitflags 1.3.2", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "color-eyre" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" +dependencies = [ + "backtrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", +] + +[[package]] +name = "const-sha1" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb58b6451e8c2a812ad979ed1d83378caa5e927eef2622017a45f251457c2c9d" + +[[package]] +name = "cross" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6abfd6b5130d5d470548ef0d04c9201805c3825b6e992009774c37738a954a" +dependencies = [ + "atty", + "clap", + "color-eyre", + "const-sha1", + "ctrlc", + "directories", + "dunce", + "eyre", + "home", + "libc", + "nix 0.24.3", + "owo-colors", + "rustc_version", + "serde", + "serde_ignored", + "serde_json", + "shell-escape", + "shell-words", + "tempfile", + "thiserror", + "toml", + "which", + "winapi", +] + +[[package]] +name = "ctrlc" +version = "3.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "672465ae37dc1bc6380a6547a8883d5dd397b0f1faaad4f265726cc7042a5345" +dependencies = [ + "nix 0.28.0", + "windows-sys", +] + +[[package]] +name = "directories" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dunce" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + +[[package]] +name = "fastrand" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "is_ci" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.5.0", + "libc", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "nix" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", +] + +[[package]] +name = "nix" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "os_str_bytes" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +dependencies = [ + "supports-color", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pseudolang" +version = "0.0.1" +dependencies = [ + "cross", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_users" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "serde_ignored" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8e319a36d1b52126a0d608f24e93b2d81297091818cd70625fcf50a15d84ddf" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shell-escape" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f" + +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "supports-color" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ba6faf2ca7ee42fdd458f4347ae0a9bd6bcc445ad7cb57ad82b383f18870d6f" +dependencies = [ + "atty", + "is_ci", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..81fbc08 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,22 @@ +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[package] +name = "pseudolang" +version = "0.0.1" +edition = "2021" +description = "A pseudolang interpreter written in Rust" + +[target.x86_64-unknown-linux-gnu] +rustflags = ["-C", "linker=x86_64-linux-gnu-gcc"] + +[target.x86_64-apple-darwin] +rustflags = ["-C", "linker=x86_64-apple-darwin15-clang"] + +[profile.dev] +panic = "abort" + +[profile.release] +panic = "abort" + +[dependencies] +cross="0.2.5" \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..69aa3a9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 RobbyV2, Vaedz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Pseudolang-Logo.png b/Pseudolang-Logo.png new file mode 100644 index 0000000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qU}h@TqCQ){{lzJ8VVbVwHbFwD=0ACz zUvW3Qdg(V={yy52aK+lBA(@M}`IZFN3tplBA7`8Y9%eA=VTS|^{Q1RYsAqbk^tyBS FKLK-11@Zs@ literal 0 HcmV?d00001 diff --git a/Pseudolang.md b/Pseudolang.md new file mode 100644 index 0000000..eaaa279 --- /dev/null +++ b/Pseudolang.md @@ -0,0 +1,212 @@ +# PseudoLang Guide + +## Assignment, Display, Input + +`a <- b` + +Evaluates b and then assigns a copy of the result to the variable a + +`DISPLAY(a)` + +Prints the value of a. + +`INPUT()` + +Accepts a value from the user (command line) and returns the input value. + +## Arithmetic Operators and Numeric Procedures + +`a + b` + +`a - b` + +`a * b` + +`a / b` + +`a MOD b` + +The arithmetic operators +, -, *, /, and MOD are used to perform arithmetic on a and b. + +`RANDOM(a, b)` + +Generates and returns a random integer from a to b, including a and b. Each result is equally likely to occur. + +## Relational and Boolean Operators + +`a = b` + +`a NOT= b` + +`a > b` + +`a < b` + +`a >= b` + +`a <= b` + +The relational operators =, !=, >, <, >=, and <= are used to test the relationship between two variables, expressions, or values. A comparison using relational operators evaluates to a Boolean value. + +`a AND b` + +Evaluates to true if both a and b are true; otherwise evaluates to false. + +`a OR b` + +Evaluates to true if a is true or if b is true or if both a and b are true; otherwise evaluates to false. + +`NOT a` + +Evaluates to true if a is false; otherwise evaluates to false. + +## Selection + +```text +IF(a) +{ + +} +``` + +The code in block of statements is executed if the Boolean expression a evaluates to true; no action is taken if condition evaluates to false. + +```text +IF(a) +{ + +} +ELSE +{ + +} +``` + +The code in first block of statements is executed if the Boolean expression a evaluates to true; otherwise the code in second block of statements is executed. + +```text +REPEAT n TIMES +{ + +} +``` + +The code inside is executed n times. + +```text +REPEAT UNTIL(a) +{ + +} +``` + +The code in block of statements is repeated until the Boolean expression a evaluates to true. + +## List operations + +`aList <- [1, 2, 3]` + +Creates a new list that contains the values 1, 2, 3 at index 1, 2, 3. Respectively and assigns it to aList, this also works with empty lists. + +`aList <- bList` + +Assigns a copy of the list bList to the list aList. + +`aList[i]` + +Accesses the element of aList at index i. The first element of aList is at index 1 and is accessed using the notation aList[1]. + +`b <- aList[i]` or `aList[i] <- b` + +Assigns the value of aList[i] to the variable b, or assigns the value of aList[i] to the variable b. + +`aList[b] <- aList[c]` + +Assigns the value of aList[c] to aList[b]. + +`INSERT(aList, i, b)` + +Any values in aList at indices greater than or equal to i are shifted one position to the right. The length of the list is increased by 1, and value b is placed at index i in aList. + +`APPEND(aList, b)` + +The length of aList is increased by 1, and value b is placed at +the end of aList. + +`REMOVE(aList, i)` + +Removes the item at index i in aList and shifts to the left any values at indices greater than i. The length of aList is decreased by 1. + +`LENGTH(aList)` + +Evaluates to the number of elements in aList (1 through length). + +```text +FOR EACH item IN aList +{ + +} +``` + +The variable item is assigned the value of each element of aList sequentially, in order, from the first element to the last element. The statements are executed once for each assignment of item. + +```text +PROCEDURE procName(a, b) +{ + +} +``` + +Defines procName as a procedure that takes zero or more arguments. The procedure contains statements. The procedure procName can be called using the following notation, where arg1 is assigned to parameter1, arg2 is assigned to parameter2 and so on. +`procName(arg1, arg2)` + +`RETURN(a)` + +Returns the flow of control to the point where the procedure was +called and returns the value of a. Can be used as a value itself. + +## Data Types + +`1` + +Integer (32 bit) + +`0.1` + +Float (32 bit) + +`"a"` + +String (32 bit) + +`TRUE` or `FALSE` + +Boolean + + +## Outside of College Board - Extras + +```text +COMMENT a +``` + +```text +COMMENTBLOCK +a +b +COMMENTBLOCK +``` + +A comment (multi-line or single-line), anything on the line after this or in between does not affect the code. + +`DISPLAYINLINE(a)` + +Prints the value of a, without a new line character. + +`IMPORT a` + +Imports a library (including functions & variables defined in that file) from a file. + +## Limitations + +Since a lot of the syntax is text like COMMENT or TRUE, you may not set variables as such, and the interpreter will try to raise an error if it occurs. diff --git a/build_release.sh b/build_release.sh new file mode 100644 index 0000000..5cb7671 --- /dev/null +++ b/build_release.sh @@ -0,0 +1,5 @@ +#!/bin/bash +chmod +x build_release.sh +cross build --target x86_64-unknown-linux-gnu --release +cross build --target x86_64-apple-darwin --release +cross build --target x86_64-pc-windows-msvc --release diff --git a/examples/hello_world.pc b/examples/hello_world.pc new file mode 100644 index 0000000..56c8727 --- /dev/null +++ b/examples/hello_world.pc @@ -0,0 +1 @@ +DISPLAY("Hello, World!") \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..52e1539 --- /dev/null +++ b/readme.md @@ -0,0 +1,70 @@ +# WARNING +# This project is still in development, and is not AT ALL yet ready for use. + +# [PseudoLang](https://pseudo-lang.org/) + +

+ Pseudolang Logo +

+ +Welcome to Pseudolang! Pseudolang is a simple programming language written in Rust, inspired by The College Board's AP Computer Science Pseudocode + +This project aims to fully support Windows, Linux (Debian), and MacOS. + +## Releases + +Soon, under the releases section you will be able to find pre-compiled binaries for all the languages and operating systems. + +## Use + +To use the compiled versions, run the executable in the directory of the file ending with `.pc`, and pass the file as and argument. Ex: `./fplc main.pc` + +It is highly recommended to add the executable to your PATH, so you can simply run `fplc`. + +Free Pseudolang Compiler = fplc (like gcc :) + +## Compiling + +In order to compile the project yourself, you will need to have rust installed. + +- Install [**rust**](https://www.rust-lang.org/tools/install), and make sure you have it added to PATH. +- Clone the repository `git clone https://github.com/Pseudolang-Software-Foundation/PseudoLang.git` +- - To build **release**, you will need bash. Then run `./build_release.sh`. The binaries will be in folders under `target` for their operating systems. +- - To build **debug**, simply run `cargo build`. The binary will be in the `target/debug` folder. + +The output will be in the target directory in debug as an executable for the 3 supported operating systems. + +## Examples + +[Pseudolang.md](Pseudolang.md) contains a full explanation of Pseudolang and features specific to PseudoLang. + +We will be adding examples of how to use PseudoLang. Check back soon! + +## Todo + +- [ ] Complete +- [ ] Web version +- [ ] Installer +- [ ] Library support (remote procedures, calls, etc) +- [ ] Raise error +- [ ] Networking +- [ ] Have source in other languages than rust +- [ ] Create release build +- [ ] Man page and and help menu on simple command run +- [ ] Examples +- [ ] VSCode syntax highlighter extension and runner +- [ ] GitHub issue template +- [ ] Error handling (suggestions, etc) +- [ ] Code todos + +## Issues + +Feel free to make issues for any bugs or trouble that you experience with this! Especially since this is new, and there are going to be a lot of them! + +## Contributing + +We welcome contributions! If there are any bugs, or particularly pointing out limitations in [Pseudolang.md](Pseudolang.md) at the bottom, or adding things from the todo list, please make a pull request! + +## License + +This project is licensed under the MIT License - see the [LICENSE file](LICENSE) file for details. diff --git a/src/interpreter.rs b/src/interpreter.rs new file mode 100644 index 0000000..14442b2 --- /dev/null +++ b/src/interpreter.rs @@ -0,0 +1,6 @@ +use crate::parser::AstNode; // Import AstNode enum from parser + +pub fn run(ast: AstNode) -> Result { + // Implement logic to interpret the AST and return the program output or an error message + Err("Interpreter functionality not implemented yet".to_string()) +} diff --git a/src/lexer.rs b/src/lexer.rs new file mode 100644 index 0000000..b961d33 --- /dev/null +++ b/src/lexer.rs @@ -0,0 +1,159 @@ +#[derive(Debug, PartialEq)] +#[allow(dead_code)] +pub enum Token { + Unknown, + Identifier(String), + + // Assignment, Display, Input + Assignment, + Display, + Input, + + // Arithmetic Operators + Plus, + Minus, + Multiply, + Divide, + Modulo, + + // Relational and Boolean Operators + Equal, + NotEqual, + GreaterThan, + LessThan, + GreaterThanOrEqual, + LessThanOrEqual, + And, + Or, + Not, + + // Selection + If, + Else, + Repeat, + RepeatUntil, + + // List operations + ListCreate, + ListAssign, + ListAccess, + ListInsert, + ListAppend, + ListRemove, + ListLength, + ForEach, + + // Procedures + Procedure, + Return, + + // Data Types + Integer(i32), + Float(f32), + String(String), + Boolean(bool), + + // Comments + Comment, + CommentBlock, + + // Outside of AP + DisplayInline, +} + +pub struct Lexer<'a> { + chars: std::str::Chars<'a>, +} + +impl<'a> Lexer<'a> { + pub fn new(input: &'a str) -> Self { + Lexer { chars: input.chars() } + } + + pub fn tokenize(&mut self) -> Vec { + let mut tokens = Vec::new(); + while let Some(token) = self.next_token() { + tokens.push(token); + } + tokens + } + + fn next_token(&mut self) -> Option { + let next_char = self.chars.next()?; + + if next_char.is_whitespace() { + return self.next_token(); + } + + match next_char { + '=' => Some(Token::Equal), + '>' => Some(Token::GreaterThan), + '<' => Some(Token::LessThan), + '+' => Some(Token::Plus), + '-' => Some(Token::Minus), + '*' => Some(Token::Multiply), + '/' => Some(Token::Divide), + '0'..='9' => { + let mut number = next_char.to_digit(10)? as i32; + while let Some(next_char) = self.chars.clone().next() { + if let Some(digit) = next_char.to_digit(10) { + number = number * 10 + digit as i32; + self.chars.next(); + } else { + break; + } + } + Some(Token::Integer(number)) + } + 'a'..='z' | 'A'..='Z' => { + let mut identifier = String::new(); + identifier.push(next_char); + while let Some(next_char) = self.chars.clone().next() { + if next_char.is_alphanumeric() || next_char == '_' { + identifier.push(next_char); + self.chars.next(); + } else { + break; + } + } + match identifier.as_str() { + /* + TODO: + 0. <- is classified as < and -, not just <- + EX: <- prints [LessThan, Minus] instead of [Assignment] + + 1. sometimes, unknown tokens cause the rest of the program to not be recognized, outputting [] + also make it so that unknown tokens are printed as themselves with Identifier + EX: a < prints [] instead of [Identifier("a"), LessThan] + < DISPLAY aaa prints [LessThan, DISPLAY] instead of [LessThan, DISPLAY, Identifier("aaa")] + a < prints [] instead of [Identifier("a"), LessThan] + + 2. Also, strings are not recognized, anything in double quotes should be a string + + 3. Parameters DISPLAY("hi") should work by having tokens in between parentheses, so DISPLAY("hi") would be [DISPLAY(String("hi"))] + + 4. Lists + */ + "<-" => Some(Token::Assignment), + "DISPLAY" => Some(Token::Display), + "INPUT" => Some(Token::Input), + "MOD" => Some(Token::Modulo), + ">=" => Some(Token::GreaterThanOrEqual), + "<=" => Some(Token::LessThanOrEqual), + "IF" => Some(Token::If), + "ELSE" => Some(Token::Else), + "REPEAT" => Some(Token::Repeat), + "REPEAT UNTIL" => Some(Token::RepeatUntil), + "NOT" => Some(Token::Not), + "AND" => Some(Token::And), + "OR" => Some(Token::Or), + "COMMENT" => Some(Token::Comment), + "COMMENTBLOCK" => Some(Token::CommentBlock), + "RETURN" => Some(Token::Return), + _ => Some(Token::Identifier(identifier)), + } + } + _ => Some(Token::Unknown), + } + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c05f98c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,60 @@ +use std::fs; +use std::io::Read; + +mod interpreter; +mod lexer; +mod parser; + +use lexer::Lexer; + +fn main() { + let args = std::env::args().skip(1).collect::>(); + + if args.len() != 2 { + eprintln!("Usage: {} ", env!("CARGO_PKG_NAME")); + std::process::exit(0); + } + + let input_file = &args[0]; + let mut file = match fs::File::open(input_file) { + Ok(file) => file, + Err(error) => { + eprintln!("Error opening file {}: {}", input_file, error); + std::process::exit(1); + } + }; + + let mut source_code = String::new(); + if let Err(error) = file.read_to_string(&mut source_code) { + eprintln!("Error reading file {}: {}", input_file, error); + std::process::exit(1); + } + + let mut lexer = Lexer::new(&source_code); + let tokens = lexer.tokenize(); + println!("{:?}", tokens); + println!("Successfully lexed program"); + + match parser::parse(tokens) { + Ok(ast) => { + let output = interpreter::run(ast); + + if let Err(err) = output { + eprintln!("Error during execution: {}", err); + std::process::exit(1); + } + + let output_file = &args[1]; + if let Err(error) = fs::write(output_file, output.unwrap()) { + eprintln!("Error writing to file {}: {}", output_file, error); + std::process::exit(1); + } + + println!("Successfully executed program and wrote output to {}", output_file); + } + Err(err) => { + eprintln!("Error parsing code: {}", err); + std::process::exit(1); + } + } +} \ No newline at end of file diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..d720dc7 --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,10 @@ +use crate::lexer::Token; // Import Token enum from lexer + +pub enum AstNode { + // Define different AST node types (e.g., Assignment, Expression, Statement, Block etc.) +} + +pub fn parse(tokens: Vec) -> Result { + // Implement logic to parse the token stream and return the AST or an error message + Err("Parser functionality not implemented yet".to_string()) +}