summaryrefslogtreecommitdiff
path: root/src/parser/grammar.jison
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-22 14:26:10 -0500
committersanine-a <sanine.not@pm.me>2023-05-22 14:26:10 -0500
commitf2a515a940ea5e66c9fbc9669e6293ae32b7041a (patch)
tree478d369195e90380027fef4137b9caac833bb219 /src/parser/grammar.jison
parentff3fdee3841743e7fe101c3fc7020a4b043bc91b (diff)
update label style and add implicit second operand
Diffstat (limited to 'src/parser/grammar.jison')
-rw-r--r--src/parser/grammar.jison87
1 files changed, 47 insertions, 40 deletions
diff --git a/src/parser/grammar.jison b/src/parser/grammar.jison
index 80edfc5..2f5b30a 100644
--- a/src/parser/grammar.jison
+++ b/src/parser/grammar.jison
@@ -4,44 +4,43 @@
%%
-<<EOF>> { console.log("EOF"); return "EOF"; }
-<comment>"\n" { this.popState(); console.log("NEWLINE"); return "NEWLINE"; }
+<<EOF>> { return "EOF"; }
+<comment>"\n" { this.popState(); return "NEWLINE"; }
<comment>. { /* ignore anything else inside a comment */ }
";" { this.pushState('comment'); }
-[\n] { console.log("NEWLINE"); return "NEWLINE"; }
+[\n] { return "NEWLINE"; }
\s { /* ignore whitespace */ }
-"MOV" { console.log("MOV"); return "MOV"; }
-"ADD" { console.log("ADD"); return "ADD"; }
-"SUB" { console.log("SUB"); return "SUB"; }
-"CMP" { console.log("CMP"); return "CMP"; }
-"SLT" { console.log("SLT"); return "SLT"; }
-"JMP" { console.log("JMP"); return "JMP"; }
-"JMZ" { console.log("JMZ"); return "JMZ"; }
-"JMN" { console.log("JMN"); return "JMN"; }
-"DJN" { console.log("DJN"); return "DJN"; }
-"SPL" { console.log("SPL"); return "SPL"; }
-"DAT" { console.log("DAT"); return "DAT"; }
-
-"EQU" { console.log("EQU"); return "EQU"; }
-"END" { console.log("END"); return "END"; }
-":" { console.log(":"); return ":"; }
-"," { console.log(","); return ","; }
-
-"#" { console.log("#"); return "#"; }
-"@" { console.log("@"); return "@"; }
-"<" { console.log("<"); return "<"; }
-"$" { console.log("$"); return "$"; }
-
-"(" { console.log("("); return "("; }
-")" { console.log(")"); return ")"; }
-"+" { console.log("+"); return "+"; }
-"-" { console.log("-"); return "-"; }
-"*" { console.log("*"); return "*"; }
-"/" { console.log("/"); return "/"; }
-[0-9]+ { console.log("NUMBER"); return "NUMBER"; }
-[A-Z][A-Z0-9_]+ { console.log("LABEL"); return "LABEL"; }
+"MOV" { return "MOV"; }
+"ADD" { return "ADD"; }
+"SUB" { return "SUB"; }
+"CMP" { return "CMP"; }
+"SLT" { return "SLT"; }
+"JMP" { return "JMP"; }
+"JMZ" { return "JMZ"; }
+"JMN" { return "JMN"; }
+"DJN" { return "DJN"; }
+"SPL" { return "SPL"; }
+"DAT" { return "DAT"; }
+
+"EQU" { return "EQU"; }
+"END" { return "END"; }
+"," { return ","; }
+
+"#" { return "#"; }
+"@" { return "@"; }
+"<" { return "<"; }
+"$" { return "$"; }
+
+"(" { return "("; }
+")" { return ")"; }
+"+" { return "+"; }
+"-" { return "-"; }
+"*" { return "*"; }
+"/" { return "/"; }
+[0-9]+ { return "NUMBER"; }
+[A-Z][A-Z0-9_]+ { return "LABEL"; }
/lex
@@ -52,8 +51,8 @@
%%
program
- : lines END coda { yy.start = 0; console.log($lines); return $lines; }
- | lines END label coda { yy.start = yy.getLabel($label); console.log($lines); return $lines; }
+ : lines END coda { yy.start = 0; return $lines; }
+ | lines END label coda { yy.start = yy.getLabel($label); return $lines; }
;
coda
@@ -93,18 +92,18 @@ line
row
: op
{
- yy.pc += 1;
+ yy.step();
$$ = $op;
}
- | label ":" op
+ | label op
{
- yy.setLabel($label, yy.pc);
- yy.pc += 1;
+ yy.setLine($label);
+ yy.step();
$$ = $op;
}
| label EQU e
{
- yy.setLabel($label, $e);
+ yy.setEqu($label, $e);
$$ = null;
}
;
@@ -113,6 +112,14 @@ row
op
: opcode address "," address
{ $$ = { opcode: $opcode, a: $address1, b: $address2 }; }
+ | opcode address
+ {
+ $$ = {
+ opcode: $opcode,
+ a: $address,
+ b: { mode: 'direct', value: 0 },
+ };
+ }
;