4 * Copyright (c) 1997-1998 Markku Rossi.
6 * Author: Markku Rossi <mtr@iki.fi>
10 * This file is part of GNU enscript.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 59 Temple Place - Suite 330,
25 * Boston, MA 02111-1307, USA.
29 * $Id: lex.l,v 1.1.1.1 2003/03/05 07:25:52 mtr Exp $
35 static void eat_comment ();
36 static char *read_string ___P ((unsigned int *len_return));
37 static void read_regexp ___P ((Node *node));
40 real [+-]?[0-9]+\.[0-9]*|[+-]?\.[0-9]+
42 symbol [a-zA-Z_][a-zA-Z_0-9]*|\$.
46 "/*" { eat_comment (); }
50 \" { yylval.node = node_alloc (nSTRING);
51 yylval.node->u.str.data
52 = read_string (&yylval.node->u.str.len);
56 '[^\\]' { yylval.node = node_alloc (nINTEGER);
57 yylval.node->u.integer = yytext[1];
61 '\\.' { yylval.node = node_alloc (nINTEGER);
65 yylval.node->u.integer = '\n';
69 yylval.node->u.integer = '\t';
73 yylval.node->u.integer = '\v';
77 yylval.node->u.integer = '\b';
81 yylval.node->u.integer = '\r';
85 yylval.node->u.integer = '\f';
89 yylval.node->u.integer = '\a';
93 yylval.node->u.integer = yytext[2];
100 \/ { yylval.node = node_alloc (nREGEXP);
101 read_regexp (yylval.node);
105 "BEGIN" { return tBEGIN; }
106 "END" { return tEND; }
107 "div" { return tDIV; }
108 "else" { return tELSE; }
109 "extends" { return tEXTENDS; }
110 "for" { return tFOR; }
112 "local" { return tLOCAL; }
113 "namerules" { return tNAMERULES; }
114 "return" { return tRETURN; }
115 "start" { return tSTART; }
116 "startrules" { return tSTARTRULES; }
117 "state" { return tSTATE; }
118 "sub" { return tSUB; }
119 "while" { return tWHILE; }
125 "&&" { return tAND; }
127 "++" { return tPLUSPLUS; }
128 "--" { return tMINUSMINUS; }
129 "+=" { return tADDASSIGN; }
130 "-=" { return tSUBASSIGN; }
131 "*=" { return tMULASSIGN; }
132 "div=" { return tDIVASSIGN; }
134 {real} { yylval.node = node_alloc (nREAL);
135 yylval.node->u.real = atof (yytext);
138 {integer} { yylval.node = node_alloc (nINTEGER);
139 yylval.node->u.integer = atoi (yytext);
142 {symbol} { yylval.node = node_alloc (nSYMBOL);
143 yylval.node->u.sym = xstrdup (yytext);
147 . { return yytext[0]; }
156 while ((c = input ()) != EOF)
169 yyerror (_("error: EOF in comment"));
175 yyerror (_("error: EOF in comment"));
186 read_string (len_return)
187 unsigned int *len_return;
206 yyerror (_("error: EOF in string constant"));
256 for (i = 0; i < 3; i++)
259 if ('0' <= ch && ch <= '7')
260 val = val * 8 + ch - '0';
274 if (bufpos >= buflen)
277 buf = (char *) xrealloc (buf, buflen);
284 buf2 = (char *) xmalloc (bufpos + 1);
285 memcpy (buf2, buf, bufpos);
289 *len_return = bufpos;
313 yyerror (_("error: EOF in regular expression"));
362 for (i = 0; i < 3; i++)
365 if ('0' <= ch && ch <= '7')
366 val = val * 8 + ch - '0';
377 /* Pass it through. */
386 if (bufpos >= buflen)
389 buf = (char *) xrealloc (buf, buflen);
396 /* Possible options. */
404 /* Case-insensitive regular expression. */
405 node->u.re.flags |= fRE_CASE_INSENSITIVE;
409 /* Unknown option => this belongs to the next token. */
416 buf2 = (char *) xmalloc (bufpos + 1);
417 memcpy (buf2, buf, bufpos);
421 node->u.re.data = buf2;
422 node->u.re.len = bufpos;