9 date 2007.11.11.22.35.51; author khansen; state Exp;
14 date 2007.08.19.11.19.47; author khansen; state Exp;
19 date 2007.08.12.18.59.00; author khansen; state Exp;
24 date 2007.08.11.01.25.50; author khansen; state Exp;
29 date 2007.07.22.13.34.38; author khansen; state Exp;
34 date 2005.01.05.02.28.40; author kenth; state Exp;
39 date 2004.12.29.21.45.26; author kenth; state Exp;
44 date 2004.12.19.19.59.14; author kenth; state Exp;
49 date 2004.12.16.13.22.27; author kenth; state Exp;
54 date 2004.12.14.01.50.42; author kenth; state Exp;
59 date 2004.12.11.02.12.41; author kenth; state Exp;
64 date 2004.12.09.11.17.15; author kenth; state Exp;
69 date 2004.12.06.05.06.21; author kenth; state Exp;
74 date 2004.06.30.07.57.03; author kenth; state Exp;
90 * $Id: parser.y,v 1.13 2007/08/19 11:19:47 khansen Exp khansen $
92 * Revision 1.13 2007/08/19 11:19:47 khansen
93 * --case-insensitive option
95 * Revision 1.12 2007/08/12 18:59:00 khansen
96 * ability to generate pure 6502 binary
98 * Revision 1.11 2007/08/11 01:25:50 khansen
99 * includepaths support (-I option)
101 * Revision 1.10 2007/07/22 13:34:38 khansen
102 * convert tabs to whitespaces
104 * Revision 1.9 2005/01/05 02:28:40 kenth
105 * anonymous union parsing
107 * Revision 1.8 2004/12/29 21:45:26 kenth
111 * Revision 1.7 2004/12/19 19:59:14 kenth
114 * Revision 1.6 2004/12/16 13:22:27 kenth
117 * Revision 1.5 2004/12/14 01:50:42 kenth
120 * Revision 1.4 2004/12/11 02:12:41 kenth
123 * Revision 1.3 2004/12/09 11:17:15 kenth
124 * added: warning_statement, error_statement
126 * Revision 1.2 2004/12/06 05:06:21 kenth
129 * Revision 1.1 2004/06/30 07:57:03 kenth
141 void yyerror(const char *); /* In lexer */
142 int yylex(void); /* In lexer */
143 int yypushandrestart(const char *); /* In lexer */
144 void __yy_memcpy(char *, char *, int);
145 extern char *yytext; /* In lexer */
146 extern YYLTYPE yylloc; /* In lexer */
147 extern astnode *root_node; /* Root of the generated parse tree */
148 void handle_incsrc(astnode *); /* See below */
149 void handle_incbin(astnode *); /* See below */
163 %token <integer> INTEGER_LITERAL
164 %token <string> STRING_LITERAL
165 %token <string> FILE_PATH
166 %token <ident> IDENTIFIER
167 %token <ident> LOCAL_ID
168 %token <ident> FORWARD_BRANCH
169 %token <ident> BACKWARD_BRANCH
171 %token <label> LOCAL_LABEL
172 %token <mnemonic> MNEMONIC
174 %type <node> identifier identifier_opt local_id assembly_unit statement labelable_statement statement_list if_statement elif_statement elif_statement_list elif_statement_list_opt ifdef_statement ifndef_statement macro_decl_statement macro_statement instruction_statement data_statement storage_statement null_statement incsrc_statement incbin_statement equ_statement assign_statement public_statement extrn_statement dataseg_statement codeseg_statement charmap_statement struc_decl_statement union_decl_statement enum_decl_statement record_decl_statement instruction expression extended_expression expression_opt arithmetic_expression comparison_expression literal label label_decl identifier_list expression_list file_specifier param_list_opt arg_list_opt else_part_opt scope_access struc_access struc_initializer field_initializer_list field_initializer_list_opt field_initializer datatype storage named_data_statement unnamed_data_statement named_storage_statement unnamed_storage_statement proc_statement rept_statement label_statement message_statement warning_statement error_statement while_statement define_statement align_statement org_statement symbol_type enum_item_list enum_item record_field_list record_field sizeof_arg label_addr_part_opt label_type_part_opt from_part_opt indexed_identifier
176 %token _LABEL_ BYTE CHAR WORD DWORD DSB DSW DSD DATASEG CODESEG IF IFDEF IFNDEF ELSE ELIF ENDIF INCSRC INCBIN MACRO REPT WHILE ENDM ALIGN EQU DEFINE END PUBLIC EXTRN CHARMAP STRUC UNION ENDS RECORD ENUM ENDE PROC ENDP SIZEOF MASK TAG MESSAGE WARNING ERROR ZEROPAGE ORG
195 %left LE_OP GE_OP '>' '<'
206 statement_list end_opt { root_node = astnode_create_list($1); }
215 labelable_statement { $$ = $1; }
216 | statement_list labelable_statement {
217 if ($1 != NULL) { $$ = $1; astnode_add_sibling($$, $2); }
223 label_decl statement { $$ = $1; astnode_add_sibling($$, $2); }
224 | statement { $$ = $1; }
228 if_statement { $$ = $1; }
229 | ifdef_statement { $$ = $1; }
230 | ifndef_statement { $$ = $1; }
231 | macro_decl_statement { $$ = $1; }
232 | macro_statement { $$ = $1; }
233 | incsrc_statement { $$ = $1; }
234 | incbin_statement { $$ = $1; }
235 | equ_statement { $$ = $1; }
236 | assign_statement { $$ = $1; }
237 | public_statement { $$ = $1; }
238 | extrn_statement { $$ = $1; }
239 | instruction_statement { $$ = $1; }
240 | data_statement { $$ = $1; }
241 | storage_statement { $$ = $1; }
242 | dataseg_statement { $$ = $1; }
243 | codeseg_statement { $$ = $1; }
244 | charmap_statement { $$ = $1; }
245 | struc_decl_statement { $$ = $1; }
246 | union_decl_statement { $$ = $1; }
247 | enum_decl_statement { $$ = $1; }
248 | record_decl_statement { $$ = $1; }
249 | proc_statement { $$ = $1; }
250 | rept_statement { $$ = $1; }
251 | while_statement { $$ = $1; }
252 | label_statement { $$ = $1; }
253 | message_statement { $$ = $1; }
254 | warning_statement { $$ = $1; }
255 | error_statement { $$ = $1; }
256 | define_statement { $$ = $1; }
257 | align_statement { $$ = $1; }
258 | org_statement { $$ = $1; }
259 | null_statement { $$ = $1; }
260 | error line_tail { $$ = NULL; }
264 ORG expression line_tail { $$ = astnode_create_org($2, @@$); }
268 ALIGN identifier_list expression line_tail { $$ = astnode_create_align($2, $3, @@$); }
272 WARNING expression line_tail { $$ = astnode_create_warning($2, @@$); }
276 ERROR expression line_tail { $$ = astnode_create_error($2, @@$); }
280 MESSAGE expression line_tail { $$ = astnode_create_message($2, @@$); }
284 _LABEL_ identifier label_addr_part_opt label_type_part_opt line_tail { $$ = astnode_create_label($2->label, $3, $4, @@$); }
288 '=' expression { $$ = $2; }
293 ':' symbol_type { $$ = $2; }
298 WHILE expression line_tail statement_list ENDM line_tail { $$ = astnode_create_while($2, $4, @@$); }
302 REPT expression line_tail statement_list ENDM line_tail { $$ = astnode_create_rept($2, $4, @@$); }
306 PROC identifier line_tail statement_list ENDP line_tail { $$ = astnode_create_proc($2, $4, @@$); }
309 struc_decl_statement:
310 STRUC identifier line_tail statement_list ENDS line_tail { $$ = astnode_create_struc_decl($2, $4, @@$); }
313 union_decl_statement:
314 UNION identifier_opt line_tail statement_list ENDS line_tail { $$ = astnode_create_union_decl($2, $4, @@$); }
318 ENUM identifier line_tail enum_item_list ENDE line_tail { $$ = astnode_create_enum_decl($2, $4, @@$); }
322 enum_item { $$ = $1; }
323 | enum_item_list enum_item { $$ = $1; astnode_add_sibling($$, $2); }
327 assign_statement { $$ = $1; }
328 | identifier line_tail { $$ = $1; }
331 record_decl_statement:
332 RECORD identifier record_field_list line_tail { $$ = astnode_create_record_decl($2, $3, @@$); }
336 record_field { $$ = $1; }
337 | record_field_list ',' record_field { $$ = $1; astnode_add_sibling($$, $3); }
341 identifier ':' expression { $$ = astnode_create_bitfield_decl($1, $3, @@$); }
345 CHARMAP file_specifier line_tail { $$ = astnode_create_charmap($2, @@$); }
349 DATASEG line_tail { $$ = astnode_create_dataseg(0, @@$); }
350 | DATASEG ZEROPAGE line_tail { $$ = astnode_create_dataseg(ZEROPAGE_FLAG, @@$); }
353 CODESEG line_tail { $$ = astnode_create_codeseg(@@$); }
357 line_tail { $$ = NULL; }
373 instruction_statement:
374 instruction line_tail { $$ = $1; }
378 MNEMONIC { $$ = astnode_create_instruction($1, IMPLIED_MODE, NULL, @@$); }
379 | MNEMONIC 'A' { $$ = astnode_create_instruction($1, ACCUMULATOR_MODE, NULL, @@$); }
380 | MNEMONIC '#' expression { $$ = astnode_create_instruction($1, IMMEDIATE_MODE, $3, @@$); }
381 | MNEMONIC expression { $$ = astnode_create_instruction($1, ABSOLUTE_MODE, $2, @@$); }
382 | MNEMONIC expression ',' 'X' { $$ = astnode_create_instruction($1, ABSOLUTE_X_MODE, $2, @@$); }
383 | MNEMONIC expression ',' 'Y' { $$ = astnode_create_instruction($1, ABSOLUTE_Y_MODE, $2, @@$); }
384 | MNEMONIC '[' expression ',' 'X' ']' { $$ = astnode_create_instruction($1, PREINDEXED_INDIRECT_MODE, $3, @@$); }
385 | MNEMONIC '[' expression ']' ',' 'Y' { $$ = astnode_create_instruction($1, POSTINDEXED_INDIRECT_MODE, $3, @@$); }
386 | MNEMONIC '[' expression ']' { $$ = astnode_create_instruction($1, INDIRECT_MODE, $3, @@$); }
390 indexed_identifier { $$ = $1; }
391 | SIZEOF sizeof_arg { $$ = astnode_create_sizeof($2, @@$); }
392 | scope_access { $$ = $1; }
393 | struc_access { $$ = $1; }
394 | local_id { $$ = $1; }
395 | literal { $$ = $1; }
396 | '$' { $$ = astnode_create_pc(@@$); }
397 | arithmetic_expression { $$ = $1; }
398 | comparison_expression { $$ = $1; }
399 | '(' expression ')' { $$ = $2; }
400 | '+' { $$ = astnode_create_forward_branch("+", @@$); }
401 | '-' { $$ = astnode_create_backward_branch("-", @@$); }
402 | FORWARD_BRANCH { $$ = astnode_create_forward_branch($1, @@$); }
403 | BACKWARD_BRANCH { $$ = astnode_create_backward_branch($1, @@$); }
404 | MASK scope_access { $$ = astnode_create_mask($2, @@$); }
408 identifier { $$ = $1; }
409 | identifier '[' expression ']' { $$ = astnode_create_index($1, $3, @@$); }
410 | identifier '(' expression ')' { $$ = astnode_create_index($1, $3, @@$); }
414 expression { $$ = $1; }
415 | struc_initializer { $$ = $1; }
419 identifier { $$ = $1; }
420 | datatype { $$ = $1; }
424 expression { $$ = $1; }
429 identifier SCOPE_OP identifier { $$ = astnode_create_scope($1, $3, @@$); }
433 indexed_identifier '.' struc_access { $$ = astnode_create_dot($1, $3, @@$); }
434 | indexed_identifier '.' indexed_identifier { $$ = astnode_create_dot($1, $3, @@$); }
438 '{' field_initializer_list_opt '}' { $$ = astnode_create_struc($2, @@$); }
441 field_initializer_list_opt:
442 field_initializer_list { $$ = $1; }
446 field_initializer_list:
447 field_initializer { $$ = $1; }
448 | field_initializer_list ',' field_initializer { $$ = $1; astnode_add_sibling($$, $3); }
452 extended_expression { $$ = $1; }
453 | { $$ = astnode_create_null(@@$); }
457 LOCAL_ID { $$ = astnode_create_local_id($1, @@$); }
460 arithmetic_expression:
461 expression '+' expression { $$ = astnode_create_arithmetic(PLUS_OPERATOR, $1, $3, @@$); }
462 | expression '-' expression { $$ = astnode_create_arithmetic(MINUS_OPERATOR, $1, $3, @@$); }
463 | expression '*' expression { $$ = astnode_create_arithmetic(MUL_OPERATOR, $1, $3, @@$); }
464 | expression '/' expression { $$ = astnode_create_arithmetic(DIV_OPERATOR, $1, $3, @@$); }
465 | expression '%' expression { $$ = astnode_create_arithmetic(MOD_OPERATOR, $1, $3, @@$); }
466 | expression '&' expression { $$ = astnode_create_arithmetic(AND_OPERATOR, $1, $3, @@$); }
467 | expression '|' expression { $$ = astnode_create_arithmetic(OR_OPERATOR, $1, $3, @@$); }
468 | expression '^' expression { $$ = astnode_create_arithmetic(XOR_OPERATOR, $1, $3, @@$); }
469 | expression SHL_OP expression { $$ = astnode_create_arithmetic(SHL_OPERATOR, $1, $3, @@$); }
470 | expression SHR_OP expression { $$ = astnode_create_arithmetic(SHR_OPERATOR, $1, $3, @@$); }
471 | '~' expression { $$ = astnode_create_arithmetic(NEG_OPERATOR, $2, NULL, @@$); }
472 | '!' expression { $$ = astnode_create_arithmetic(NOT_OPERATOR, $2, NULL, @@$); }
473 | '^' identifier { $$ = astnode_create_arithmetic(BANK_OPERATOR, $2, NULL, @@$); }
474 | '<' expression %prec LO_OP { $$ = astnode_create_arithmetic(LO_OPERATOR, $2, NULL, @@$); }
475 | '>' expression %prec HI_OP { $$ = astnode_create_arithmetic(HI_OPERATOR, $2, NULL, @@$); }
476 | '-' expression %prec UMINUS { $$ = astnode_create_arithmetic(UMINUS_OPERATOR, $2, NULL, @@$); }
479 comparison_expression:
480 expression EQ_OP expression { $$ = astnode_create_arithmetic(EQ_OPERATOR, $1, $3, @@$); }
481 | expression NE_OP expression { $$ = astnode_create_arithmetic(NE_OPERATOR, $1, $3, @@$); }
482 | expression '>' expression { $$ = astnode_create_arithmetic(GT_OPERATOR, $1, $3, @@$); }
483 | expression '<' expression { $$ = astnode_create_arithmetic(LT_OPERATOR, $1, $3, @@$); }
484 | expression GE_OP expression { $$ = astnode_create_arithmetic(GE_OPERATOR, $1, $3, @@$); }
485 | expression LE_OP expression { $$ = astnode_create_arithmetic(LE_OPERATOR, $1, $3, @@$); }
489 LABEL { $$ = astnode_create_label($1, NULL, NULL, @@$); }
490 | LOCAL_LABEL { $$ = astnode_create_local_label($1, @@$); }
491 | '+' { $$ = astnode_create_forward_branch_decl("+", @@$); }
492 | '-' { $$ = astnode_create_backward_branch_decl("-", @@$); }
493 | FORWARD_BRANCH { $$ = astnode_create_forward_branch_decl($1, @@$); }
494 | BACKWARD_BRANCH { $$ = astnode_create_backward_branch_decl($1, @@$); }
498 IDENTIFIER { $$ = astnode_create_identifier($1, @@$); }
502 identifier { $$ = $1; }
503 | { $$ = astnode_create_null(@@$); }
507 INTEGER_LITERAL { $$ = astnode_create_integer($1, @@$); }
508 | STRING_LITERAL { $$ = astnode_create_string($1, @@$); }
512 IF expression line_tail statement_list elif_statement_list_opt else_part_opt ENDIF line_tail { $$ = astnode_create_if($2, $4, $5, $6, @@$); }
515 elif_statement_list_opt:
516 elif_statement_list { $$ = $1; }
521 elif_statement { $$ = $1; }
522 | elif_statement_list elif_statement { $$ = $1; astnode_add_sibling($$, $2); }
526 ELIF expression line_tail statement_list { $$ = astnode_create_case($2, $4, @@$); }
530 ELSE line_tail statement_list { $$ = $3; }
535 IFDEF identifier line_tail statement_list else_part_opt ENDIF line_tail { $$ = astnode_create_ifdef($2, $4, $5, @@$); }
539 IFNDEF identifier line_tail statement_list else_part_opt ENDIF line_tail { $$ = astnode_create_ifndef($2, $4, $5, @@$); }
543 named_data_statement line_tail { $$ = $1; }
544 | unnamed_data_statement line_tail { $$ = $1; }
547 named_data_statement:
548 identifier unnamed_data_statement { $$ = astnode_create_var_decl(0, $1, $2, @@$); }
549 | ZEROPAGE identifier unnamed_data_statement { $$ = astnode_create_var_decl(ZEROPAGE_FLAG, $2, $3, @@$); }
550 | PUBLIC identifier unnamed_data_statement { $$ = astnode_create_var_decl(PUBLIC_FLAG, $2, $3, @@$); }
551 | ZEROPAGE PUBLIC identifier unnamed_data_statement { $$ = astnode_create_var_decl(ZEROPAGE_FLAG | PUBLIC_FLAG, $3, $4, @@$); }
552 | PUBLIC ZEROPAGE identifier unnamed_data_statement { $$ = astnode_create_var_decl(PUBLIC_FLAG | ZEROPAGE_FLAG, $3, $4, @@$); }
555 unnamed_data_statement:
556 datatype expression_list { $$ = astnode_create_data($1, $2, @@$); }
557 | datatype { $$ = astnode_create_storage($1, NULL, @@$); }
558 | datatype '[' expression ']' { $$ = astnode_create_storage($1, $3, @@$); }
562 BYTE { $$ = astnode_create_datatype(BYTE_DATATYPE, NULL, @@$); }
563 | CHAR { $$ = astnode_create_datatype(CHAR_DATATYPE, NULL, @@$); }
564 | WORD { $$ = astnode_create_datatype(WORD_DATATYPE, NULL, @@$); }
565 | DWORD { $$ = astnode_create_datatype(DWORD_DATATYPE, NULL, @@$); }
566 | TAG identifier { $$ = astnode_create_datatype(USER_DATATYPE, $2, @@$); }
567 | '.' identifier { $$ = astnode_create_datatype(USER_DATATYPE, $2, @@$); }
571 extended_expression { $$ = $1; }
572 | expression_list ',' extended_expression { $$ = $1; astnode_add_sibling($$, $3); }
576 INCSRC file_specifier line_tail { $$ = astnode_create_incsrc($2, @@$); handle_incsrc($$); }
580 INCBIN file_specifier line_tail { $$ = astnode_create_incbin($2, @@$); handle_incbin($$); }
584 STRING_LITERAL { $$ = astnode_create_string($1, @@$); }
585 | FILE_PATH { $$ = astnode_create_file_path($1, @@$); }
588 macro_decl_statement:
589 MACRO identifier param_list_opt line_tail statement_list ENDM line_tail { $$ = astnode_create_macro_decl($2, $3, $5, @@$); }
593 identifier_list { $$ = $1; }
598 identifier arg_list_opt line_tail { $$ = astnode_create_macro($1, $2, @@$); }
602 expression_list { $$ = $1; }
607 identifier { $$ = $1; }
608 | identifier_list ',' identifier { $$ = $1; astnode_add_sibling($$, $3); }
612 identifier EQU extended_expression line_tail { $$ = astnode_create_equ($1, $3, @@$); }
616 identifier '=' extended_expression line_tail { $$ = astnode_create_assign($1, $3, @@$); }
620 DEFINE identifier line_tail { $$ = astnode_create_equ($2, astnode_create_integer(0, @@$), @@$); }
621 | DEFINE identifier extended_expression line_tail { $$ = astnode_create_equ($2, $3, @@$); }
625 PUBLIC identifier_list line_tail { $$ = astnode_create_public($2, @@$); }
629 EXTRN identifier_list ':' symbol_type from_part_opt line_tail { $$ = astnode_create_extrn($2, $4, $5, @@$); }
633 '@@' identifier { $$ = $2; }
638 datatype { $$ = $1; }
639 | identifier { $$ = astnode_create_datatype(USER_DATATYPE, $1, @@$); }
640 | PROC { $$ = astnode_create_integer(PROC_SYMBOL, @@$); }
641 | _LABEL_ { $$ = astnode_create_integer(LABEL_SYMBOL, @@$); }
645 named_storage_statement { $$ = $1; }
646 | unnamed_storage_statement { $$ = $1; }
649 named_storage_statement:
650 identifier unnamed_storage_statement { $$ = astnode_create_var_decl(0, $1, $2, @@$); }
651 | ZEROPAGE identifier unnamed_storage_statement { $$ = astnode_create_var_decl(ZEROPAGE_FLAG, $2, $3, @@$); }
652 | PUBLIC identifier unnamed_storage_statement { $$ = astnode_create_var_decl(PUBLIC_FLAG, $2, $3, @@$); }
653 | ZEROPAGE PUBLIC identifier unnamed_storage_statement { $$ = astnode_create_var_decl(ZEROPAGE_FLAG | PUBLIC_FLAG, $3, $4, @@$); }
654 | PUBLIC ZEROPAGE identifier unnamed_storage_statement { $$ = astnode_create_var_decl(PUBLIC_FLAG | ZEROPAGE_FLAG, $3, $4, @@$); }
657 unnamed_storage_statement:
658 storage expression_opt line_tail { $$ = astnode_create_storage($1, $2, @@$); }
662 DSB { $$ = astnode_create_datatype(BYTE_DATATYPE, NULL, @@$); }
663 | DSW { $$ = astnode_create_datatype(WORD_DATATYPE, NULL, @@$); }
664 | DSD { $$ = astnode_create_datatype(DWORD_DATATYPE, NULL, @@$); }
668 * Takes care of switching to a new scanner input stream when a "incsrc" statement
669 * has been encountered.
670 * The current stream is pushed on a stack, and will be popped when EOF is reached
672 * @@param n A node of type INCSRC_NODE
674 void handle_incsrc(astnode *n)
677 /* Get the node which describes the file to include */
678 astnode *file = astnode_get_child(n, 0);
680 switch (astnode_get_type(file)) {
682 /* TODO: add path searching */
684 switch (yypushandrestart(file->string)) {
689 /* Failed to open file */
690 sprintf(errs, "could not open '%s' for reading", file->string);
695 yyerror("Maximum include nesting level reached");
704 // TODO: This shouldn't be done here but rather in astproc module.
707 * Takes care of including the binary contents of the file specified by a parsed
708 * "incbin" statement.
709 * Calls yyerror() if the file can't be included for some reason.
710 * @@param n A node of type INCBIN_NODE
712 void handle_incbin(astnode *n)
718 /* Get the node which describes the file to include */
719 astnode *file = astnode_get_child(n, 0);
720 const char *filename = file->string;
722 switch (astnode_get_type(file)) {
724 /* TODO: add path searching */
726 /* Attempt to open file */
727 fp = fopen(filename, "rb");
728 if (!fp && (filename[0] != '/')) {
729 /* Try search paths */
730 /* ### copied from scanner.l -- generalize */
732 for (i = 0; i < xasm_args.include_path_count; ++i) {
733 const char *include_path = xasm_args.include_paths[i];
734 char *path = (char *)malloc(
735 strlen(include_path) + strlen("/") + strlen(filename) + 1);
736 strcpy(path, include_path);
738 strcat(path, filename);
739 fp = fopen(path, "rb");
747 fseek(fp, 0, SEEK_END);
751 /* Allocate buffer to hold file contents */
752 data = (unsigned char *)malloc(size);
753 /* Read file contents into buffer */
754 fread(data, 1, size, fp);
755 /* Insert binary node */
756 astnode_add_sibling(n, astnode_create_binary(data, size, n->loc) );
762 /* Couldn't open file */
763 sprintf(errs, "could not open '%s' for reading", file->string);
776 @--case-insensitive option
781 * $Id: parser.y,v 1.12 2007/08/12 18:59:00 khansen Exp khansen $
791 @ability to generate pure 6502 binary
796 * $Id: parser.y,v 1.11 2007/08/11 01:25:50 khansen Exp khansen $
800 void yyerror(char *); /* In lexer */
803 int yypushandrestart(char *); /* In lexer */
814 @includepaths support (-I option)
819 * $Id: parser.y,v 1.10 2007/07/22 13:34:38 khansen Exp khansen $
823 %type <node> identifier identifier_opt local_id assembly_unit statement labelable_statement statement_list if_statement elif_statement elif_statement_list elif_statement_list_opt ifdef_statement ifndef_statement macro_decl_statement macro_statement instruction_statement data_statement storage_statement null_statement incsrc_statement incbin_statement equ_statement assign_statement public_statement extrn_statement dataseg_statement codeseg_statement charmap_statement struc_decl_statement union_decl_statement enum_decl_statement record_decl_statement instruction expression extended_expression expression_opt arithmetic_expression comparison_expression literal label label_decl identifier_list expression_list file_specifier param_list_opt arg_list_opt else_part_opt scope_access struc_access struc_initializer field_initializer_list field_initializer_list_opt field_initializer datatype storage named_data_statement unnamed_data_statement named_storage_statement unnamed_storage_statement proc_statement rept_statement label_statement message_statement warning_statement error_statement while_statement define_statement align_statement symbol_type enum_item_list enum_item record_field_list record_field sizeof_arg label_addr_part_opt label_type_part_opt from_part_opt indexed_identifier
826 %token _LABEL_ BYTE CHAR WORD DWORD DSB DSW DSD DATASEG CODESEG IF IFDEF IFNDEF ELSE ELIF ENDIF INCSRC INCBIN MACRO REPT WHILE ENDM ALIGN EQU DEFINE END PUBLIC EXTRN CHARMAP STRUC UNION ENDS RECORD ENUM ENDE PROC ENDP SIZEOF MASK TAG MESSAGE WARNING ERROR ZEROPAGE
831 '=' INTEGER_LITERAL { $$ = astnode_create_integer($2, @@$); }
837 @convert tabs to whitespaces
842 * $Id: parser.y,v 1.9 2005/01/05 02:28:40 kenth Exp khansen $
848 fp = fopen(file->string, "rb");
854 @anonymous union parsing
859 * $Id: parser.y,v 1.8 2004/12/29 21:45:26 kenth Exp kenth $
863 void yyerror(char *); /* In lexer */
864 int yylex(void); /* In lexer */
865 int yypushandrestart(char *); /* In lexer */
868 extern char *yytext; /* In lexer */
869 extern YYLTYPE yylloc; /* In lexer */
870 extern astnode *root_node; /* Root of the generated parse tree */
871 void handle_incsrc(astnode *); /* See below */
872 void handle_incbin(astnode *); /* See below */
875 statement_list end_opt { root_node = astnode_create_list($1); }
884 labelable_statement { $$ = $1; }
885 | statement_list labelable_statement {
886 if ($1 != NULL) { $$ = $1; astnode_add_sibling($$, $2); }
892 label_decl statement { $$ = $1; astnode_add_sibling($$, $2); }
893 | statement { $$ = $1; }
897 if_statement { $$ = $1; }
898 | ifdef_statement { $$ = $1; }
899 | ifndef_statement { $$ = $1; }
900 | macro_decl_statement { $$ = $1; }
901 | macro_statement { $$ = $1; }
902 | incsrc_statement { $$ = $1; }
903 | incbin_statement { $$ = $1; }
904 | equ_statement { $$ = $1; }
905 | assign_statement { $$ = $1; }
906 | public_statement { $$ = $1; }
907 | extrn_statement { $$ = $1; }
908 | instruction_statement { $$ = $1; }
909 | data_statement { $$ = $1; }
910 | storage_statement { $$ = $1; }
911 | dataseg_statement { $$ = $1; }
912 | codeseg_statement { $$ = $1; }
913 | charmap_statement { $$ = $1; }
914 | struc_decl_statement { $$ = $1; }
915 | union_decl_statement { $$ = $1; }
916 | enum_decl_statement { $$ = $1; }
917 | record_decl_statement { $$ = $1; }
918 | proc_statement { $$ = $1; }
919 | rept_statement { $$ = $1; }
920 | while_statement { $$ = $1; }
921 | label_statement { $$ = $1; }
922 | message_statement { $$ = $1; }
923 | warning_statement { $$ = $1; }
924 | error_statement { $$ = $1; }
925 | define_statement { $$ = $1; }
926 | align_statement { $$ = $1; }
927 | null_statement { $$ = $1; }
928 | error line_tail { $$ = NULL; }
932 ALIGN identifier_list expression line_tail { $$ = astnode_create_align($2, $3, @@$); }
936 WARNING expression line_tail { $$ = astnode_create_warning($2, @@$); }
940 ERROR expression line_tail { $$ = astnode_create_error($2, @@$); }
944 MESSAGE expression line_tail { $$ = astnode_create_message($2, @@$); }
948 _LABEL_ identifier label_addr_part_opt label_type_part_opt line_tail { $$ = astnode_create_label($2->label, $3, $4, @@$); }
952 '=' INTEGER_LITERAL { $$ = astnode_create_integer($2, @@$); }
957 ':' symbol_type { $$ = $2; }
962 WHILE expression line_tail statement_list ENDM line_tail { $$ = astnode_create_while($2, $4, @@$); }
966 REPT expression line_tail statement_list ENDM line_tail { $$ = astnode_create_rept($2, $4, @@$); }
970 PROC identifier line_tail statement_list ENDP line_tail { $$ = astnode_create_proc($2, $4, @@$); }
974 STRUC identifier line_tail statement_list ENDS line_tail { $$ = astnode_create_struc_decl($2, $4, @@$); }
978 UNION identifier_opt line_tail statement_list ENDS line_tail { $$ = astnode_create_union_decl($2, $4, @@$); }
982 ENUM identifier line_tail enum_item_list ENDE line_tail { $$ = astnode_create_enum_decl($2, $4, @@$); }
986 enum_item { $$ = $1; }
987 | enum_item_list enum_item { $$ = $1; astnode_add_sibling($$, $2); }
991 assign_statement { $$ = $1; }
992 | identifier line_tail { $$ = $1; }
996 RECORD identifier record_field_list line_tail { $$ = astnode_create_record_decl($2, $3, @@$); }
1000 record_field { $$ = $1; }
1001 | record_field_list ',' record_field { $$ = $1; astnode_add_sibling($$, $3); }
1005 identifier ':' expression { $$ = astnode_create_bitfield_decl($1, $3, @@$); }
1009 CHARMAP file_specifier line_tail { $$ = astnode_create_charmap($2, @@$); }
1013 DATASEG line_tail { $$ = astnode_create_dataseg(0, @@$); }
1014 | DATASEG ZEROPAGE line_tail { $$ = astnode_create_dataseg(ZEROPAGE_FLAG, @@$); }
1017 CODESEG line_tail { $$ = astnode_create_codeseg(@@$); }
1021 line_tail { $$ = NULL; }
1038 instruction line_tail { $$ = $1; }
1042 MNEMONIC { $$ = astnode_create_instruction($1, IMPLIED_MODE, NULL, @@$); }
1043 | MNEMONIC 'A' { $$ = astnode_create_instruction($1, ACCUMULATOR_MODE, NULL, @@$); }
1044 | MNEMONIC '#' expression { $$ = astnode_create_instruction($1, IMMEDIATE_MODE, $3, @@$); }
1045 | MNEMONIC expression { $$ = astnode_create_instruction($1, ABSOLUTE_MODE, $2, @@$); }
1046 | MNEMONIC expression ',' 'X' { $$ = astnode_create_instruction($1, ABSOLUTE_X_MODE, $2, @@$); }
1047 | MNEMONIC expression ',' 'Y' { $$ = astnode_create_instruction($1, ABSOLUTE_Y_MODE, $2, @@$); }
1048 | MNEMONIC '[' expression ',' 'X' ']' { $$ = astnode_create_instruction($1, PREINDEXED_INDIRECT_MODE, $3, @@$); }
1049 | MNEMONIC '[' expression ']' ',' 'Y' { $$ = astnode_create_instruction($1, POSTINDEXED_INDIRECT_MODE, $3, @@$); }
1050 | MNEMONIC '[' expression ']' { $$ = astnode_create_instruction($1, INDIRECT_MODE, $3, @@$); }
1054 indexed_identifier { $$ = $1; }
1055 | SIZEOF sizeof_arg { $$ = astnode_create_sizeof($2, @@$); }
1056 | scope_access { $$ = $1; }
1057 | struc_access { $$ = $1; }
1058 | local_id { $$ = $1; }
1059 | literal { $$ = $1; }
1060 | '$' { $$ = astnode_create_pc(@@$); }
1061 | arithmetic_expression { $$ = $1; }
1062 | comparison_expression { $$ = $1; }
1063 | '(' expression ')' { $$ = $2; }
1064 | '+' { $$ = astnode_create_forward_branch("+", @@$); }
1065 | '-' { $$ = astnode_create_backward_branch("-", @@$); }
1066 | FORWARD_BRANCH { $$ = astnode_create_forward_branch($1, @@$); }
1067 | BACKWARD_BRANCH { $$ = astnode_create_backward_branch($1, @@$); }
1068 | MASK scope_access { $$ = astnode_create_mask($2, @@$); }
1072 identifier { $$ = $1; }
1073 | identifier '[' expression ']' { $$ = astnode_create_index($1, $3, @@$); }
1074 | identifier '(' expression ')' { $$ = astnode_create_index($1, $3, @@$); }
1078 expression { $$ = $1; }
1079 | struc_initializer { $$ = $1; }
1083 identifier { $$ = $1; }
1084 | datatype { $$ = $1; }
1088 expression { $$ = $1; }
1093 identifier SCOPE_OP identifier { $$ = astnode_create_scope($1, $3, @@$); }
1097 indexed_identifier '.' struc_access { $$ = astnode_create_dot($1, $3, @@$); }
1098 | indexed_identifier '.' indexed_identifier { $$ = astnode_create_dot($1, $3, @@$); }
1102 '{' field_initializer_list_opt '}' { $$ = astnode_create_struc($2, @@$); }
1106 field_initializer_list { $$ = $1; }
1111 field_initializer { $$ = $1; }
1112 | field_initializer_list ',' field_initializer { $$ = $1; astnode_add_sibling($$, $3); }
1116 extended_expression { $$ = $1; }
1117 | { $$ = astnode_create_null(@@$); }
1121 LOCAL_ID { $$ = astnode_create_local_id($1, @@$); }
1125 expression '+' expression { $$ = astnode_create_arithmetic(PLUS_OPERATOR, $1, $3, @@$); }
1126 | expression '-' expression { $$ = astnode_create_arithmetic(MINUS_OPERATOR, $1, $3, @@$); }
1127 | expression '*' expression { $$ = astnode_create_arithmetic(MUL_OPERATOR, $1, $3, @@$); }
1128 | expression '/' expression { $$ = astnode_create_arithmetic(DIV_OPERATOR, $1, $3, @@$); }
1129 | expression '%' expression { $$ = astnode_create_arithmetic(MOD_OPERATOR, $1, $3, @@$); }
1130 | expression '&' expression { $$ = astnode_create_arithmetic(AND_OPERATOR, $1, $3, @@$); }
1131 | expression '|' expression { $$ = astnode_create_arithmetic(OR_OPERATOR, $1, $3, @@$); }
1132 | expression '^' expression { $$ = astnode_create_arithmetic(XOR_OPERATOR, $1, $3, @@$); }
1133 | expression SHL_OP expression { $$ = astnode_create_arithmetic(SHL_OPERATOR, $1, $3, @@$); }
1134 | expression SHR_OP expression { $$ = astnode_create_arithmetic(SHR_OPERATOR, $1, $3, @@$); }
1135 | '~' expression { $$ = astnode_create_arithmetic(NEG_OPERATOR, $2, NULL, @@$); }
1136 | '!' expression { $$ = astnode_create_arithmetic(NOT_OPERATOR, $2, NULL, @@$); }
1137 | '^' identifier { $$ = astnode_create_arithmetic(BANK_OPERATOR, $2, NULL, @@$); }
1138 | '<' expression %prec LO_OP { $$ = astnode_create_arithmetic(LO_OPERATOR, $2, NULL, @@$); }
1139 | '>' expression %prec HI_OP { $$ = astnode_create_arithmetic(HI_OPERATOR, $2, NULL, @@$); }
1140 | '-' expression %prec UMINUS { $$ = astnode_create_arithmetic(UMINUS_OPERATOR, $2, NULL, @@$); }
1144 expression EQ_OP expression { $$ = astnode_create_arithmetic(EQ_OPERATOR, $1, $3, @@$); }
1145 | expression NE_OP expression { $$ = astnode_create_arithmetic(NE_OPERATOR, $1, $3, @@$); }
1146 | expression '>' expression { $$ = astnode_create_arithmetic(GT_OPERATOR, $1, $3, @@$); }
1147 | expression '<' expression { $$ = astnode_create_arithmetic(LT_OPERATOR, $1, $3, @@$); }
1148 | expression GE_OP expression { $$ = astnode_create_arithmetic(GE_OPERATOR, $1, $3, @@$); }
1149 | expression LE_OP expression { $$ = astnode_create_arithmetic(LE_OPERATOR, $1, $3, @@$); }
1153 LABEL { $$ = astnode_create_label($1, NULL, NULL, @@$); }
1154 | LOCAL_LABEL { $$ = astnode_create_local_label($1, @@$); }
1155 | '+' { $$ = astnode_create_forward_branch_decl("+", @@$); }
1156 | '-' { $$ = astnode_create_backward_branch_decl("-", @@$); }
1157 | FORWARD_BRANCH { $$ = astnode_create_forward_branch_decl($1, @@$); }
1158 | BACKWARD_BRANCH { $$ = astnode_create_backward_branch_decl($1, @@$); }
1162 IDENTIFIER { $$ = astnode_create_identifier($1, @@$); }
1166 identifier { $$ = $1; }
1167 | { $$ = astnode_create_null(@@$); }
1171 INTEGER_LITERAL { $$ = astnode_create_integer($1, @@$); }
1172 | STRING_LITERAL { $$ = astnode_create_string($1, @@$); }
1176 IF expression line_tail statement_list elif_statement_list_opt else_part_opt ENDIF line_tail { $$ = astnode_create_if($2, $4, $5, $6, @@$); }
1180 elif_statement_list { $$ = $1; }
1185 elif_statement { $$ = $1; }
1186 | elif_statement_list elif_statement { $$ = $1; astnode_add_sibling($$, $2); }
1190 ELIF expression line_tail statement_list { $$ = astnode_create_case($2, $4, @@$); }
1194 ELSE line_tail statement_list { $$ = $3; }
1199 IFDEF identifier line_tail statement_list else_part_opt ENDIF line_tail { $$ = astnode_create_ifdef($2, $4, $5, @@$); }
1203 IFNDEF identifier line_tail statement_list else_part_opt ENDIF line_tail { $$ = astnode_create_ifndef($2, $4, $5, @@$); }
1207 named_data_statement line_tail { $$ = $1; }
1208 | unnamed_data_statement line_tail { $$ = $1; }
1212 identifier unnamed_data_statement { $$ = astnode_create_var_decl(0, $1, $2, @@$); }
1213 | ZEROPAGE identifier unnamed_data_statement { $$ = astnode_create_var_decl(ZEROPAGE_FLAG, $2, $3, @@$); }
1214 | PUBLIC identifier unnamed_data_statement { $$ = astnode_create_var_decl(PUBLIC_FLAG, $2, $3, @@$); }
1215 | ZEROPAGE PUBLIC identifier unnamed_data_statement { $$ = astnode_create_var_decl(ZEROPAGE_FLAG | PUBLIC_FLAG, $3, $4, @@$); }
1216 | PUBLIC ZEROPAGE identifier unnamed_data_statement { $$ = astnode_create_var_decl(PUBLIC_FLAG | ZEROPAGE_FLAG, $3, $4, @@$); }
1220 datatype expression_list { $$ = astnode_create_data($1, $2, @@$); }
1221 | datatype { $$ = astnode_create_storage($1, NULL, @@$); }
1222 | datatype '[' expression ']' { $$ = astnode_create_storage($1, $3, @@$); }
1226 BYTE { $$ = astnode_create_datatype(BYTE_DATATYPE, NULL, @@$); }
1227 | CHAR { $$ = astnode_create_datatype(CHAR_DATATYPE, NULL, @@$); }
1228 | WORD { $$ = astnode_create_datatype(WORD_DATATYPE, NULL, @@$); }
1229 | DWORD { $$ = astnode_create_datatype(DWORD_DATATYPE, NULL, @@$); }
1230 | TAG identifier { $$ = astnode_create_datatype(USER_DATATYPE, $2, @@$); }
1231 | '.' identifier { $$ = astnode_create_datatype(USER_DATATYPE, $2, @@$); }
1235 extended_expression { $$ = $1; }
1236 | expression_list ',' extended_expression { $$ = $1; astnode_add_sibling($$, $3); }
1240 INCSRC file_specifier line_tail { $$ = astnode_create_incsrc($2, @@$); handle_incsrc($$); }
1244 INCBIN file_specifier line_tail { $$ = astnode_create_incbin($2, @@$); handle_incbin($$); }
1248 STRING_LITERAL { $$ = astnode_create_string($1, @@$); }
1249 | FILE_PATH { $$ = astnode_create_file_path($1, @@$); }
1253 MACRO identifier param_list_opt line_tail statement_list ENDM line_tail { $$ = astnode_create_macro_decl($2, $3, $5, @@$); }
1257 identifier_list { $$ = $1; }
1262 identifier arg_list_opt line_tail { $$ = astnode_create_macro($1, $2, @@$); }
1266 expression_list { $$ = $1; }
1271 identifier { $$ = $1; }
1272 | identifier_list ',' identifier { $$ = $1; astnode_add_sibling($$, $3); }
1276 identifier EQU extended_expression line_tail { $$ = astnode_create_equ($1, $3, @@$); }
1280 identifier '=' extended_expression line_tail { $$ = astnode_create_assign($1, $3, @@$); }
1284 DEFINE identifier line_tail { $$ = astnode_create_equ($2, astnode_create_integer(0, @@$), @@$); }
1285 | DEFINE identifier extended_expression line_tail { $$ = astnode_create_equ($2, $3, @@$); }
1289 PUBLIC identifier_list line_tail { $$ = astnode_create_public($2, @@$); }
1293 EXTRN identifier_list ':' symbol_type from_part_opt line_tail { $$ = astnode_create_extrn($2, $4, $5, @@$); }
1297 '@@' identifier { $$ = $2; }
1302 datatype { $$ = $1; }
1303 | identifier { $$ = astnode_create_datatype(USER_DATATYPE, $1, @@$); }
1304 | PROC { $$ = astnode_create_integer(PROC_SYMBOL, @@$); }
1305 | _LABEL_ { $$ = astnode_create_integer(LABEL_SYMBOL, @@$); }
1309 named_storage_statement { $$ = $1; }
1310 | unnamed_storage_statement { $$ = $1; }
1314 identifier unnamed_storage_statement { $$ = astnode_create_var_decl(0, $1, $2, @@$); }
1315 | ZEROPAGE identifier unnamed_storage_statement { $$ = astnode_create_var_decl(ZEROPAGE_FLAG, $2, $3, @@$); }
1316 | PUBLIC identifier unnamed_storage_statement { $$ = astnode_create_var_decl(PUBLIC_FLAG, $2, $3, @@$); }
1317 | ZEROPAGE PUBLIC identifier unnamed_storage_statement { $$ = astnode_create_var_decl(ZEROPAGE_FLAG | PUBLIC_FLAG, $3, $4, @@$); }
1318 | PUBLIC ZEROPAGE identifier unnamed_storage_statement { $$ = astnode_create_var_decl(PUBLIC_FLAG | ZEROPAGE_FLAG, $3, $4, @@$); }
1322 storage expression_opt line_tail { $$ = astnode_create_storage($1, $2, @@$); }
1326 DSB { $$ = astnode_create_datatype(BYTE_DATATYPE, NULL, @@$); }
1327 | DSW { $$ = astnode_create_datatype(WORD_DATATYPE, NULL, @@$); }
1328 | DSD { $$ = astnode_create_datatype(DWORD_DATATYPE, NULL, @@$); }
1333 /* Get the node which describes the file to include */
1334 astnode *file = astnode_get_child(n, 0);
1336 switch (astnode_get_type(file)) {
1338 /* TODO: add path searching */
1339 case FILE_PATH_NODE:
1340 switch (yypushandrestart(file->string)) {
1345 /* Failed to open file */
1346 sprintf(errs, "could not open '%s' for reading", file->string);
1350 /* Stack overflow */
1351 yyerror("Maximum include nesting level reached");
1362 unsigned char *data;
1365 /* Get the node which describes the file to include */
1366 astnode *file = astnode_get_child(n, 0);
1368 switch (astnode_get_type(file)) {
1370 /* TODO: add path searching */
1371 case FILE_PATH_NODE:
1372 /* Attempt to open file */
1373 fp = fopen(file->string, "rb");
1376 fseek(fp, 0, SEEK_END);
1380 /* Allocate buffer to hold file contents */
1381 data = (unsigned char *)malloc(size);
1382 /* Read file contents into buffer */
1383 fread(data, 1, size, fp);
1384 /* Insert binary node */
1385 astnode_add_sibling(n, astnode_create_binary(data, size, n->loc) );
1391 /* Couldn't open file */
1392 sprintf(errs, "could not open '%s' for reading", file->string);
1411 * $Id: parser.y,v 1.7 2004/12/19 19:59:14 kenth Exp kenth $
1415 %type <node> identifier local_id assembly_unit statement labelable_statement statement_list if_statement elif_statement elif_statement_list elif_statement_list_opt ifdef_statement ifndef_statement macro_decl_statement macro_statement instruction_statement data_statement storage_statement null_statement incsrc_statement incbin_statement equ_statement assign_statement public_statement extrn_statement dataseg_statement codeseg_statement charmap_statement struc_decl_statement union_decl_statement enum_decl_statement record_decl_statement instruction expression extended_expression expression_opt arithmetic_expression comparison_expression literal label label_decl identifier_list expression_list file_specifier param_list_opt arg_list_opt else_part_opt scope_access struc_access struc_initializer field_initializer_list field_initializer_list_opt field_initializer datatype storage named_data_statement unnamed_data_statement named_storage_statement unnamed_storage_statement proc_statement rept_statement label_statement message_statement warning_statement error_statement while_statement define_statement align_statement symbol_type enum_item_list enum_item record_field_list record_field sizeof_arg label_addr_part_opt label_type_part_opt from_part_opt indexed_identifier
1418 UNION identifier line_tail statement_list ENDS line_tail { $$ = astnode_create_union_decl($2, $4, @@$); }
1430 * $Id: parser.y,v 1.6 2004/12/16 13:22:27 kenth Exp kenth $
1434 %type <node> identifier local_id assembly_unit statement labelable_statement statement_list if_statement elif_statement elif_statement_list elif_statement_list_opt ifdef_statement ifndef_statement macro_decl_statement macro_statement instruction_statement data_statement storage_statement null_statement incsrc_statement incbin_statement equ_statement assign_statement public_statement extrn_statement dataseg_statement codeseg_statement charmap_statement struc_decl_statement union_decl_statement enum_decl_statement record_decl_statement instruction expression extended_expression expression_opt arithmetic_expression comparison_expression literal label label_decl identifier_list expression_list file_specifier param_list_opt arg_list_opt else_part_opt scope_access struc_access struc_initializer field_initializer_list field_initializer_list_opt field_initializer datatype storage named_data_statement unnamed_data_statement named_storage_statement unnamed_storage_statement proc_statement rept_statement label_statement message_statement warning_statement error_statement while_statement define_statement align_statement symbol_type enum_item_list enum_item record_field_list record_field sizeof_arg label_addr_part_opt label_type_part_opt from_part_opt
1437 identifier { $$ = $1; }
1441 identifier '.' struc_access { $$ = astnode_create_dot($1, $3, @@$); }
1442 | identifier '.' identifier { $$ = astnode_create_dot($1, $3, @@$); }
1453 * $Id: parser.y,v 1.5 2004/12/14 01:50:42 kenth Exp kenth $
1457 %type <node> identifier local_id assembly_unit statement labelable_statement statement_list if_statement elif_statement elif_statement_list elif_statement_list_opt ifdef_statement ifndef_statement macro_decl_statement macro_statement instruction_statement data_statement storage_statement null_statement incsrc_statement incbin_statement equ_statement assign_statement public_statement extrn_statement dataseg_statement codeseg_statement charmap_statement struc_decl_statement union_decl_statement enum_decl_statement record_decl_statement instruction expression extended_expression expression_opt arithmetic_expression comparison_expression literal label label_decl identifier_list expression_list file_specifier param_list_opt arg_list_opt else_part_opt scope_access struc_access struc_initializer field_initializer_list field_initializer_list_opt field_initializer datatype storage named_data_statement unnamed_data_statement named_storage_statement unnamed_storage_statement proc_statement rept_statement label_statement message_statement warning_statement error_statement while_statement define_statement symbol_type enum_item_list enum_item record_field_list record_field sizeof_arg label_type_part_opt
1460 %token _LABEL_ BYTE CHAR WORD DWORD DSB DSW DSD DATASEG CODESEG IF IFDEF IFNDEF ELSE ELIF ENDIF INCSRC INCBIN MACRO REPT WHILE ENDM ALIGN EQU DEFINE END PUBLIC EXTRN CHARMAP STRUC UNION ENDS RECORD ENUM ENDE PROC ENDP SIZEOF MASK TAG MESSAGE WARNING ERROR
1466 _LABEL_ identifier label_type_part_opt line_tail { $$ = astnode_create_label($2->label, $3, @@$); }
1469 DATASEG line_tail { $$ = astnode_create_dataseg(@@$); }
1473 LABEL { $$ = astnode_create_label($1, NULL, @@$); }
1476 identifier unnamed_data_statement { $$ = astnode_create_var_decl($1, $2, @@$); }
1479 EXTRN identifier_list ':' symbol_type line_tail { $$ = astnode_create_extrn($2, $4, @@$); }
1482 identifier unnamed_storage_statement { $$ = astnode_create_var_decl($1, $2, @@$); }
1493 * $Id: parser.y,v 1.4 2004/12/11 02:12:41 kenth Exp kenth $
1497 %type <node> identifier local_id assembly_unit statement labelable_statement statement_list if_statement elif_statement elif_statement_list elif_statement_list_opt ifdef_statement ifndef_statement macro_decl_statement macro_statement instruction_statement data_statement storage_statement null_statement incsrc_statement incbin_statement equ_statement assign_statement public_statement extrn_statement dataseg_statement codeseg_statement charmap_statement struc_decl_statement union_decl_statement enum_decl_statement record_decl_statement instruction expression expression_opt arithmetic_expression comparison_expression literal label label_decl identifier_list expression_list file_specifier param_list_opt arg_list_opt else_part_opt scope_access struc_access struc_initializer field_initializer_list field_initializer_list_opt field_initializer datatype storage named_data_statement unnamed_data_statement named_storage_statement unnamed_storage_statement proc_statement rept_statement label_statement message_statement warning_statement error_statement while_statement symbol_type enum_item_list enum_item record_field_list record_field sizeof_arg
1503 %token BYTE CHAR WORD DWORD
1505 %token DATASEG CODESEG
1506 %token IF IFDEF IFNDEF ELSE ELIF ENDIF
1507 %token INCSRC INCBIN
1508 %token MACRO REPT WHILE ENDM
1514 %token STRUC UNION ENDS
1521 %token MESSAGE WARNING ERROR
1525 _LABEL_ identifier line_tail { $$ = astnode_create_label($2->label, @@$); }
1527 | struc_initializer { $$ = $1; }
1531 expression { $$ = $1; }
1534 | '^' expression { $$ = astnode_create_arithmetic(BANK_OPERATOR, $2, NULL, @@$); }
1537 LABEL { $$ = astnode_create_label($1, @@$); }
1541 expression { $$ = $1; }
1542 | expression_list ',' expression { $$ = $1; astnode_add_sibling($$, $3); }
1545 identifier EQU expression line_tail { $$ = astnode_create_equ($1, $3, @@$); }
1548 identifier '=' expression line_tail { $$ = astnode_create_assign($1, $3, @@$); }
1559 * $Id: parser.y,v 1.3 2004/12/09 11:17:15 kenth Exp kenth $
1563 %type <node> identifier local_id assembly_unit statement labelable_statement statement_list if_statement ifdef_statement ifndef_statement macro_decl_statement macro_statement instruction_statement data_statement storage_statement null_statement incsrc_statement incbin_statement equ_statement assign_statement public_statement extrn_statement dataseg_statement codeseg_statement charmap_statement struc_decl_statement union_decl_statement enum_decl_statement instruction expression expression_opt arithmetic_expression comparison_expression literal label label_decl identifier_list expression_list file_specifier param_list_opt arg_list_opt else_part_opt scope_access struc_access struc_initializer field_initializer_list field_initializer_list_opt field_initializer datatype storage named_data_statement unnamed_data_statement named_storage_statement unnamed_storage_statement proc_statement rept_statement label_statement message_statement warning_statement error_statement symbol_type enum_item_list enum_item sizeof_arg
1566 %token MACRO REPT ENDM
1577 IF expression line_tail statement_list else_part_opt ENDIF line_tail { $$ = astnode_create_if($2, $4, $5, NULL, @@$); }
1580 ELSE statement_list { $$ = $2; }
1587 @added: warning_statement, error_statement
1592 * $Id: parser.y,v 1.2 2004/12/06 05:06:21 kenth Exp kenth $
1607 * $Id: parser.y,v 1.1 2004/06/30 07:57:03 kenth Exp kenth $
1611 %type <node> identifier local_id assembly_unit statement labelable_statement statement_list if_statement ifdef_statement ifndef_statement macro_decl_statement macro_statement instruction_statement data_statement storage_statement null_statement incsrc_statement incbin_statement equ_statement assign_statement public_statement extrn_statement dataseg_statement codeseg_statement charmap_statement struc_decl_statement union_decl_statement enum_decl_statement instruction expression expression_opt arithmetic_expression comparison_expression literal label label_decl identifier_list expression_list file_specifier param_list_opt arg_list_opt else_part_opt scope_access struc_access struc_initializer field_initializer_list field_initializer_list_opt field_initializer datatype storage named_data_statement unnamed_data_statement named_storage_statement unnamed_storage_statement proc_statement rept_statement label_statement message_statement symbol_type enum_item_list enum_item sizeof_arg
1631 #include "astnode.h"
1639 %token <datatype> DATATYPE
1640 %token <datatype> STORAGE
1641 %type <node> identifier local_id assembly_unit statement labelable_statement statement_list if_statement ifdef_statement ifndef_statement macro_decl_statement macro_statement instruction_statement data_statement storage_statement null_statement incsrc_statement incbin_statement equ_statement assign_statement public_statement extrn_statement dataseg_statement codeseg_statement charmap_statement instruction expression arithmetic_expression comparison_expression literal label label_decl identifier_list expression_list file_specifier param_list_opt arg_list_opt else_part_opt
1671 | '?' expression { $$ = astnode_create_arithmetic(BANK_OPERATOR, $2, NULL, @@$); }
1679 IF expression line_tail statement_list else_part_opt ENDIF line_tail { astnode_create_if($2, $4, $5, NULL, @@$); }
1686 DATATYPE expression_list line_tail { $$ = astnode_create_data($1, $2, @@$); }
1694 | expression_list ',' expression {
1695 if ($1 != NULL) { $$ = $1; astnode_add_sibling($$, $3); }
1706 pragma_prefix identifier arg_list_opt line_tail { $$ = astnode_create_macro($2, $3, @@$); }
1711 | identifier_list ',' identifier {
1712 if ($1 != NULL) { $$ = $1; astnode_add_sibling($$, $3); }
1721 EXTRN identifier_list line_tail { $$ = astnode_create_extrn($2, @@$); }
1725 STORAGE expression line_tail { $$ = astnode_create_storage($1, $2, @@$); }