Skip to content

Commit

Permalink
Allow label names to begin with a valid register name (e.g., R1_INIT)
Browse files Browse the repository at this point in the history
Resolves #3
  • Loading branch information
iafisher committed Dec 13, 2018
1 parent 8dfe24c commit df16826
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hera/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def value(self, matches):
ntkn.end_line = otkn.end_line
ntkn.end_column = otkn.end_column
return ntkn
elif matches[0].type == "SYMBOL":
if matches[0][0] in "rR" and matches[0][1:].isdigit():
matches[0].type = "REGISTER"
return matches[0]
else:
return matches[0]

Expand All @@ -65,10 +69,9 @@ def value(self, matches):
_arglist: ( value "," )* value
value: DECIMAL | HEX | OCTAL | BINARY | REGISTER | SYMBOL | STRING
value: DECIMAL | HEX | OCTAL | BINARY | SYMBOL | STRING
REGISTER.3: /[rR][0-9]+/
SYMBOL.2: /[A-Za-z_][A-Za-z0-9_]*/
SYMBOL: /[A-Za-z_][A-Za-z0-9_]*/
DECIMAL: /-?[0-9]+/
HEX: /-?0x[0-9a-fA-F]+/
// TODO: How should I handle zero-prefixed numbers, which the HERA-C
Expand Down
4 changes: 4 additions & 0 deletions test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def test_parse_negative_octal_number():
assert parse("SETLO(R3, -0o173)") == [Op("SETLO", ["R3", -123])]


def test_parse_label_starting_with_register_name():
assert parse("LABEL(R1_INIT)") == [Op("LABEL", ["R1_INIT"])]


def test_parse_single_line_comment():
assert parse("SETLO(R1, 0) // R1 <- 0") == [Op("SETLO", ["R1", 0])]

Expand Down

0 comments on commit df16826

Please sign in to comment.