summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2017-01-14 12:01:13 -0600
committerBobby Bingham <koorogi@koorogi.info>2017-01-15 23:18:58 -0600
commita743db94541bebafff23c8a490dbce3f55d69712 (patch)
treeb477bdc3fcc69b3f53a553212eac9bff229ab76d
parent737723366b815438da51d9cee0347d6180c8a535 (diff)
nqasm: Improve parsing at end of file
Bison's implicit $accept rule ends with the END token. The fact that input could also end with END (via the line non-terminal) resulted in a shift reduce conflict. We resolve the conflict by modifying the lexer so that if it encounters end of file partway through a line, it produces a final EOL token before EOF.
-rw-r--r--lexer.l5
-rw-r--r--parser.y5
2 files changed, 6 insertions, 4 deletions
diff --git a/lexer.l b/lexer.l
index 9a34d66..6b6b121 100644
--- a/lexer.l
+++ b/lexer.l
@@ -55,7 +55,10 @@ EOI [ \t\n#]
<inst>nop/{EOI} { BEGIN(args); return T_NOP; }
{SP}*{COMMENT}?\n { BEGIN(INITIAL); return T_EOL; }
-{SP}*{COMMENT} { BEGIN(INITIAL); return T_SPACE; }
+{SP}*{COMMENT} { BEGIN(INITIAL); return T_EOL; }
{SP}+ { return T_SPACE; }
+<INITIAL><<EOF>> { return 0; }
+<<EOF>> { BEGIN(INITIAL); return T_EOL; }
+
%%
diff --git a/parser.y b/parser.y
index 78bf123..48bd13f 100644
--- a/parser.y
+++ b/parser.y
@@ -69,7 +69,7 @@ void yyerror(const char *msg)
%type <inst> inst
%%
-input: %empty
+input: line
| input line
;
@@ -151,6 +151,5 @@ inst: T_ADD
;
eol: T_EOL
- | T_SPACE END
- | END
+ | T_SPACE T_EOL
;