diff options
author | sanine-a <sanine.not@pm.me> | 2023-05-22 13:51:05 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-05-22 13:51:05 -0500 |
commit | ff3fdee3841743e7fe101c3fc7020a4b043bc91b (patch) | |
tree | 76fa1b375d06be81452ef6eff5b18184e8445177 /src/parser/grammar.jison | |
parent | 003640b43862e66256dd8e21711246d909431d98 (diff) |
fix double-newline bug in grammar
Diffstat (limited to 'src/parser/grammar.jison')
-rw-r--r-- | src/parser/grammar.jison | 70 |
1 files changed, 35 insertions, 35 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 |