summaryrefslogtreecommitdiff
path: root/parser.y
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2017-01-17 20:14:45 -0600
committerBobby Bingham <koorogi@koorogi.info>2017-01-17 23:00:52 -0600
commit9244eacb5ab0b9a11480d1ad40d4720575676877 (patch)
treec49c20b4c693c6676d49f35b6c1217131dd4c0da /parser.y
parentbb7ae08ee638cf9b88a69ca89c5b6b12401c37f5 (diff)
nqasm: parse labels
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y13
1 files changed, 11 insertions, 2 deletions
diff --git a/parser.y b/parser.y
index 76748de..1f4f5bd 100644
--- a/parser.y
+++ b/parser.y
@@ -29,6 +29,7 @@ void yyerror(const char *msg)
struct arguments args;
struct argument arg;
long lval;
+ char *str;
}
%token END 0 "end of file"
@@ -72,12 +73,15 @@ void yyerror(const char *msg)
%token T_ADDPC
%token T_NOP
+%token <str> T_LABEL
%token <lval> T_INT
%token T_BADINT
%token <arg> T_REG
%token <arg> T_REGPTR
+
%token T_COMMA ","
+%token T_COLON ":"
%type <inst> inst
%type <arg> imm
@@ -98,11 +102,16 @@ input: line
| input line
;
-line: T_SPACE inst eol
- { add_instruction(&$2); }
+line:
+ bol inst eol { add_instruction(&$2); }
| eol
;
+bol:
+ T_SPACE
+ | T_LABEL ":" { add_label($1); }
+ ;
+
inst:
T_ADD a_reg3 { $$ = INSTRUCTION_ARGS(ADD, $2); }
| T_SUB a_reg3 { $$ = INSTRUCTION_ARGS(SUB, $2); }