18c2ecf20Sopenharmony_ci%{ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Sub-Lexical Analyzer for macro invokation in 48c2ecf20Sopenharmony_ci * the Aic7xxx SCSI Host adapter sequencer assembler. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (c) 2001 Adaptec Inc. 78c2ecf20Sopenharmony_ci * All rights reserved. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 108c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 118c2ecf20Sopenharmony_ci * are met: 128c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 138c2ecf20Sopenharmony_ci * notice, this list of conditions, and the following disclaimer, 148c2ecf20Sopenharmony_ci * without modification. 158c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer 168c2ecf20Sopenharmony_ci * substantially similar to the "NO WARRANTY" disclaimer below 178c2ecf20Sopenharmony_ci * ("Disclaimer") and any redistribution must be conditioned upon 188c2ecf20Sopenharmony_ci * including a substantially similar Disclaimer requirement for further 198c2ecf20Sopenharmony_ci * binary redistribution. 208c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names 218c2ecf20Sopenharmony_ci * of any contributors may be used to endorse or promote products derived 228c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 258c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 268c2ecf20Sopenharmony_ci * Software Foundation. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * NO WARRANTY 298c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 308c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 318c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 328c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 338c2ecf20Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 348c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 358c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 368c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 378c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 388c2ecf20Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 398c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES. 408c2ecf20Sopenharmony_ci * 418c2ecf20Sopenharmony_ci * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_macro_scan.l#8 $ 428c2ecf20Sopenharmony_ci * 438c2ecf20Sopenharmony_ci * $FreeBSD$ 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#include <sys/types.h> 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#include <inttypes.h> 498c2ecf20Sopenharmony_ci#include <limits.h> 508c2ecf20Sopenharmony_ci#include <regex.h> 518c2ecf20Sopenharmony_ci#include <stdio.h> 528c2ecf20Sopenharmony_ci#include <string.h> 538c2ecf20Sopenharmony_ci#include <sysexits.h> 548c2ecf20Sopenharmony_ci#include "../queue.h" 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#include "aicasm.h" 578c2ecf20Sopenharmony_ci#include "aicasm_symbol.h" 588c2ecf20Sopenharmony_ci#include "aicasm_macro_gram.h" 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define MAX_STR_CONST 4096 618c2ecf20Sopenharmony_cistatic char string_buf[MAX_STR_CONST]; 628c2ecf20Sopenharmony_cistatic char *string_buf_ptr; 638c2ecf20Sopenharmony_cistatic int parren_count; 648c2ecf20Sopenharmony_cistatic char buf[255]; 658c2ecf20Sopenharmony_ciint mmlineno; 668c2ecf20Sopenharmony_ci%} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciWORD [A-Za-z_][-A-Za-z_0-9]* 698c2ecf20Sopenharmony_ciSPACE [ \t]+ 708c2ecf20Sopenharmony_ciMCARG [^(), \t]+ 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci%x ARGLIST 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci%% 758c2ecf20Sopenharmony_ci\n { 768c2ecf20Sopenharmony_ci ++mmlineno; 778c2ecf20Sopenharmony_ci } 788c2ecf20Sopenharmony_ci\r ; 798c2ecf20Sopenharmony_ci<ARGLIST>{SPACE} ; 808c2ecf20Sopenharmony_ci<ARGLIST>\( { 818c2ecf20Sopenharmony_ci parren_count++; 828c2ecf20Sopenharmony_ci if (parren_count == 1) { 838c2ecf20Sopenharmony_ci string_buf_ptr = string_buf; 848c2ecf20Sopenharmony_ci return ('('); 858c2ecf20Sopenharmony_ci } 868c2ecf20Sopenharmony_ci *string_buf_ptr++ = '('; 878c2ecf20Sopenharmony_ci } 888c2ecf20Sopenharmony_ci<ARGLIST>\) { 898c2ecf20Sopenharmony_ci if (parren_count == 1) { 908c2ecf20Sopenharmony_ci if (string_buf_ptr != string_buf) { 918c2ecf20Sopenharmony_ci /* 928c2ecf20Sopenharmony_ci * Return an argument and 938c2ecf20Sopenharmony_ci * rescan this parren so we 948c2ecf20Sopenharmony_ci * can return it as well. 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci *string_buf_ptr = '\0'; 978c2ecf20Sopenharmony_ci mmlval.str = string_buf; 988c2ecf20Sopenharmony_ci string_buf_ptr = string_buf; 998c2ecf20Sopenharmony_ci unput(')'); 1008c2ecf20Sopenharmony_ci return T_ARG; 1018c2ecf20Sopenharmony_ci } 1028c2ecf20Sopenharmony_ci BEGIN INITIAL; 1038c2ecf20Sopenharmony_ci return (')'); 1048c2ecf20Sopenharmony_ci } 1058c2ecf20Sopenharmony_ci parren_count--; 1068c2ecf20Sopenharmony_ci *string_buf_ptr++ = ')'; 1078c2ecf20Sopenharmony_ci } 1088c2ecf20Sopenharmony_ci<ARGLIST>{MCARG} { 1098c2ecf20Sopenharmony_ci char *yptr; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci yptr = mmtext; 1128c2ecf20Sopenharmony_ci while (*yptr) 1138c2ecf20Sopenharmony_ci *string_buf_ptr++ = *yptr++; 1148c2ecf20Sopenharmony_ci } 1158c2ecf20Sopenharmony_ci<ARGLIST>\, { 1168c2ecf20Sopenharmony_ci if (string_buf_ptr != string_buf) { 1178c2ecf20Sopenharmony_ci /* 1188c2ecf20Sopenharmony_ci * Return an argument and 1198c2ecf20Sopenharmony_ci * rescan this comma so we 1208c2ecf20Sopenharmony_ci * can return it as well. 1218c2ecf20Sopenharmony_ci */ 1228c2ecf20Sopenharmony_ci *string_buf_ptr = '\0'; 1238c2ecf20Sopenharmony_ci mmlval.str = string_buf; 1248c2ecf20Sopenharmony_ci string_buf_ptr = string_buf; 1258c2ecf20Sopenharmony_ci unput(','); 1268c2ecf20Sopenharmony_ci return T_ARG; 1278c2ecf20Sopenharmony_ci } 1288c2ecf20Sopenharmony_ci return ','; 1298c2ecf20Sopenharmony_ci } 1308c2ecf20Sopenharmony_ci{WORD}[(] { 1318c2ecf20Sopenharmony_ci /* May be a symbol or a macro invocation. */ 1328c2ecf20Sopenharmony_ci mmlval.sym = symtable_get(mmtext); 1338c2ecf20Sopenharmony_ci if (mmlval.sym->type != MACRO) { 1348c2ecf20Sopenharmony_ci stop("Expecting Macro Name", 1358c2ecf20Sopenharmony_ci EX_DATAERR); 1368c2ecf20Sopenharmony_ci } 1378c2ecf20Sopenharmony_ci unput('('); 1388c2ecf20Sopenharmony_ci parren_count = 0; 1398c2ecf20Sopenharmony_ci BEGIN ARGLIST; 1408c2ecf20Sopenharmony_ci return T_SYMBOL; 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci. { 1438c2ecf20Sopenharmony_ci snprintf(buf, sizeof(buf), "Invalid character " 1448c2ecf20Sopenharmony_ci "'%c'", mmtext[0]); 1458c2ecf20Sopenharmony_ci stop(buf, EX_DATAERR); 1468c2ecf20Sopenharmony_ci } 1478c2ecf20Sopenharmony_ci%% 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ciint 1508c2ecf20Sopenharmony_cimmwrap() 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci stop("EOF encountered in macro call", EX_DATAERR); 1538c2ecf20Sopenharmony_ci} 154