Skip to content

Commit 3581b0a

Browse files
committed
Implement DB allowing Strings and Chars
Now it's possible to assemble: DB "Hello", ' ', "Worl", 'd' + 128
1 parent f982b61 commit 3581b0a

6 files changed

Lines changed: 53 additions & 16 deletions

File tree

parsetab/tabs.dbm.bak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'zxbppparse', (0, 69164)
2-
'asmparse', (69632, 250673)
3-
'zxnext_asmparse', (320512, 281631)
4-
'zxbparser', (602624, 708747)
1+
'zxbppparse', (0, 69165)
2+
'asmparse', (69632, 253669)
3+
'zxnext_asmparse', (323584, 284580)
4+
'zxbparser', (608256, 708747)

parsetab/tabs.dbm.dat

5.5 KB
Binary file not shown.

parsetab/tabs.dbm.dir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'zxbppparse', (0, 69164)
2-
'asmparse', (69632, 250673)
3-
'zxnext_asmparse', (320512, 281631)
4-
'zxbparser', (602624, 708747)
1+
'zxbppparse', (0, 69165)
2+
'asmparse', (69632, 253669)
3+
'zxnext_asmparse', (323584, 284580)
4+
'zxbparser', (608256, 708747)

tests/functional/db_multi.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
DB "Hello", 32, "Worl", 'D' + 32
3+

tests/functional/db_multi.bin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World

zxbasm/asmparse.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .asmlex import tokens # noqa
2020
from .asm import AsmInstruction, Error
2121
from ast_ import Ast
22+
from ast_.tree import NotAnAstError
2223
from api.debug import __DEBUG__
2324
from api.config import OPTIONS
2425
from api.errmsg import syntax_error as error
@@ -133,7 +134,7 @@ def bytes(self):
133134
if self.pending:
134135
return tuple([0] * self.arg_num)
135136

136-
return tuple([x & 0xFF for x in self.argval()])
137+
return tuple(x & 0xFF for x in self.argval())
137138

138139
if self.asm == 'DEFS':
139140
if self.pending:
@@ -299,6 +300,21 @@ def try_eval(self):
299300

300301
return None
301302

303+
@classmethod
304+
def makenode(cls, symbol, *nexts):
305+
""" Stores the symbol in an AST instance,
306+
and left and right to the given ones
307+
"""
308+
result = cls(symbol)
309+
for i in nexts:
310+
if i is None:
311+
continue
312+
if not isinstance(i, cls):
313+
raise NotAnAstError(i)
314+
result.appendChild(i)
315+
316+
return result
317+
302318

303319
class Label(object):
304320
""" A class to store Label information (NAME, linenumber and Address)
@@ -735,8 +751,8 @@ def p_idlist_id(p):
735751

736752

737753
def p_DEFB(p): # Define bytes
738-
""" asm : DEFB number_list
739-
| DEFB STRING
754+
""" asm : DEFB expr_list
755+
| DEFB number_list
740756
"""
741757
p[0] = Asm(p.lineno(1), 'DEFB', p[2])
742758

@@ -760,6 +776,25 @@ def p_DEFW(p): # Define words
760776
p[0] = Asm(p.lineno(1), 'DEFW', p[2])
761777

762778

779+
def p_expr_list_from_string(p):
780+
""" expr_list : STRING
781+
"""
782+
p[0] = tuple(Expr.makenode(Container(ord(x), p.lineno(1))) for x in p[1])
783+
784+
785+
def p_expr_list_plus_expr(p):
786+
""" expr_list : expr_list COMMA expr
787+
| expr_list COMMA pexpr
788+
"""
789+
p[0] = p[1] + (p[3],)
790+
791+
792+
def p_expr_list_plus_string(p):
793+
""" expr_list : expr_list COMMA STRING
794+
"""
795+
p[0] = p[1] + tuple(Expr.makenode(Container(ord(x), p.lineno(3))) for x in p[3])
796+
797+
763798
def p_number_list(p):
764799
""" number_list : expr
765800
| pexpr
@@ -1548,12 +1583,10 @@ def main(argv):
15481583

15491584

15501585
# Z80 only ASM parser
1551-
parser = api.utils.get_or_create('asmparse',
1552-
lambda: yacc.yacc(start="start", debug=OPTIONS.Debug.value > 2))
1586+
parser = api.utils.get_or_create('asmparse', lambda: yacc.yacc(start="start", debug=True))
15531587

15541588
# needed for ply
15551589
from .zxnext import * # noqa
15561590

1557-
# ZXNEXT extended OPcodes parser
1558-
zxnext_parser = api.utils.get_or_create('zxnext_asmparse',
1559-
lambda: yacc.yacc(start="start", debug=OPTIONS.Debug.value > 2))
1591+
# ZXNEXT extended Opcodes parser
1592+
zxnext_parser = api.utils.get_or_create('zxnext_asmparse', lambda: yacc.yacc(start="start", debug=True))

0 commit comments

Comments
 (0)