172445Sassar%{ 272445Sassar/* 3233294Sstas * Copyright (c) 1998 - 2000 Kungliga Tekniska H��gskolan 4233294Sstas * (Royal Institute of Technology, Stockholm, Sweden). 5233294Sstas * All rights reserved. 672445Sassar * 7233294Sstas * Redistribution and use in source and binary forms, with or without 8233294Sstas * modification, are permitted provided that the following conditions 9233294Sstas * are met: 1072445Sassar * 11233294Sstas * 1. Redistributions of source code must retain the above copyright 12233294Sstas * notice, this list of conditions and the following disclaimer. 1372445Sassar * 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. 1772445Sassar * 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. 2172445Sassar * 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. 3372445Sassar */ 3472445Sassar 3572445Sassar/* 3672445Sassar * This is to handle the definition of this symbol in some AIX 3772445Sassar * headers, which will conflict with the definition that lex will 3872445Sassar * generate for it. It's only a problem for AIX lex. 3972445Sassar */ 4072445Sassar 4172445Sassar#undef ECHO 4272445Sassar 4372445Sassar#include "compile_et.h" 4472445Sassar#include "parse.h" 4572445Sassar#include "lex.h" 4672445Sassar 4772445Sassarstatic unsigned lineno = 1; 4872445Sassarstatic int getstring(void); 4972445Sassar 5072445Sassar#define YY_NO_UNPUT 5172445Sassar 5272445Sassar#undef ECHO 5372445Sassar 5472445Sassar%} 5572445Sassar 56233294Sstas%option nounput 5772445Sassar 5872445Sassar%% 5972445Sassaret { return ET; } 6072445Sassarerror_table { return ET; } 6172445Sassarec { return EC; } 6272445Sassarerror_code { return EC; } 6372445Sassarprefix { return PREFIX; } 6472445Sassarindex { return INDEX; } 6572445Sassarid { return ID; } 6672445Sassarend { return END; } 6772445Sassar[0-9]+ { yylval.number = atoi(yytext); return NUMBER; } 6872445Sassar#[^\n]* ; 6972445Sassar[ \t] ; 7072445Sassar\n { lineno++; } 7172445Sassar\" { return getstring(); } 7272445Sassar[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return STRING; } 7372445Sassar. { return *yytext; } 7472445Sassar%% 7572445Sassar 7672445Sassar#ifndef yywrap /* XXX */ 7772445Sassarint 78233294Sstasyywrap () 7972445Sassar{ 8072445Sassar return 1; 8172445Sassar} 8272445Sassar#endif 8372445Sassar 8472445Sassarstatic int 8572445Sassargetstring(void) 8672445Sassar{ 8772445Sassar char x[128]; 8872445Sassar int i = 0; 8972445Sassar int c; 9072445Sassar int quote = 0; 91178825Sdfr while(i < sizeof(x) - 1 && (c = input()) != EOF){ 9272445Sassar if(quote) { 9372445Sassar x[i++] = c; 9472445Sassar quote = 0; 9572445Sassar continue; 9672445Sassar } 9772445Sassar if(c == '\n'){ 98233294Sstas _lex_error_message("unterminated string"); 9972445Sassar lineno++; 10072445Sassar break; 10172445Sassar } 10272445Sassar if(c == '\\'){ 10372445Sassar quote++; 10472445Sassar continue; 10572445Sassar } 10672445Sassar if(c == '\"') 10772445Sassar break; 10872445Sassar x[i++] = c; 10972445Sassar } 11072445Sassar x[i] = '\0'; 11172445Sassar yylval.string = strdup(x); 112178825Sdfr if (yylval.string == NULL) 113178825Sdfr err(1, "malloc"); 11472445Sassar return STRING; 11572445Sassar} 11672445Sassar 11772445Sassarvoid 118233294Sstas_lex_error_message (const char *format, ...) 11972445Sassar{ 12072445Sassar va_list args; 12172445Sassar 12272445Sassar va_start (args, format); 12372445Sassar fprintf (stderr, "%s:%d:", filename, lineno); 12472445Sassar vfprintf (stderr, format, args); 12572445Sassar va_end (args); 12672445Sassar numerror++; 12772445Sassar} 128