154 lines · plain
1%{2/*3 * Sub-Lexical Analyzer for macro invokation in 4 * the Aic7xxx SCSI Host adapter sequencer assembler.5 *6 * Copyright (c) 2001 Adaptec Inc.7 * All rights reserved.8 *9 * Redistribution and use in source and binary forms, with or without10 * modification, are permitted provided that the following conditions11 * are met:12 * 1. Redistributions of source code must retain the above copyright13 * notice, this list of conditions, and the following disclaimer,14 * without modification.15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer16 * substantially similar to the "NO WARRANTY" disclaimer below17 * ("Disclaimer") and any redistribution must be conditioned upon18 * including a substantially similar Disclaimer requirement for further19 * binary redistribution.20 * 3. Neither the names of the above-listed copyright holders nor the names21 * of any contributors may be used to endorse or promote products derived22 * from this software without specific prior written permission.23 *24 * Alternatively, this software may be distributed under the terms of the25 * GNU General Public License ("GPL") version 2 as published by the Free26 * Software Foundation.27 *28 * NO WARRANTY29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT33 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING38 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE39 * POSSIBILITY OF SUCH DAMAGES.40 *41 * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_macro_scan.l#8 $42 *43 * $FreeBSD$44 */45 46#include <sys/types.h>47 48#include <inttypes.h>49#include <limits.h>50#include <regex.h>51#include <stdio.h>52#include <string.h>53#include <sysexits.h>54#include "../queue.h"55 56#include "aicasm.h"57#include "aicasm_symbol.h"58#include "aicasm_macro_gram.h"59 60#define MAX_STR_CONST 409661static char string_buf[MAX_STR_CONST];62static char *string_buf_ptr;63static int parren_count;64static char buf[255];65int mmlineno;66%}67 68WORD [A-Za-z_][-A-Za-z_0-9]*69SPACE [ \t]+70MCARG [^(), \t]+71 72%x ARGLIST73 74%%75\n {76 ++mmlineno;77 }78\r ;79<ARGLIST>{SPACE} ;80<ARGLIST>\( {81 parren_count++;82 if (parren_count == 1) {83 string_buf_ptr = string_buf;84 return ('(');85 }86 *string_buf_ptr++ = '(';87 }88<ARGLIST>\) {89 if (parren_count == 1) {90 if (string_buf_ptr != string_buf) {91 /*92 * Return an argument and93 * rescan this parren so we94 * can return it as well.95 */96 *string_buf_ptr = '\0';97 mmlval.str = string_buf;98 string_buf_ptr = string_buf;99 unput(')');100 return T_ARG;101 }102 BEGIN INITIAL;103 return (')');104 }105 parren_count--;106 *string_buf_ptr++ = ')';107 }108<ARGLIST>{MCARG} {109 char *yptr;110 111 yptr = mmtext;112 while (*yptr)113 *string_buf_ptr++ = *yptr++;114 }115<ARGLIST>\, {116 if (string_buf_ptr != string_buf) {117 /*118 * Return an argument and119 * rescan this comma so we120 * can return it as well.121 */122 *string_buf_ptr = '\0';123 mmlval.str = string_buf;124 string_buf_ptr = string_buf;125 unput(',');126 return T_ARG;127 }128 return ',';129 }130{WORD}[(] {131 /* May be a symbol or a macro invocation. */132 mmlval.sym = symtable_get(mmtext);133 if (mmlval.sym->type != MACRO) {134 stop("Expecting Macro Name",135 EX_DATAERR);136 }137 unput('(');138 parren_count = 0;139 BEGIN ARGLIST;140 return T_SYMBOL;141 }142. { 143 snprintf(buf, sizeof(buf), "Invalid character "144 "'%c'", mmtext[0]);145 stop(buf, EX_DATAERR);146 }147%%148 149int150mmwrap()151{152 stop("EOF encountered in macro call", EX_DATAERR);153}154