summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appl/cmd/mkfile14
-rw-r--r--appl/cmd/sh9.b (renamed from sh9.b)0
-rw-r--r--appl/cmd/sh92.b (renamed from sh92.b)53
-rw-r--r--appl/lib/mkfile19
-rw-r--r--appl/lib/sh9parser.b (renamed from sh9parser.b)24
-rw-r--r--appl/lib/sh9util.b (renamed from sh9util.b)2
-rw-r--r--appl/mkfile7
-rw-r--r--mkconfig1
-rw-r--r--mkfile38
-rw-r--r--module/mkfile9
-rw-r--r--module/mkmod16
-rw-r--r--module/sh9parser.m (renamed from sh9parser.m)7
-rw-r--r--module/sh9util.m (renamed from sh9util.m)2
13 files changed, 125 insertions, 67 deletions
diff --git a/appl/cmd/mkfile b/appl/cmd/mkfile
new file mode 100644
index 0000000..a422ace
--- /dev/null
+++ b/appl/cmd/mkfile
@@ -0,0 +1,14 @@
+<../../mkconfig
+
+TARG=\
+ sh9.dis\
+ sh92.dis\
+
+SYSMODULES=\
+ sh9util.m\
+ sh9parser.m\
+ sys.m\
+
+DISBIN=$ROOT/dis
+
+<$ROOT/mkfiles/mkdis
diff --git a/sh9.b b/appl/cmd/sh9.b
index 64d88e1..64d88e1 100644
--- a/sh9.b
+++ b/appl/cmd/sh9.b
diff --git a/sh92.b b/appl/cmd/sh92.b
index bce58c3..9748da7 100644
--- a/sh92.b
+++ b/appl/cmd/sh92.b
@@ -63,11 +63,12 @@ S_CALL: con "CALL";
tokenize(line: string, line_n: int): array of ref TokNode {
toks : list of ref TokNode;
- last_tok: TokNode;
+ last_tok:= ref TokNode;
last_tok.start = -1;
last_tok.line = -1;
last_tok.tok = "";
last_tok.typ = S_UNKNOWN;
+ k:=0;
for (i := 0; i < len line; i++) {
if (last_tok.typ == S_DQSTR) {
@@ -77,7 +78,7 @@ tokenize(line: string, line_n: int): array of ref TokNode {
if ((last_tok.tok[l-1:] != "\\") || ((last_tok.tok[l-1:] == "\\") && (last_tok.tok[l-2:l-1] == "\\"))) {
# end of str
last_tok.tok = last_tok.tok + line[i:i+1];
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
+ (last_tok, toks) = set_last_tok(last_tok, toks);
} else {
# escaped dqte, just continue
last_tok.tok = last_tok.tok + line[i:i+1];
@@ -94,7 +95,7 @@ tokenize(line: string, line_n: int): array of ref TokNode {
if ((last_tok.tok[l-1:] != "\\") || ((last_tok.tok[l-1:] == "\\") && (last_tok.tok[l-2:l-1] == "\\"))) {
# end of str
last_tok.tok = last_tok.tok + line[i:i+1];
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
+ (last_tok, toks) = set_last_tok(last_tok, toks);
} else {
# escaped sqte, just continue
last_tok.tok = last_tok.tok + line[i:i+1];
@@ -107,45 +108,45 @@ tokenize(line: string, line_n: int): array of ref TokNode {
} else {
case (line[i:i+1]) {
" " or "\t" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
+ (last_tok, toks) = set_last_tok(last_tok, toks);
};
"=" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
- toks = ref mk_tok(i, line_n, "=", S_EQ) :: toks;
+ (last_tok, toks) = set_last_tok(last_tok, toks);
+ toks = mk_tok(i, line_n, "=", S_EQ) :: toks;
};
";" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
- toks = ref mk_tok(i, line_n, ";", S_SEMIC) :: toks;
+ (last_tok, toks) = set_last_tok(last_tok, toks);
+ toks = mk_tok(i, line_n, ";", S_SEMIC) :: toks;
};
"$" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
- toks = ref mk_tok(i, line_n, "$", S_DOL) :: toks;
+ (last_tok, toks) = set_last_tok(last_tok, toks);
+ toks = mk_tok(i, line_n, "$", S_DOL) :: toks;
};
"(" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
- toks = ref mk_tok(i, line_n, "(", S_LPAR) :: toks;
+ (last_tok, toks) = set_last_tok(last_tok, toks);
+ toks = mk_tok(i, line_n, "(", S_LPAR) :: toks;
};
")" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
- toks = ref mk_tok(i, line_n, ")", S_RPAR) :: toks;
+ (last_tok, toks) = set_last_tok(last_tok, toks);
+ toks = mk_tok(i, line_n, ")", S_RPAR) :: toks;
};
"{" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
- toks = ref mk_tok(i, line_n, "{", S_LCURLY) :: toks;
+ (last_tok, toks) = set_last_tok(last_tok, toks);
+ toks = mk_tok(i, line_n, "{", S_LCURLY) :: toks;
};
"}" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
- toks = ref mk_tok(i, line_n, "}", S_RCURLY) :: toks;
+ (last_tok, toks) = set_last_tok(last_tok, toks);
+ toks = mk_tok(i, line_n, "}", S_RCURLY) :: toks;
};
"\"" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
+ (last_tok, toks) = set_last_tok(last_tok, toks);
last_tok.start = i;
last_tok.line = line_n;
last_tok.typ = S_DQSTR;
last_tok.tok = last_tok.tok + line[i:i+1];
};
"'" => {
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
+ (last_tok, toks) = set_last_tok(last_tok, toks);
last_tok.start = i;
last_tok.line = line_n;
last_tok.typ = S_SQSTR;
@@ -162,8 +163,8 @@ tokenize(line: string, line_n: int): array of ref TokNode {
}
}
}
- (last_tok, toks) = set_last_tok(ref last_tok, toks);
- toks = ref mk_tok(i, line_n, "", S_EOL) :: toks;
+ (last_tok, toks) = set_last_tok(last_tok, toks);
+ toks = mk_tok(i, line_n, "", S_EOL) :: toks;
toks = reverse_list(toks);
return to_array(toks);
}
@@ -180,10 +181,16 @@ empty(toks: array of ref TokNode) {
sys->print("EMPTY\n");
}
+Te: adt{
+ s: string;
+};
+
init(ctxt: ref Draw->Context, argv: list of string) {
sys = load Sys Sys->PATH;
sh9u = load Sh9Util Sh9Util->PATH;
sh9p = load Sh9Parser Sh9Parser->PATH;
+ sh9p->init();
+
assign_g_semic : GrammarNode = (array [] of {S_ID, S_EQ, S_EXPR, S_SEMIC}, S_UNKNOWN, stmt_assign);
assign_g_eol : GrammarNode = (array [] of {S_ID, S_EQ, S_EXPR, S_EOL}, S_UNKNOWN, stmt_assign);
@@ -193,7 +200,7 @@ init(ctxt: ref Draw->Context, argv: list of string) {
grammar: array of ref GrammarNode;
grammar = array [] of {ref assign_g_semic, ref assign_g_eol, ref sqstr_expr_g, ref str_expr_g, ref cmd_call_g};
- toks1 := tokenize("A = 'smth \"test\" ';", 0);
+ toks1 := tokenize("AB = 'smth \"test\" ';", 0);
print_toks(toks1);
sys->print("Parse\n");
parse_toks(toks1, grammar);
diff --git a/appl/lib/mkfile b/appl/lib/mkfile
new file mode 100644
index 0000000..0becc2b
--- /dev/null
+++ b/appl/lib/mkfile
@@ -0,0 +1,19 @@
+<../../mkconfig
+
+TARG=\
+ sh9util.dis\
+ sh9parser.dis\
+
+
+SYSMODULES=\
+ sh9util.m\
+ sh9parser.m\
+ sys.m\
+
+
+MODULES=\
+
+
+DISBIN=$ROOT/dis/lib
+
+<$ROOT/mkfiles/mkdis
diff --git a/sh9parser.b b/appl/lib/sh9parser.b
index fcae119..ac46b40 100644
--- a/sh9parser.b
+++ b/appl/lib/sh9parser.b
@@ -24,18 +24,29 @@ GrammarNode.print_expr(gn: self ref GrammarNode) {
}
}
-mk_tok(start: int, line: int, tok: string, typ: string) : TokNode {
+init()
+{
+ sys = load Sys Sys->PATH;
+ sh9u = load Sh9Util Sh9Util->PATH;
+}
+
+mk_tok(start: int, line: int, tok: string, typ: string) : ref TokNode {
tok_node: TokNode;
tok_node.start = start;
tok_node.line = line;
tok_node.tok = tok;
tok_node.typ = typ;
- return tok_node;
+ return ref tok_node;
}
-set_last_tok(last_tok: ref TokNode, toks: list of ref TokNode): (TokNode, list of ref TokNode) {
+set_last_tok(last_tok: ref TokNode, toks: list of ref TokNode): (ref TokNode, list of ref TokNode) {
+ sys->print("last_tok: %s\n", last_tok.typ);
ret_tok: TokNode;
- ret_tok = *last_tok;
+ #ret_tok = *last_tok;
+ ret_tok.typ = last_tok.typ;
+ ret_tok.start = last_tok.start;
+ ret_tok.tok = last_tok.tok;
+ ret_tok.line = last_tok.line;
if (last_tok.typ != S_UNKNOWN) {
toks = last_tok :: toks;
ret_tok.typ = S_UNKNOWN;
@@ -43,7 +54,8 @@ set_last_tok(last_tok: ref TokNode, toks: list of ref TokNode): (TokNode, list o
ret_tok.tok = "";
ret_tok.line = -1;
}
- return (ret_tok, toks);
+ sys->print("ret_tok: %s\n", ret_tok.typ);
+ return (ref ret_tok, toks);
}
print_toks(toks: array of ref TokNode) {
@@ -118,7 +130,7 @@ parse_toks(toks: array of ref TokNode, g: array of ref GrammarNode): array of re
sys->print("Before replace: ");
print_toks_short(toks);
gj.callback(toks[lt-i: lt-i+len gj.expr]);
- toks = replace_toks(toks, lt-i, len gj.expr, array[] of {ref mk_tok(toks[lt - i].start, toks[lt - i].line, "", gj.transform)});
+ toks = replace_toks(toks, lt-i, len gj.expr, array[] of {mk_tok(toks[lt - i].start, toks[lt - i].line, "", gj.transform)});
sys->print("After replace: ");
changed = 1;
break fast;
diff --git a/sh9util.b b/appl/lib/sh9util.b
index f74032e..7452a13 100644
--- a/sh9util.b
+++ b/appl/lib/sh9util.b
@@ -8,7 +8,7 @@ reverse_list[T](toks: list of T): list of T
out : list of T;
for (i := 0; i < lt; i ++) {
tok := hd toks;
- #toks = tl toks;
+ toks = tl toks;
out = tok :: out;
}
return out;
diff --git a/appl/mkfile b/appl/mkfile
new file mode 100644
index 0000000..1946c4f
--- /dev/null
+++ b/appl/mkfile
@@ -0,0 +1,7 @@
+<../mkconfig
+
+DIRS=\
+ lib\
+ cmd\
+
+<$ROOT/mkfiles/mksubdirs
diff --git a/mkconfig b/mkconfig
new file mode 100644
index 0000000..b72b198
--- /dev/null
+++ b/mkconfig
@@ -0,0 +1 @@
+<$ROOT/mkconfig
diff --git a/mkfile b/mkfile
index cf68f33..ded2d68 100644
--- a/mkfile
+++ b/mkfile
@@ -1,35 +1,7 @@
-<../../../mkconfig
+<mkconfig
-TARG=sh92.dis\
- sh9util.dis\
- sh9parser.dis\
+DIRS=\
+ module\
+ appl\
-INS= $ROOT/dis/sh92.dis\
- $ROOT/dis/sh9/sh9util.dis\
- $ROOT/dis/sh9/sh9parser.dis\
-
-SYSMODULES=\
- sys.m\
-
-DISBIN=$ROOT/dis/sh9
-
-<$ROOT/mkfiles/mkdis
-
-all:V: $TARG
-
-install:V: $INS
- cp $DISBIN/sh92.dis $DISBIN/..
-
-nuke:V: clean
- rm -f $INS
-
-clean:V:
- rm -f *.dis *.sbl
-
-uninstall:V:
- rm -f $INS
-
-$ROOT/dis/sh92.dis: sh92.dis
- mkdir $DISBIN/ && rm -f $ROOT/dis/sh92.dis && cp sh92.dis $ROOT/dis/sh92.dis
-
-%.dis: ${SYSMODULES:%=$MODDIR/%}
+<$ROOT/mkfiles/mksubdirs
diff --git a/module/mkfile b/module/mkfile
new file mode 100644
index 0000000..ebe0018
--- /dev/null
+++ b/module/mkfile
@@ -0,0 +1,9 @@
+<../mkconfig
+
+MODS=\
+ sh9util.m\
+ sh9parser.m\
+
+<mkmod
+
+nuke:QV: \ No newline at end of file
diff --git a/module/mkmod b/module/mkmod
new file mode 100644
index 0000000..16b7252
--- /dev/null
+++ b/module/mkmod
@@ -0,0 +1,16 @@
+MODDIR=$ROOT/module
+
+$MODDIR/%.m: %.m
+ rm -f $MODDIR/$stem.m && cp $stem.m $MODDIR/$stem.m
+
+
+MODFILES=${MODS:%=$MODDIR/%}
+
+all:QV:
+
+clean:QV:
+
+install:V: $MODFILES
+
+nuke:V:
+ rm -f $MODFILES
diff --git a/sh9parser.m b/module/sh9parser.m
index cbad2f6..0807105 100644
--- a/sh9parser.m
+++ b/module/sh9parser.m
@@ -1,15 +1,16 @@
Sh9Parser: module
{
-PATH: con "sh9parser.dis";
+PATH: con "/dis/lib/sh9parser.dis";
DESCR: con "Mostly generic parser for sh9";
-mk_tok: fn(start: int, line: int, tok: string, typ: string) : TokNode;
-set_last_tok: fn(last_tok: ref TokNode, toks: list of ref TokNode): (TokNode, list of ref TokNode);
+mk_tok: fn(start: int, line: int, tok: string, typ: string) : ref TokNode;
+set_last_tok: fn(last_tok: ref TokNode, toks: list of ref TokNode): (ref TokNode, list of ref TokNode);
print_toks: fn(toks: array of ref TokNode);
print_toks_short: fn(toks: array of ref TokNode);
check_grammar_node_match: fn(toks: array of ref TokNode, gn: ref GrammarNode): int;
replace_toks: fn(src: array of ref TokNode, replace_start: int, replace_len: int, replace_with: array of ref TokNode): array of ref TokNode;
parse_toks: fn(toks: array of ref TokNode, g: array of ref GrammarNode): array of ref TokNode;
+init: fn();
TokNode: adt {
start: int;
diff --git a/sh9util.m b/module/sh9util.m
index aa44c3f..bcf940a 100644
--- a/sh9util.m
+++ b/module/sh9util.m
@@ -1,6 +1,6 @@
Sh9Util: module
{
-PATH: con "sh9util.dis";
+PATH: con "/dis/lib/sh9util.dis";
DESCR: con "Utility functions for sh9";
reverse_list: fn[T](toks: list of T): list of T;