From ff3fdee3841743e7fe101c3fc7020a4b043bc91b Mon Sep 17 00:00:00 2001 From: sanine-a Date: Mon, 22 May 2023 13:51:05 -0500 Subject: fix double-newline bug in grammar --- src/parser/grammar.jison | 70 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/parser/grammar.jison') 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 @@ %% -<> { return "EOF"; } -"\n" { this.popState(); return "NEWLINE"; } +<> { console.log("EOF"); return "EOF"; } +"\n" { this.popState(); console.log("NEWLINE"); return "NEWLINE"; } . { /* 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 -- cgit v1.2.1