1 /* Lexical analyzer for calc program.
3 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 This program is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 3 of the License, or (at your option) any later
12 This program is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14 PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with
17 this program. If not, see http://www.gnu.org/licenses/. */
21 #include "calc-common.h"
25 /* Let GNU flex use readline. See the calcread.c redefined input() for a
26 way that might work for a standard lex too. */
27 #define YY_INPUT(buf,result,max_size) \
28 result = calc_input (buf, max_size);
32 /* Non-zero when reading the second or subsequent line of an expression,
33 used to give a different prompt when using readline. */
34 int calc_more_input = 0;
37 const struct calc_keywords_t calc_keywords[] = {
40 { "decimal", DECIMAL },
48 { "nextprime", NEXTPRIME },
59 [ \t\f] { /* white space is skipped */ }
61 [;\n] { /* semicolon or newline separates statements */
64 \\\n { /* escaped newlines are skipped */ }
68 /* comment through to escaped newline is skipped */ }
69 #[^\n]*\n { /* comment through to newline is a separator */
72 #[^\n]* { /* comment through to EOF skipped */ }
75 [-+*/%()<>^!=,] { return yytext[0]; }
80 "<<" { return LSHIFT; }
81 ">>" { return RSHIFT; }
89 [a-zA-Z][a-zA-Z0-9]* {
92 for (i = 0; calc_keywords[i].name != NULL; i++)
93 if (strcmp (yytext, calc_keywords[i].name) == 0)
94 return calc_keywords[i].value;
96 if (yytext[0] >= 'a' && yytext[0] <= 'z' && yytext[1] == '\0')
98 yylval.var = yytext[0] - 'a';