From 40c36621eb1803268a9c880a986ea0a8172bbb17 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Fri, 13 Mar 2026 15:39:27 +0100 Subject: [PATCH] Grammar and init --- .gitignore | 5 +++ Cargo.lock | 7 ++++ Cargo.toml | 6 ++++ src/grammar.pest | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 0 5 files changed, 110 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/grammar.pest create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore index ad67955..0728338 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,8 @@ target # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + + +# Added by cargo + +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..9622d12 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "archforge" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..95356c1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "archforge" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/src/grammar.pest b/src/grammar.pest new file mode 100644 index 0000000..f6ec143 --- /dev/null +++ b/src/grammar.pest @@ -0,0 +1,92 @@ +WHITESPACE = _{ (" " | "\t" | NEWLINE | COMMENT)+ } +COMMENT = _{ "//" ~ (!NEWLINE ~ ANY)* } + +program = { SOI ~ statement* ~ EOI } + +statement = _{ + function_def + | pointer_assign + | instruction + | function_call +} + +/// // +// FUNCTIONS +/// // + +function_def = { + ident ~ "(" ~ param_list? ~ ")" ~ block +} + +param_list = { + ident ~ ("," ~ ident)* +} + +block = { + "{" ~ statement* ~ "}" +} + +/// // +// INSTRUCTIONS +/// // + +instruction = { + opcode ~ operand_list? +} + +operand_list = { + operand ~ ("," ~ operand)* +} + +/// // +// POINTERS +/// // + +pointer_assign = { + reg ~ "->" ~ reg +} + +pointer_expr = { + "->" ~ reg +} + +/// // +// FUNCTION CALLS +/// // + +function_call = { + ident ~ "(" ~ arg_list? ~ ")" +} + +arg_list = { + operand ~ ("," ~ operand)* +} + +/// // +// OPERANDS +/// // + +operand = _{ + pointer_expr + | reg + | number +} + +global_reg = { "$" ~ ident } +local_reg = { "%" ~ ident } + +reg = { local_reg | global_reg } + +number = @{ + "-"? ~ ASCII_DIGIT+ +} + +/// // +// BASICS +/// // + +opcode = @{ ASCII_ALPHA_UPPER+ } + +ident = @{ + (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..e69de29