1919from .asmlex import tokens # noqa
2020from .asm import AsmInstruction , Error
2121from ast_ import Ast
22+ from ast_ .tree import NotAnAstError
2223from api .debug import __DEBUG__
2324from api .config import OPTIONS
2425from 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
303319class Label (object ):
304320 """ A class to store Label information (NAME, linenumber and Address)
@@ -735,8 +751,8 @@ def p_idlist_id(p):
735751
736752
737753def 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+
763798def 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
15551589from .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