1218822Sdim%{ 238889Sjdp/* 3218822Sdim * Copyright (c) 1998 - 2000 Kungliga Tekniska H��gskolan 4218822Sdim * (Royal Institute of Technology, Stockholm, Sweden). 538889Sjdp * All rights reserved. 6218822Sdim * 7218822Sdim * Redistribution and use in source and binary forms, with or without 860484Sobrien * modification, are permitted provided that the following conditions 9218822Sdim * are met: 10218822Sdim * 11218822Sdim * 1. Redistributions of source code must retain the above copyright 1238889Sjdp * notice, this list of conditions and the following disclaimer. 1338889Sjdp * 14218822Sdim * 2. Redistributions in binary form must reproduce the above copyright 15218822Sdim * notice, this list of conditions and the following disclaimer in the 1638889Sjdp * documentation and/or other materials provided with the distribution. 17218822Sdim * 18218822Sdim * 3. Neither the name of the Institute nor the names of its contributors 1938889Sjdp * may be used to endorse or promote products derived from this software 20218822Sdim * without specific prior written permission. 21218822Sdim * 2260484Sobrien * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 23218822Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24218822Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2538889Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 26218822Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27218822Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2860484Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29218822Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30218822Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3160484Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32218822Sdim * SUCH DAMAGE. 33218822Sdim */ 3438889Sjdp 35218822Sdim/* 36218822Sdim * This is to handle the definition of this symbol in some AIX 37218822Sdim * headers, which will conflict with the definition that lex will 3860484Sobrien * generate for it. It's only a problem for AIX lex. 39218822Sdim */ 40218822Sdim 4138889Sjdp#undef ECHO 42218822Sdim 43218822Sdim#include "compile_et.h" 44218822Sdim#include "parse.h" 4538889Sjdp#include "lex.h" 46218822Sdim 47218822Sdimstatic unsigned lineno = 1; 4838889Sjdpstatic int getstring(void); 49218822Sdim 50218822Sdim#define YY_NO_UNPUT 51218822Sdim 5238889Sjdp#undef ECHO 53218822Sdim 54218822Sdim%} 5538889Sjdp 56218822Sdim%option nounput 57218822Sdim 5838889Sjdp%% 59218822Sdimet { return ET; } 60218822Sdimerror_table { return ET; } 6138889Sjdpec { return EC; } 62218822Sdimerror_code { return EC; } 63218822Sdimprefix { return PREFIX; } 6438889Sjdpindex { return INDEX; } 65218822Sdimid { return ID; } 6660484Sobrienend { return END; } 6738889Sjdp[0-9]+ { yylval.number = atoi(yytext); return NUMBER; } 68218822Sdim#[^\n]* ; 6960484Sobrien[ \t] ; 7038889Sjdp\n { lineno++; } 71218822Sdim\" { return getstring(); } 72218822Sdim[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return STRING; } 7338889Sjdp. { return *yytext; } 74218822Sdim%% 75218822Sdim 7638889Sjdp#ifndef yywrap /* XXX */ 77218822Sdimint 78218822Sdimyywrap () 7938889Sjdp{ 80218822Sdim return 1; 81218822Sdim} 8238889Sjdp#endif 83218822Sdim 8438889Sjdpstatic int 8538889Sjdpgetstring(void) 86218822Sdim{ 87218822Sdim char x[128]; 8838889Sjdp int i = 0; 89218822Sdim int c; 9038889Sjdp int quote = 0; 9138889Sjdp while(i < sizeof(x) - 1 && (c = input()) != EOF){ 92218822Sdim if(quote) { 9338889Sjdp x[i++] = c; 9438889Sjdp quote = 0; 95218822Sdim continue; 96218822Sdim } 9760484Sobrien if(c == '\n'){ 98218822Sdim _lex_error_message("unterminated string"); 9938889Sjdp lineno++; 10060484Sobrien break; 101218822Sdim } 102218822Sdim if(c == '\\'){ 10360484Sobrien quote++; 104218822Sdim continue; 105218822Sdim } 106218822Sdim if(c == '\"') 10760484Sobrien break; 108218822Sdim x[i++] = c; 109218822Sdim } 11060484Sobrien x[i] = '\0'; 111218822Sdim yylval.string = strdup(x); 112218822Sdim if (yylval.string == NULL) 11377298Sobrien err(1, "malloc"); 114218822Sdim return STRING; 115130561Sobrien} 116130561Sobrien 117218822Sdimvoid 118130561Sobrien_lex_error_message (const char *format, ...) 119130561Sobrien{ 120218822Sdim va_list args; 121130561Sobrien 122130561Sobrien va_start (args, format); 123218822Sdim fprintf (stderr, "%s:%d:", filename, lineno); 124218822Sdim vfprintf (stderr, format, args); 12578828Sobrien va_end (args); 126218822Sdim numerror++; 127218822Sdim} 12860484Sobrien