summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-22 13:51:05 -0500
committersanine-a <sanine.not@pm.me>2023-05-22 13:51:05 -0500
commitff3fdee3841743e7fe101c3fc7020a4b043bc91b (patch)
tree76fa1b375d06be81452ef6eff5b18184e8445177 /src
parent003640b43862e66256dd8e21711246d909431d98 (diff)
fix double-newline bug in grammar
Diffstat (limited to 'src')
-rw-r--r--src/parser/grammar.jison70
-rw-r--r--src/parser/grammar.js76
-rw-r--r--src/parser/test.red3
3 files changed, 74 insertions, 75 deletions
diff --git a/src/parser/grammar.jison b/src/parser/grammar.jison
index ae8793b..80edfc5 100644
--- a/src/parser/grammar.jison
+++ b/src/parser/grammar.jison
@@ -4,44 +4,44 @@
%%
-<<EOF>> { return "EOF"; }
-<comment>"\n" { this.popState(); return "NEWLINE"; }
+<<EOF>> { console.log("EOF"); return "EOF"; }
+<comment>"\n" { this.popState(); console.log("NEWLINE"); return "NEWLINE"; }
<comment>. { /* ignore anything else inside a comment */ }
";" { this.pushState('comment'); }
-[\n] { console.log("new!"); return "NEWLINE"; }
+[\n] { console.log("NEWLINE"); return "NEWLINE"; }
\s { /* ignore whitespace */ }
-"MOV" { console.log("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 "*"; }
-"/" { return "/"; }
-[0-9]+ { return "NUMBER"; }
-[A-Z][A-Z0-9_]+ { return "LABEL"; }
+"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"; }
/lex
@@ -52,8 +52,8 @@
%%
program
- : lines NEWLINE END coda { yy.start = 0; return $lines; }
- | lines NEWLINE END label coda { yy.start = yy.getLabel($label); return $lines; }
+ : 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; }
;
coda
diff --git a/src/parser/grammar.js b/src/parser/grammar.js
index 73505c3..7dea851 100644
--- a/src/parser/grammar.js
+++ b/src/parser/grammar.js
@@ -72,22 +72,22 @@
}
*/
var grammar = (function(){
-var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,10],$V1=[1,11],$V2=[1,12],$V3=[1,13],$V4=[1,14],$V5=[1,15],$V6=[1,16],$V7=[1,17],$V8=[1,18],$V9=[1,19],$Va=[1,20],$Vb=[1,9],$Vc=[5,20,21,22,23,24,25,26,27,28,29,30,43],$Vd=[2,10],$Ve=[1,29],$Vf=[1,30],$Vg=[1,31],$Vh=[1,32],$Vi=[1,34],$Vj=[1,33],$Vk=[1,35],$Vl=[32,33,34,35,37,40,42,43],$Vm=[5,19],$Vn=[1,42],$Vo=[1,43],$Vp=[1,44],$Vq=[1,45],$Vr=[37,40,42,43],$Vs=[5,19,36,37,38,39,41],$Vt=[1,52],$Vu=[1,51],$Vv=[5,10],$Vw=[5,19,36,37,41];
+var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,5],$V1=[1,10],$V2=[1,11],$V3=[1,12],$V4=[1,13],$V5=[1,14],$V6=[1,15],$V7=[1,16],$V8=[1,17],$V9=[1,18],$Va=[1,19],$Vb=[1,20],$Vc=[1,9],$Vd=[5,10,20,21,22,23,24,25,26,27,28,29,30,43],$Ve=[1,29],$Vf=[1,30],$Vg=[1,31],$Vh=[1,32],$Vi=[1,34],$Vj=[1,33],$Vk=[1,35],$Vl=[32,33,34,35,37,40,42,43],$Vm=[1,40],$Vn=[1,41],$Vo=[10,19],$Vp=[1,46],$Vq=[1,47],$Vr=[1,48],$Vs=[1,49],$Vt=[37,40,42,43],$Vu=[10,19,36,37,38,39,41],$Vv=[9,10],$Vw=[10,19,36,37,41];
var parser = {trace: function trace () { },
yy: {},
-symbols_: {"error":2,"program":3,"lines":4,"NEWLINE":5,"END":6,"coda":7,"label":8,"newlines":9,"EOF":10,"line":11,"row":12,"op":13,":":14,"EQU":15,"e":16,"opcode":17,"address":18,",":19,"MOV":20,"ADD":21,"SUB":22,"CMP":23,"SLT":24,"JMP":25,"JMZ":26,"JMN":27,"DJN":28,"SPL":29,"DAT":30,"address_mode":31,"#":32,"@":33,"<":34,"$":35,"+":36,"-":37,"*":38,"/":39,"(":40,")":41,"NUMBER":42,"LABEL":43,"$accept":0,"$end":1},
-terminals_: {2:"error",5:"NEWLINE",6:"END",10:"EOF",14:":",15:"EQU",19:",",20:"MOV",21:"ADD",22:"SUB",23:"CMP",24:"SLT",25:"JMP",26:"JMZ",27:"JMN",28:"DJN",29:"SPL",30:"DAT",32:"#",33:"@",34:"<",35:"$",36:"+",37:"-",38:"*",39:"/",40:"(",41:")",42:"NUMBER",43:"LABEL"},
-productions_: [0,[3,4],[3,5],[7,2],[7,1],[9,2],[9,1],[4,2],[4,1],[11,2],[11,1],[12,1],[12,3],[12,3],[13,4],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[18,2],[18,1],[31,1],[31,1],[31,1],[31,1],[16,3],[16,3],[16,3],[16,3],[16,3],[16,2],[16,1],[16,1],[8,1]],
+symbols_: {"error":2,"program":3,"lines":4,"END":5,"coda":6,"label":7,"newlines":8,"EOF":9,"NEWLINE":10,"line":11,"row":12,"op":13,":":14,"EQU":15,"e":16,"opcode":17,"address":18,",":19,"MOV":20,"ADD":21,"SUB":22,"CMP":23,"SLT":24,"JMP":25,"JMZ":26,"JMN":27,"DJN":28,"SPL":29,"DAT":30,"address_mode":31,"#":32,"@":33,"<":34,"$":35,"+":36,"-":37,"*":38,"/":39,"(":40,")":41,"NUMBER":42,"LABEL":43,"$accept":0,"$end":1},
+terminals_: {2:"error",5:"END",9:"EOF",10:"NEWLINE",14:":",15:"EQU",19:",",20:"MOV",21:"ADD",22:"SUB",23:"CMP",24:"SLT",25:"JMP",26:"JMZ",27:"JMN",28:"DJN",29:"SPL",30:"DAT",32:"#",33:"@",34:"<",35:"$",36:"+",37:"-",38:"*",39:"/",40:"(",41:")",42:"NUMBER",43:"LABEL"},
+productions_: [0,[3,3],[3,4],[6,2],[6,1],[8,2],[8,1],[4,2],[4,1],[11,2],[11,1],[12,1],[12,3],[12,3],[13,4],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[17,1],[18,2],[18,1],[31,1],[31,1],[31,1],[31,1],[16,3],[16,3],[16,3],[16,3],[16,3],[16,2],[16,1],[16,1],[7,1]],
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
/* this == yyval */
var $0 = $$.length - 1;
switch (yystate) {
case 1:
- yy.start = 0; return $$[$0-3];
+ yy.start = 0; console.log($$[$0-2]); return $$[$0-2];
break;
case 2:
- yy.start = yy.getLabel($$[$0-1]); return $$[$0-4];
+ yy.start = yy.getLabel($$[$0-1]); console.log($$[$0-3]); return $$[$0-3];
break;
case 7:
@@ -186,8 +186,8 @@ case 40:
break;
}
},
-table: [{3:1,4:2,5:[1,5],8:7,11:3,12:4,13:6,17:8,20:$V0,21:$V1,22:$V2,23:$V3,24:$V4,25:$V5,26:$V6,27:$V7,28:$V8,29:$V9,30:$Va,43:$Vb},{1:[3]},{5:[1,21],8:7,11:22,12:4,13:6,17:8,20:$V0,21:$V1,22:$V2,23:$V3,24:$V4,25:$V5,26:$V6,27:$V7,28:$V8,29:$V9,30:$Va,43:$Vb},o($Vc,[2,8]),{5:[1,23]},o($Vc,$Vd),{5:[2,11]},{14:[1,24],15:[1,25]},{8:36,16:28,18:26,31:27,32:$Ve,33:$Vf,34:$Vg,35:$Vh,37:$Vi,40:$Vj,42:$Vk,43:$Vb},o([5,10,14,15,19,36,37,38,39,41],[2,40]),o($Vl,[2,15]),o($Vl,[2,16]),o($Vl,[2,17]),o($Vl,[2,18]),o($Vl,[2,19]),o($Vl,[2,20]),o($Vl,[2,21]),o($Vl,[2,22]),o($Vl,[2,23]),o($Vl,[2,24]),o($Vl,[2,25]),o($Vc,$Vd,{6:[1,37]}),o($Vc,[2,7]),o($Vc,[2,9]),{13:38,17:8,20:$V0,21:$V1,22:$V2,23:$V3,24:$V4,25:$V5,26:$V6,27:$V7,28:$V8,29:$V9,30:$Va},{8:36,16:39,37:$Vi,40:$Vj,42:$Vk,43:$Vb},{19:[1,40]},{8:36,16:41,37:$Vi,40:$Vj,42:$Vk,43:$Vb},o($Vm,[2,27],{36:$Vn,37:$Vo,38:$Vp,39:$Vq}),o($Vr,[2,28]),o($Vr,[2,29]),o($Vr,[2,30]),o($Vr,[2,31]),{8:36,16:46,37:$Vi,40:$Vj,42:$Vk,43:$Vb},{8:36,16:47,37:$Vi,40:$Vj,42:$Vk,43:$Vb},o($Vs,[2,38]),o($Vs,[2,39]),{5:$Vt,7:48,8:49,9:50,10:$Vu,43:$Vb},{5:[2,12]},{5:[2,13],36:$Vn,37:$Vo,38:$Vp,39:$Vq},{8:36,16:28,18:53,31:27,32:$Ve,33:$Vf,34:$Vg,35:$Vh,37:$Vi,40:$Vj,42:$Vk,43:$Vb},o($Vm,[2,26],{36:$Vn,37:$Vo,38:$Vp,39:$Vq}),{8:36,16:54,37:$Vi,40:$Vj,42:$Vk,43:$Vb},{8:36,16:55,37:$Vi,40:$Vj,42:$Vk,43:$Vb},{8:36,16:56,37:$Vi,40:$Vj,42:$Vk,43:$Vb},{8:36,16:57,37:$Vi,40:$Vj,42:$Vk,43:$Vb},{36:$Vn,37:$Vo,38:$Vp,39:$Vq,41:[1,58]},o($Vs,[2,37]),{1:[2,1]},{5:$Vt,7:59,9:50,10:$Vu},{5:[1,61],10:[1,60]},{1:[2,4]},o($Vv,[2,6]),{5:[2,14]},o($Vw,[2,32],{38:$Vp,39:$Vq}),o($Vw,[2,33],{38:$Vp,39:$Vq}),o($Vs,[2,34]),o($Vs,[2,35]),o($Vs,[2,36]),{1:[2,2]},{1:[2,3]},o($Vv,[2,5])],
-defaultActions: {6:[2,11],38:[2,12],48:[2,1],51:[2,4],53:[2,14],59:[2,2],60:[2,3]},
+table: [{3:1,4:2,7:7,10:$V0,11:3,12:4,13:6,17:8,20:$V1,21:$V2,22:$V3,23:$V4,24:$V5,25:$V6,26:$V7,27:$V8,28:$V9,29:$Va,30:$Vb,43:$Vc},{1:[3]},{5:[1,21],7:7,10:$V0,11:22,12:4,13:6,17:8,20:$V1,21:$V2,22:$V3,23:$V4,24:$V5,25:$V6,26:$V7,27:$V8,28:$V9,29:$Va,30:$Vb,43:$Vc},o($Vd,[2,8]),{10:[1,23]},o($Vd,[2,10]),{10:[2,11]},{14:[1,24],15:[1,25]},{7:36,16:28,18:26,31:27,32:$Ve,33:$Vf,34:$Vg,35:$Vh,37:$Vi,40:$Vj,42:$Vk,43:$Vc},o([9,10,14,15,19,36,37,38,39,41],[2,40]),o($Vl,[2,15]),o($Vl,[2,16]),o($Vl,[2,17]),o($Vl,[2,18]),o($Vl,[2,19]),o($Vl,[2,20]),o($Vl,[2,21]),o($Vl,[2,22]),o($Vl,[2,23]),o($Vl,[2,24]),o($Vl,[2,25]),{6:37,7:38,8:39,9:$Vm,10:$Vn,43:$Vc},o($Vd,[2,7]),o($Vd,[2,9]),{13:42,17:8,20:$V1,21:$V2,22:$V3,23:$V4,24:$V5,25:$V6,26:$V7,27:$V8,28:$V9,29:$Va,30:$Vb},{7:36,16:43,37:$Vi,40:$Vj,42:$Vk,43:$Vc},{19:[1,44]},{7:36,16:45,37:$Vi,40:$Vj,42:$Vk,43:$Vc},o($Vo,[2,27],{36:$Vp,37:$Vq,38:$Vr,39:$Vs}),o($Vt,[2,28]),o($Vt,[2,29]),o($Vt,[2,30]),o($Vt,[2,31]),{7:36,16:50,37:$Vi,40:$Vj,42:$Vk,43:$Vc},{7:36,16:51,37:$Vi,40:$Vj,42:$Vk,43:$Vc},o($Vu,[2,38]),o($Vu,[2,39]),{1:[2,1]},{6:52,8:39,9:$Vm,10:$Vn},{9:[1,53],10:[1,54]},{1:[2,4]},o($Vv,[2,6]),{10:[2,12]},{10:[2,13],36:$Vp,37:$Vq,38:$Vr,39:$Vs},{7:36,16:28,18:55,31:27,32:$Ve,33:$Vf,34:$Vg,35:$Vh,37:$Vi,40:$Vj,42:$Vk,43:$Vc},o($Vo,[2,26],{36:$Vp,37:$Vq,38:$Vr,39:$Vs}),{7:36,16:56,37:$Vi,40:$Vj,42:$Vk,43:$Vc},{7:36,16:57,37:$Vi,40:$Vj,42:$Vk,43:$Vc},{7:36,16:58,37:$Vi,40:$Vj,42:$Vk,43:$Vc},{7:36,16:59,37:$Vi,40:$Vj,42:$Vk,43:$Vc},{36:$Vp,37:$Vq,38:$Vr,39:$Vs,41:[1,60]},o($Vu,[2,37]),{1:[2,2]},{1:[2,3]},o($Vv,[2,5]),{10:[2,14]},o($Vw,[2,32],{38:$Vr,39:$Vs}),o($Vw,[2,33],{38:$Vr,39:$Vs}),o($Vu,[2,34]),o($Vu,[2,35]),o($Vu,[2,36])],
+defaultActions: {6:[2,11],37:[2,1],40:[2,4],42:[2,12],52:[2,2],53:[2,3],55:[2,14]},
parseError: function parseError (str, hash) {
if (hash.recoverable) {
this.trace(str);
@@ -662,71 +662,71 @@ options: {},
performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
var YYSTATE=YY_START;
switch($avoiding_name_collisions) {
-case 0: return "EOF";
+case 0: console.log("EOF"); return "EOF";
break;
-case 1: this.popState(); return "NEWLINE";
+case 1: this.popState(); console.log("NEWLINE"); return "NEWLINE";
break;
case 2: /* ignore anything else inside a comment */
break;
case 3: this.pushState('comment');
break;
-case 4: console.log("new!"); return "NEWLINE";
+case 4: console.log("NEWLINE"); return "NEWLINE";
break;
case 5: /* ignore whitespace */
break;
-case 6: console.log("mov"); return "MOV";
+case 6: console.log("MOV"); return "MOV";
break;
-case 7: return "ADD";
+case 7: console.log("ADD"); return "ADD";
break;
-case 8: return "SUB";
+case 8: console.log("SUB"); return "SUB";
break;
-case 9: return "CMP";
+case 9: console.log("CMP"); return "CMP";
break;
-case 10: return "SLT";
+case 10: console.log("SLT"); return "SLT";
break;
-case 11: return "JMP";
+case 11: console.log("JMP"); return "JMP";
break;
-case 12: return "JMZ";
+case 12: console.log("JMZ"); return "JMZ";
break;
-case 13: return "JMN";
+case 13: console.log("JMN"); return "JMN";
break;
-case 14: return "DJN";
+case 14: console.log("DJN"); return "DJN";
break;
-case 15: return "SPL";
+case 15: console.log("SPL"); return "SPL";
break;
-case 16: return "DAT";
+case 16: console.log("DAT"); return "DAT";
break;
-case 17: return "EQU";
+case 17: console.log("EQU"); return "EQU";
break;
-case 18: return "END";
+case 18: console.log("END"); return "END";
break;
-case 19: return ":";
+case 19: console.log(":"); return ":";
break;
-case 20: return ",";
+case 20: console.log(","); return ",";
break;
-case 21: return "#";
+case 21: console.log("#"); return "#";
break;
-case 22: return "@";
+case 22: console.log("@"); return "@";
break;
-case 23: return "<";
+case 23: console.log("<"); return "<";
break;
-case 24: return "$";
+case 24: console.log("$"); return "$";
break;
-case 25: return "(";
+case 25: console.log("("); return "(";
break;
-case 26: return ")";
+case 26: console.log(")"); return ")";
break;
-case 27: return "+";
+case 27: console.log("+"); return "+";
break;
-case 28: return "-";
+case 28: console.log("-"); return "-";
break;
-case 29: return "*";
+case 29: console.log("*"); return "*";
break;
-case 30: return "/";
+case 30: console.log("/"); return "/";
break;
-case 31: return "NUMBER";
+case 31: console.log("NUMBER"); return "NUMBER";
break;
-case 32: return "LABEL";
+case 32: console.log("LABEL"); return "LABEL";
break;
}
},
diff --git a/src/parser/test.red b/src/parser/test.red
index 54e3453..bf41132 100644
--- a/src/parser/test.red
+++ b/src/parser/test.red
@@ -1,3 +1,2 @@
-MOV 0, 0
-
+MOV 0, -10
END