| 1 |
/* otp-lexer.l: Lexical analysis for OTP files |
| 2 |
|
| 3 |
This file is part of Omega, |
| 4 |
which is based on the web2c distribution of TeX, |
| 5 |
|
| 6 |
Copyright (c) 1994--2001 John Plaice and Yannis Haralambous |
| 7 |
Copyright (c) 2002 Behdad Esfahbod |
| 8 |
Copyright (C) 2002, 2005, 2006 Roozbeh Pournader |
| 9 |
|
| 10 |
Omega is free software; you can redistribute it and/or modify |
| 11 |
it under the terms of the GNU General Public License as published by |
| 12 |
the Free Software Foundation; either version 2 of the License, or |
| 13 |
(at your option) any later version. |
| 14 |
|
| 15 |
Omega is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with Omega; if not, write to the Free Software Foundation, Inc., |
| 22 |
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| 23 |
|
| 24 |
*/ |
| 25 |
|
| 26 |
%option never-interactive |
| 27 |
|
| 28 |
%top{ |
| 29 |
#include "routines.h" |
| 30 |
#include "yystype.h" |
| 31 |
#include "otp-parser.h" |
| 32 |
} |
| 33 |
|
| 34 |
%{ |
| 35 |
#define YY_NO_UNPUT |
| 36 |
#define OTP_MAXCODE 0xFFFF |
| 37 |
int line_number = 1; |
| 38 |
extern YYSTYPE yylval; |
| 39 |
%} |
| 40 |
|
| 41 |
|
| 42 |
hexnumber @\"[a-fA-F0-9]+ |
| 43 |
octnumber @'[0-7]+ |
| 44 |
decnumber [0-9]+ |
| 45 |
id ([a-zA-Z][_a-zA-Z0-9]*) |
| 46 |
string \"([^\"]|\"\")*\" |
| 47 |
|
| 48 |
%% |
| 49 |
[ \t] {} |
| 50 |
"%".*\n { line_number++;} |
| 51 |
\r\n|\n|\r { line_number++;} |
| 52 |
{hexnumber} { |
| 53 |
int i, j; |
| 54 |
yylval.yint=0; |
| 55 |
for (i=2; i<yyleng; i++) { |
| 56 |
j = yytext[i]; |
| 57 |
if ((j>='0')&&(j<='9')) { |
| 58 |
yylval.yint = (yylval.yint*16)+(j-'0'); |
| 59 |
} else if ((j>='a')&&(j<='f')) { |
| 60 |
yylval.yint = (yylval.yint*16)+(j-'a'+10); |
| 61 |
} else { /* ((j>='A') && (j>='F')) */ |
| 62 |
yylval.yint = (yylval.yint*16)+(j-'A'+10); |
| 63 |
} |
| 64 |
if (yylval.yint>OTP_MAXCODE) { |
| 65 |
fprintf(stderr, "line %d: value too large (%x)\n", |
| 66 |
line_number, yylval.yint); |
| 67 |
exit(1); |
| 68 |
} |
| 69 |
} |
| 70 |
return(NUMBER); |
| 71 |
} |
| 72 |
{octnumber} { |
| 73 |
int i, j; |
| 74 |
yylval.yint=0; |
| 75 |
for (i=2; i<yyleng; i++) { |
| 76 |
j = yytext[i]; |
| 77 |
yylval.yint = (yylval.yint*8)+(j-'0'); |
| 78 |
if (yylval.yint>OTP_MAXCODE) { |
| 79 |
fprintf(stderr, "line %d: value too large (%o)\n", |
| 80 |
line_number, yylval.yint); |
| 81 |
exit(1); |
| 82 |
} |
| 83 |
} |
| 84 |
return(NUMBER); |
| 85 |
} |
| 86 |
{decnumber} { |
| 87 |
int i, j; |
| 88 |
yylval.yint=0; |
| 89 |
for (i=0; i<yyleng; i++) { |
| 90 |
j = yytext[i]; |
| 91 |
yylval.yint = (yylval.yint*10)+(j-'0'); |
| 92 |
if (yylval.yint>OTP_MAXCODE) { |
| 93 |
fprintf(stderr, "line %d: value too large (%d)\n", |
| 94 |
line_number, yylval.yint); |
| 95 |
exit(1); |
| 96 |
} |
| 97 |
} |
| 98 |
return(NUMBER); |
| 99 |
} |
| 100 |
"`"[\x20-\x7e]"'" { |
| 101 |
yylval.yint=yytext[1]; |
| 102 |
return(NUMBER); |
| 103 |
} |
| 104 |
{id} { yylval.ystring=xstrdup(yytext); return(ID); } |
| 105 |
{string} { |
| 106 |
int i, j, last; |
| 107 |
char *newtext; |
| 108 |
last=yyleng-2; |
| 109 |
i=0; |
| 110 |
j=1; |
| 111 |
newtext=yylval.ystring=xstrdup(yytext); |
| 112 |
while (j<=last) { |
| 113 |
newtext[i]=yytext[j]; |
| 114 |
if ((yytext[j]=='"') && (yytext[j+1]=='"')) j=j+2; |
| 115 |
else j++; |
| 116 |
i++; |
| 117 |
} |
| 118 |
newtext[i]='\0'; |
| 119 |
return(STRING); |
| 120 |
} |
| 121 |
=> return(RIGHTARROW); |
| 122 |
"<"= return(LEFTARROW); |
| 123 |
input: return(MYINPUT); |
| 124 |
output: return(OUTPUT); |
| 125 |
aliases: return(ALIASES); |
| 126 |
states: return(STATES); |
| 127 |
tables: return(TABLES); |
| 128 |
expressions: return(EXPRESSIONS); |
| 129 |
push: return(PUSH); |
| 130 |
pop: return(POP); |
| 131 |
div: return(DIV); |
| 132 |
mod: return(MOD); |
| 133 |
beg: return(BEG); |
| 134 |
end: return(END); |
| 135 |
. return(yytext[0]); |
| 136 |
|
| 137 |
%% |
| 138 |
|