beginning of compiler
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
(* Spider Assembly EBNF | Sintek Analytics @ 2026 | All Rights Reserved *)
|
||||
|
||||
(* Characters & Structures *)
|
||||
letter = ? isUTF8Alpha ? ;
|
||||
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
|
||||
alpha_num_char = letter | digit ;
|
||||
|
||||
hex_digit = digit | "A" | "B" | "C" | "D" | "E" | "F" | "a" | "b" | "c" | "d" | "e" | "f" ;
|
||||
octal_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
|
||||
binary_digit = "0" | "1" ;
|
||||
|
||||
ws_char = ? isWhithespaceCharNotCrLf ? ;
|
||||
ws_optional = { ws_char } ;
|
||||
whitespace = ws_char , { ws_char } ;
|
||||
newline = "\r" | "\n" | "\r\n" ;
|
||||
utf8_char = ? isUTF8CharNotCrLf ? ;
|
||||
|
||||
char_escape = "\\", utf8_char ;
|
||||
char_content = char_escape | ? isUTF8CharLitCont ? ; (* Not ' or \ *)
|
||||
char_lit = "'", char_content, "'" ;
|
||||
|
||||
string_char = char_escape | ? isUTF8StringLitCont ? ; (* Not " or \ *)
|
||||
string_lit = '"', { string_char }, '"' ;
|
||||
|
||||
(* Literals *)
|
||||
identifier = ( letter | "_" ) , { alpha_num_char | "_" } ;
|
||||
comment = ";" , { utf8_char } ;
|
||||
|
||||
sign = "+" | "-" ;
|
||||
exponent_marker = "e" | "E" ;
|
||||
exponent = exponent_marker , [ sign ] , digit , { digit } ;
|
||||
|
||||
decimal_lit = [ sign ] , digit , { digit } , [ "B" | "S" | "I" | "L" ] ;
|
||||
float_lit = [ sign ] , (
|
||||
( digit , { digit } , "." , digit , { digit } , [ exponent ] ) |
|
||||
( "." , digit , { digit } , [ exponent ] ) |
|
||||
( digit , { digit } , exponent )
|
||||
) , [ "F" | "D" ] ;
|
||||
|
||||
hex_lit = [ sign ] , "0x" , hex_digit , { hex_digit } ;
|
||||
octal_lit = [ sign ] , "0c" , octal_digit , { octal_digit } ;
|
||||
binary_lit = [ sign ] , "0b" , binary_digit , { binary_digit } ;
|
||||
|
||||
literal = decimal_lit | float_lit | hex_lit | octal_lit | binary_lit | string_lit | char_lit ;
|
||||
literal_cast = ("B" | "S" | "I" | "L" | "F" | "D"), ws_optional, "(", ws_optional, literal, ws_optional, ")" ;
|
||||
literal_decl = literal | literal_cast ;
|
||||
|
||||
(* Operands *)
|
||||
register = "R" , alpha_num_char , alpha_num_char ;
|
||||
addrm_ind = "[", ws_optional, literal_decl, ws_optional, "]" ;
|
||||
addrm_ptr = "[", ws_optional, register, ws_optional, "]" ;
|
||||
addrm_idx = "[", ws_optional, register, ws_optional, "+", ws_optional, literal_decl, ws_optional, "]";
|
||||
addrm_sca = "[", ws_optional, register, ws_optional, "+", register, ws_optional, "*", ws_optional, literal_decl, ws_optional, "]";
|
||||
addrm_dis = "[", ws_optional, register, ws_optional, "+", register, ws_optional, "*", ws_optional, literal_decl, ws_optional, "+", ws_optional, literal_decl, ws_optional, "]";
|
||||
addr_modes = addrm_ind | addrm_ptr | addrm_idx | addrm_sca | addrm_dis ;
|
||||
operand = register | identifier | literal_decl | addr_modes ;
|
||||
|
||||
(* Generalized Instructions *)
|
||||
opcode = letter , { alpha_num_char } ;
|
||||
operand_list = operand , { "," , ws_optional , operand } ;
|
||||
instruction = opcode , [ whitespace , operand_list ] ;
|
||||
|
||||
(* Added Preprocessor, Sections, and Metadata Syntaxes *)
|
||||
include_decl = "include", whitespace, string_lit ;
|
||||
annotation_oper = identifier, [ ws_optional, "=", ws_optional, literal_decl ] ;
|
||||
annotation_ops = annotation_oper , { ws_optional, "," , ws_optional , annotation_oper } ;
|
||||
annotation_args = "(", ws_optional, annotation_ops, ws_optional, ")" ;
|
||||
annotation = "@", identifier, [ annotation_args ] ;
|
||||
section_decl = "section", whitespace, ".", identifier ;
|
||||
|
||||
(* Line Structure *)
|
||||
label = identifier, ":" ;
|
||||
line_content = include_decl | section_decl | ( [ annotation, whitespace ], [ label, ws_optional ], [ instruction ] ) ;
|
||||
line = ws_optional, [ line_content ], ws_optional , [ comment ] , newline ;
|
||||
line_last = ws_optional, [ line_content ], ws_optional , [ comment ] ;
|
||||
program = { line }, [ line_last ] ;
|
||||
Reference in New Issue
Block a user