1/* 2 * NASM-compatible parser header file 3 * 4 * Copyright (C) 2002-2007 Peter Johnson 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27#ifndef YASM_NASM_PARSER_H 28#define YASM_NASM_PARSER_H 29 30#include "nasm-parser-struct.h" 31 32#define YYCTYPE unsigned char 33 34#define MAX_SAVED_LINE_LEN 80 35 36enum tokentype { 37 INTNUM = 258, 38 FLTNUM, 39 DIRECTIVE_NAME, 40 FILENAME, 41 STRING, 42 SIZE_OVERRIDE, 43 OFFSET, 44 DECLARE_DATA, 45 RESERVE_SPACE, 46 LABEL, 47 INCBIN, 48 EQU, 49 TIMES, 50 DUP, 51 SEG, 52 WRT, 53 ABS, 54 REL, 55 NOSPLIT, 56 STRICT, 57 INSN, 58 PREFIX, 59 REG, 60 REGGROUP, 61 SEGREG, 62 TARGETMOD, 63 LEFT_OP, 64 RIGHT_OP, 65 LOW, 66 HIGH, 67 SIGNDIV, 68 SIGNMOD, 69 START_SECTION_ID, 70 ID, 71 LOCAL_ID, 72 SPECIAL_ID, 73 NONLOCAL_ID, 74 LINE, 75 NONE /* special token for lookahead */ 76}; 77 78enum nasm_parser_state { 79 INITIAL, 80 DIRECTIVE, 81 SECTION_DIRECTIVE, 82 DIRECTIVE2, 83 LINECHG, 84 LINECHG2, 85 INSTRUCTION 86}; 87 88#define YYSTYPE nasm_yystype 89 90/* shorter access names to commonly used parser_nasm fields */ 91#define p_object (parser_nasm->object) 92#define p_symtab (parser_nasm->object->symtab) 93#define cursect (parser_nasm->object->cur_section) 94#define curtok (parser_nasm->token) 95#define curval (parser_nasm->tokval) 96 97#define INTNUM_val (curval.intn) 98#define FLTNUM_val (curval.flt) 99#define DIRECTIVE_NAME_val (curval.str_val) 100#define FILENAME_val (curval.str_val) 101#define STRING_val (curval.str) 102#define SIZE_OVERRIDE_val (curval.int_info) 103#define DECLARE_DATA_val (curval.int_info) 104#define RESERVE_SPACE_val (curval.int_info) 105#define INSN_val (curval.bc) 106#define PREFIX_val (curval.arch_data) 107#define REG_val (curval.arch_data) 108#define REGGROUP_val (curval.arch_data) 109#define SEGREG_val (curval.arch_data) 110#define TARGETMOD_val (curval.arch_data) 111#define ID_val (curval.str_val) 112 113#define cur_line (yasm_linemap_get_current(parser_nasm->linemap)) 114 115#define p_expr_new_tree(l,o,r) yasm_expr_create_tree(l,o,r,cur_line) 116#define p_expr_new_branch(o,r) yasm_expr_create_branch(o,r,cur_line) 117#define p_expr_new_ident(r) yasm_expr_create_ident(r,cur_line) 118 119void nasm_parser_parse(yasm_parser_nasm *parser_nasm); 120void nasm_parser_cleanup(yasm_parser_nasm *parser_nasm); 121int nasm_parser_lex(YYSTYPE *lvalp, yasm_parser_nasm *parser_nasm); 122 123#endif 124