ParseTree

This commit is contained in:
2026-09-27 01:05:03 -06:00
parent df2a7c8289
commit 5dd0c85d78
7 changed files with 822 additions and 36 deletions
+20 -20
View File
@@ -106,17 +106,17 @@ namespace spider::asm_ebnf {
binary_digit = tf.choice("01");
ws_char = tf.fn(isWhithespaceCharNotCrLf);
ws_optional = tf.tag(tf.rep(ws_char), "whitespace", true);
whitespace = tf.tag(tf.seq({ ws_char, tf.rep(ws_char) }), "whitespace", true);
newline = tf.choice({ tf["\r\n"], tf["\r"], tf["\n"] });
ws_optional = tf.rep(ws_char);
whitespace = tf.seq({ ws_char, tf.rep(ws_char) });
newline = tf.tag(tf.choice({ tf["\r\n"], tf["\r"], tf["\n"] }), "newline", true);
utf8_char = tf.fn(isUTF8CharNotCrLf);
char_escape = tf.seq({ tf["\\"], utf8_char });
char_content = tf.choice({ char_escape, tf.fn(isUTF8CharLitCont) });
char_lit = tf.seq({ tf["'"], char_content, tf["'"] });
char_lit = tf.tag(tf.seq({ tf["'"], char_content, tf["'"] }), "char_lit", true);
string_char = tf.choice({ char_escape, tf.fn(isUTF8StringLitCont) });
string_lit = tf.seq({ tf["\""], tf.rep(string_char), tf["\""] });
string_lit = tf.tag(tf.seq({ tf["\""], tf.rep(string_char), tf["\""] }), "string_lit", true);
// (* Literals *)
identifier = tf.tag(tf.seq({
@@ -185,29 +185,29 @@ namespace spider::asm_ebnf {
// (* Generalized Instructions *)
opcode = tf.tag(tf.seq({ letter, tf.rep(alpha_num_char) }), "opcode", true);
operand_list = tf.seq({ operand, tf.rep(tf.seq({ tf[","], ws_optional, operand })) });
instruction = tf.tag(tf.seq({ opcode, tf.opt(tf.seq({ whitespace, operand_list })) }), "instruction");
operand_list = tf.tag(tf.seq({ operand, tf.rep(tf.seq({ tf[","], ws_optional, operand })) }), "operand_list", true);
instruction = tf.tag(tf.seq({ opcode, tf.opt(tf.seq({ whitespace, operand_list })) }), "instruction", true);
// (* Added Preprocessor, Annotation *)
annotation_named = tf.tag(tf.seq({ identifier, ws_optional, tf["="], ws_optional, literal_decl }), "annotation_arg_named");
annotation_arg = tf.tag(tf.choice({ annotation_named, literal_decl }), "annotation_arg");
annotation_args = tf.seq({ annotation_arg, tf.rep(tf.seq({ ws_optional, tf[","], ws_optional, annotation_arg })) });
annotation_pars = tf.seq({ tf["("], ws_optional, annotation_args, ws_optional, tf[")"] });
annotation = tf.tag(tf.seq({ tf["@"], identifier, tf.opt(annotation_pars) }), "annotation");
annotation_named = tf.tag(tf.seq({ identifier, ws_optional, tf["="], ws_optional, literal_decl }), "annotation_arg_named", true);
annotation_arg = tf.tag(tf.choice({ annotation_named, literal_decl }), "annotation_arg", true);
annotation_args = tf.tag(tf.seq({ annotation_arg, tf.rep(tf.seq({ ws_optional, tf[","], ws_optional, annotation_arg })) }), "annotation_args", true);
annotation_pars = tf.tag(tf.seq({ tf["("], ws_optional, annotation_args, ws_optional, tf[")"] }), "annotation_pars", true);
annotation = tf.tag(tf.seq({ tf["@"], identifier, tf.opt(annotation_pars) }), "annotation", true);
preprocessor_val = tf.choice({ identifier, literal_decl });
preprocessor = tf.tag(tf.seq({ tf["#"], identifier, whitespace, preprocessor_val }), "preprocessor");
preprocessor = tf.tag(tf.seq({ tf["#"], identifier, whitespace, preprocessor_val }), "preprocessor", true);
// (* Line Structure & Program *)
label = tf.tag(tf.seq({ identifier, tf[":"] }), "label");
line_label = tf.seq({ label, tf.opt(tf.seq({ whitespace, instruction })) });
line_annotation = tf.seq({ annotation, tf.opt(tf.seq({ whitespace, instruction })) });
line_content = tf.choice({ preprocessor, line_annotation, line_label, instruction });
line = tf.seq({ ws_optional, tf.opt(line_content), ws_optional, tf.opt(comment), newline });
line_last = tf.seq({ ws_optional, tf.opt(line_content), ws_optional, tf.opt(comment) });
program = tf.seq({ tf.rep(line), tf.opt(line_last) });
label = tf.tag(tf.seq({ identifier, tf[":"] }), "label", true);
line_label = tf.tag(tf.seq({ label, tf.opt(tf.seq({ whitespace, instruction })) }), "line_label", true);
line_annotation = tf.tag(tf.seq({ annotation, tf.opt(tf.seq({ whitespace, instruction })) }), "line_annotation", true);
line_content = tf.tag(tf.choice({ preprocessor, line_annotation, line_label, instruction }), "line_content", true);
line = tf.tag(tf.seq({ ws_optional, tf.opt(line_content), ws_optional, tf.opt(comment), newline }), "line", true);
line_last = tf.tag(tf.seq({ ws_optional, tf.opt(line_content), ws_optional, tf.opt(comment) }), "line_last", true);
program = tf.tag(tf.seq({ tf.rep(line), tf.opt(line_last) }), "program", true);
}
}