lex.l revision 225736
183221Smarcel%{ 283221Smarcel/* 383221Smarcel * Copyright (c) 1998 - 2000 Kungliga Tekniska H�gskolan 483221Smarcel * (Royal Institute of Technology, Stockholm, Sweden). 583221Smarcel * All rights reserved. 683221Smarcel * 783221Smarcel * Redistribution and use in source and binary forms, with or without 883221Smarcel * modification, are permitted provided that the following conditions 983221Smarcel * are met: 1083221Smarcel * 1183221Smarcel * 1. Redistributions of source code must retain the above copyright 1283221Smarcel * notice, this list of conditions and the following disclaimer. 1383221Smarcel * 1483221Smarcel * 2. Redistributions in binary form must reproduce the above copyright 1583221Smarcel * notice, this list of conditions and the following disclaimer in the 1683221Smarcel * documentation and/or other materials provided with the distribution. 1783221Smarcel * 1883221Smarcel * 3. Neither the name of the Institute nor the names of its contributors 1983221Smarcel * may be used to endorse or promote products derived from this software 2083221Smarcel * without specific prior written permission. 2183221Smarcel * 2283221Smarcel * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 2383221Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2483221Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2583221Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 2683221Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2783221Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2883221Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2983221Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3083221Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3183221Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3283221Smarcel * SUCH DAMAGE. 3383221Smarcel */ 3483221Smarcel 3583221Smarcel/* 3683221Smarcel * This is to handle the definition of this symbol in some AIX 3783221Smarcel * headers, which will conflict with the definition that lex will 3883221Smarcel * generate for it. It's only a problem for AIX lex. 3983221Smarcel */ 4083221Smarcel 4183221Smarcel#undef ECHO 4283221Smarcel 4383221Smarcel#include "compile_et.h" 4483221Smarcel#include "parse.h" 4583221Smarcel#include "lex.h" 4683221Smarcel 4783221SmarcelRCSID("$Id: lex.l 15143 2005-05-16 08:52:54Z lha $"); 4883221Smarcel 4983221Smarcelstatic unsigned lineno = 1; 5083221Smarcelstatic int getstring(void); 5183221Smarcel 5283221Smarcel#define YY_NO_UNPUT 5383221Smarcel 5483221Smarcel#undef ECHO 5583221Smarcel 5683221Smarcel%} 5783221Smarcel 5883221Smarcel 5983221Smarcel%% 6083221Smarcelet { return ET; } 6183221Smarcelerror_table { return ET; } 6283221Smarcelec { return EC; } 6383221Smarcelerror_code { return EC; } 6483221Smarcelprefix { return PREFIX; } 6583221Smarcelindex { return INDEX; } 6683221Smarcelid { return ID; } 6783221Smarcelend { return END; } 6883221Smarcel[0-9]+ { yylval.number = atoi(yytext); return NUMBER; } 6983221Smarcel#[^\n]* ; 7083221Smarcel[ \t] ; 7183221Smarcel\n { lineno++; } 7283221Smarcel\" { return getstring(); } 7383221Smarcel[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return STRING; } 7483221Smarcel. { return *yytext; } 7583221Smarcel%% 7683221Smarcel 7783221Smarcel#ifndef yywrap /* XXX */ 7883366Sjulianint 7983221Smarcelyywrap () 8083221Smarcel{ 8183221Smarcel return 1; 8283221Smarcel} 8383221Smarcel#endif 8483221Smarcel 8583221Smarcelstatic int 8683221Smarcelgetstring(void) 8783221Smarcel{ 8883221Smarcel char x[128]; 8983221Smarcel int i = 0; 9083221Smarcel int c; 9183221Smarcel int quote = 0; 9283221Smarcel while(i < sizeof(x) - 1 && (c = input()) != EOF){ 9383221Smarcel if(quote) { 9483221Smarcel x[i++] = c; 9583221Smarcel quote = 0; 9683221Smarcel continue; 9783221Smarcel } 9883221Smarcel if(c == '\n'){ 9983221Smarcel error_message("unterminated string"); 10083221Smarcel lineno++; 10183221Smarcel break; 10283221Smarcel } 10383221Smarcel if(c == '\\'){ 10483221Smarcel quote++; 10583221Smarcel continue; 10683221Smarcel } 10783221Smarcel if(c == '\"') 10883221Smarcel break; 10983221Smarcel x[i++] = c; 11083221Smarcel } 11183221Smarcel x[i] = '\0'; 11283221Smarcel yylval.string = strdup(x); 11383221Smarcel if (yylval.string == NULL) 11483221Smarcel err(1, "malloc"); 11583221Smarcel return STRING; 11683221Smarcel} 11783221Smarcel 11883221Smarcelvoid 11983221Smarcelerror_message (const char *format, ...) 12083221Smarcel{ 121 va_list args; 122 123 va_start (args, format); 124 fprintf (stderr, "%s:%d:", filename, lineno); 125 vfprintf (stderr, format, args); 126 va_end (args); 127 numerror++; 128} 129