Grammar and init
This commit is contained in:
@@ -19,3 +19,8 @@ target
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# 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.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
|||||||
Generated
+7
@@ -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"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "archforge"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
@@ -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 | "_")*
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user