150764Smarkm%{ 250764Smarkm/* 3233294Sstas * Copyright (c) 1998 - 2000 Kungliga Tekniska H��gskolan 4233294Sstas * (Royal Institute of Technology, Stockholm, Sweden). 5233294Sstas * All rights reserved. 650764Smarkm * 7233294Sstas * Redistribution and use in source and binary forms, with or without 8233294Sstas * modification, are permitted provided that the following conditions 9233294Sstas * are met: 1050764Smarkm * 11233294Sstas * 1. Redistributions of source code must retain the above copyright 12233294Sstas * notice, this list of conditions and the following disclaimer. 1350764Smarkm * 14233294Sstas * 2. Redistributions in binary form must reproduce the above copyright 15233294Sstas * notice, this list of conditions and the following disclaimer in the 16233294Sstas * documentation and/or other materials provided with the distribution. 1750764Smarkm * 18233294Sstas * 3. Neither the name of the Institute nor the names of its contributors 19233294Sstas * may be used to endorse or promote products derived from this software 20233294Sstas * without specific prior written permission. 2150764Smarkm * 22233294Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 23233294Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25233294Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 26233294Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30233294Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32233294Sstas * SUCH DAMAGE. 3350764Smarkm */ 3450764Smarkm 3550764Smarkm/* 3650764Smarkm * This is to handle the definition of this symbol in some AIX 3750764Smarkm * headers, which will conflict with the definition that lex will 3850764Smarkm * generate for it. It's only a problem for AIX lex. 3950764Smarkm */ 4050764Smarkm 4150764Smarkm#undef ECHO 4250764Smarkm 4350764Smarkm#include "compile_et.h" 4450764Smarkm#include "parse.h" 45127807Snectar#include "lex.h" 4650764Smarkm 4750764Smarkmstatic unsigned lineno = 1; 48127807Snectarstatic int getstring(void); 4950764Smarkm 50127807Snectar#define YY_NO_UNPUT 51127807Snectar 52127807Snectar#undef ECHO 53127807Snectar 5450764Smarkm%} 5550764Smarkm 56233294Sstas%option nounput 5750764Smarkm 5850764Smarkm%% 5950764Smarkmet { return ET; } 6050764Smarkmerror_table { return ET; } 6150764Smarkmec { return EC; } 6250764Smarkmerror_code { return EC; } 6350764Smarkmprefix { return PREFIX; } 6450764Smarkmindex { return INDEX; } 6550764Smarkmid { return ID; } 6650764Smarkmend { return END; } 6750764Smarkm[0-9]+ { yylval.number = atoi(yytext); return NUMBER; } 6850764Smarkm#[^\n]* ; 6950764Smarkm[ \t] ; 7050764Smarkm\n { lineno++; } 7150764Smarkm\" { return getstring(); } 7250764Smarkm[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return STRING; } 7350764Smarkm. { return *yytext; } 7450764Smarkm%% 7550764Smarkm 7650764Smarkm#ifndef yywrap /* XXX */ 7750764Smarkmint 78233294Sstasyywrap () 7950764Smarkm{ 8050764Smarkm return 1; 8150764Smarkm} 8250764Smarkm#endif 8350764Smarkm 84127807Snectarstatic int 8550764Smarkmgetstring(void) 8650764Smarkm{ 8750764Smarkm char x[128]; 8850764Smarkm int i = 0; 8950764Smarkm int c; 9050764Smarkm int quote = 0; 91178846Sdfr while(i < sizeof(x) - 1 && (c = input()) != EOF){ 9250764Smarkm if(quote) { 9350764Smarkm x[i++] = c; 9450764Smarkm quote = 0; 9550764Smarkm continue; 9650764Smarkm } 9750764Smarkm if(c == '\n'){ 98233294Sstas _lex_error_message("unterminated string"); 9950764Smarkm lineno++; 10050764Smarkm break; 10150764Smarkm } 10250764Smarkm if(c == '\\'){ 10350764Smarkm quote++; 10450764Smarkm continue; 10550764Smarkm } 10650764Smarkm if(c == '\"') 10750764Smarkm break; 10850764Smarkm x[i++] = c; 10950764Smarkm } 11050764Smarkm x[i] = '\0'; 11150764Smarkm yylval.string = strdup(x); 112178846Sdfr if (yylval.string == NULL) 113178846Sdfr err(1, "malloc"); 11450764Smarkm return STRING; 11550764Smarkm} 11650764Smarkm 11750764Smarkmvoid 118233294Sstas_lex_error_message (const char *format, ...) 11950764Smarkm{ 12050764Smarkm va_list args; 12150764Smarkm 12250764Smarkm va_start (args, format); 12350764Smarkm fprintf (stderr, "%s:%d:", filename, lineno); 12450764Smarkm vfprintf (stderr, format, args); 12550764Smarkm va_end (args); 12650764Smarkm numerror++; 12750764Smarkm} 128