15e9cd1aeSAssar Westerlund %{ 25e9cd1aeSAssar Westerlund /* 3*ae771770SStanislav Sedov * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan 45e9cd1aeSAssar Westerlund * (Royal Institute of Technology, Stockholm, Sweden). 55e9cd1aeSAssar Westerlund * All rights reserved. 65e9cd1aeSAssar Westerlund * 75e9cd1aeSAssar Westerlund * Redistribution and use in source and binary forms, with or without 85e9cd1aeSAssar Westerlund * modification, are permitted provided that the following conditions 95e9cd1aeSAssar Westerlund * are met: 105e9cd1aeSAssar Westerlund * 115e9cd1aeSAssar Westerlund * 1. Redistributions of source code must retain the above copyright 125e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer. 135e9cd1aeSAssar Westerlund * 145e9cd1aeSAssar Westerlund * 2. Redistributions in binary form must reproduce the above copyright 155e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer in the 165e9cd1aeSAssar Westerlund * documentation and/or other materials provided with the distribution. 175e9cd1aeSAssar Westerlund * 185e9cd1aeSAssar Westerlund * 3. Neither the name of the Institute nor the names of its contributors 195e9cd1aeSAssar Westerlund * may be used to endorse or promote products derived from this software 205e9cd1aeSAssar Westerlund * without specific prior written permission. 215e9cd1aeSAssar Westerlund * 225e9cd1aeSAssar Westerlund * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 235e9cd1aeSAssar Westerlund * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 245e9cd1aeSAssar Westerlund * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 255e9cd1aeSAssar Westerlund * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 265e9cd1aeSAssar Westerlund * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 275e9cd1aeSAssar Westerlund * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 285e9cd1aeSAssar Westerlund * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 295e9cd1aeSAssar Westerlund * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 305e9cd1aeSAssar Westerlund * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 315e9cd1aeSAssar Westerlund * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 325e9cd1aeSAssar Westerlund * SUCH DAMAGE. 335e9cd1aeSAssar Westerlund */ 345e9cd1aeSAssar Westerlund 355e9cd1aeSAssar Westerlund /* 365e9cd1aeSAssar Westerlund * This is to handle the definition of this symbol in some AIX 375e9cd1aeSAssar Westerlund * headers, which will conflict with the definition that lex will 385e9cd1aeSAssar Westerlund * generate for it. It's only a problem for AIX lex. 395e9cd1aeSAssar Westerlund */ 405e9cd1aeSAssar Westerlund 415e9cd1aeSAssar Westerlund #undef ECHO 425e9cd1aeSAssar Westerlund 435e9cd1aeSAssar Westerlund #include "compile_et.h" 445e9cd1aeSAssar Westerlund #include "parse.h" 455e9cd1aeSAssar Westerlund #include "lex.h" 465e9cd1aeSAssar Westerlund 475e9cd1aeSAssar Westerlund static unsigned lineno = 1; 485e9cd1aeSAssar Westerlund static int getstring(void); 495e9cd1aeSAssar Westerlund 505e9cd1aeSAssar Westerlund #define YY_NO_UNPUT 515e9cd1aeSAssar Westerlund 525e9cd1aeSAssar Westerlund #undef ECHO 535e9cd1aeSAssar Westerlund 545e9cd1aeSAssar Westerlund %} 555e9cd1aeSAssar Westerlund 56*ae771770SStanislav Sedov %option nounput 575e9cd1aeSAssar Westerlund 585e9cd1aeSAssar Westerlund %% 595e9cd1aeSAssar Westerlund et { return ET; } 605e9cd1aeSAssar Westerlund error_table { return ET; } 615e9cd1aeSAssar Westerlund ec { return EC; } 625e9cd1aeSAssar Westerlund error_code { return EC; } 635e9cd1aeSAssar Westerlund prefix { return PREFIX; } 645e9cd1aeSAssar Westerlund index { return INDEX; } 655e9cd1aeSAssar Westerlund id { return ID; } 665e9cd1aeSAssar Westerlund end { return END; } 675e9cd1aeSAssar Westerlund [0-9]+ { yylval.number = atoi(yytext); return NUMBER; } 685e9cd1aeSAssar Westerlund #[^\n]* ; 695e9cd1aeSAssar Westerlund [ \t] ; 705e9cd1aeSAssar Westerlund \n { lineno++; } 715e9cd1aeSAssar Westerlund \" { return getstring(); } 725e9cd1aeSAssar Westerlund [a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return STRING; } 735e9cd1aeSAssar Westerlund . { return *yytext; } 745e9cd1aeSAssar Westerlund %% 755e9cd1aeSAssar Westerlund 765e9cd1aeSAssar Westerlund #ifndef yywrap /* XXX */ 775e9cd1aeSAssar Westerlund int 785e9cd1aeSAssar Westerlund yywrap () 795e9cd1aeSAssar Westerlund { 805e9cd1aeSAssar Westerlund return 1; 815e9cd1aeSAssar Westerlund } 825e9cd1aeSAssar Westerlund #endif 835e9cd1aeSAssar Westerlund 845e9cd1aeSAssar Westerlund static int 855e9cd1aeSAssar Westerlund getstring(void) 865e9cd1aeSAssar Westerlund { 875e9cd1aeSAssar Westerlund char x[128]; 885e9cd1aeSAssar Westerlund int i = 0; 895e9cd1aeSAssar Westerlund int c; 905e9cd1aeSAssar Westerlund int quote = 0; 91c19800e8SDoug Rabson while(i < sizeof(x) - 1 && (c = input()) != EOF){ 925e9cd1aeSAssar Westerlund if(quote) { 935e9cd1aeSAssar Westerlund x[i++] = c; 945e9cd1aeSAssar Westerlund quote = 0; 955e9cd1aeSAssar Westerlund continue; 965e9cd1aeSAssar Westerlund } 975e9cd1aeSAssar Westerlund if(c == '\n'){ 98*ae771770SStanislav Sedov _lex_error_message("unterminated string"); 995e9cd1aeSAssar Westerlund lineno++; 1005e9cd1aeSAssar Westerlund break; 1015e9cd1aeSAssar Westerlund } 1025e9cd1aeSAssar Westerlund if(c == '\\'){ 1035e9cd1aeSAssar Westerlund quote++; 1045e9cd1aeSAssar Westerlund continue; 1055e9cd1aeSAssar Westerlund } 1065e9cd1aeSAssar Westerlund if(c == '\"') 1075e9cd1aeSAssar Westerlund break; 1085e9cd1aeSAssar Westerlund x[i++] = c; 1095e9cd1aeSAssar Westerlund } 1105e9cd1aeSAssar Westerlund x[i] = '\0'; 1115e9cd1aeSAssar Westerlund yylval.string = strdup(x); 112c19800e8SDoug Rabson if (yylval.string == NULL) 113c19800e8SDoug Rabson err(1, "malloc"); 1145e9cd1aeSAssar Westerlund return STRING; 1155e9cd1aeSAssar Westerlund } 1165e9cd1aeSAssar Westerlund 1175e9cd1aeSAssar Westerlund void 118*ae771770SStanislav Sedov _lex_error_message (const char *format, ...) 1195e9cd1aeSAssar Westerlund { 1205e9cd1aeSAssar Westerlund va_list args; 1215e9cd1aeSAssar Westerlund 1225e9cd1aeSAssar Westerlund va_start (args, format); 1235e9cd1aeSAssar Westerlund fprintf (stderr, "%s:%d:", filename, lineno); 1245e9cd1aeSAssar Westerlund vfprintf (stderr, format, args); 1255e9cd1aeSAssar Westerlund va_end (args); 1265e9cd1aeSAssar Westerlund numerror++; 1275e9cd1aeSAssar Westerlund } 128