1 /** @file input_lexer.ll
3 * Lexical analyzer definition for reading expressions.
4 * This file must be processed with flex. */
7 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include "input_lexer.h"
42 #ifndef NO_NAMESPACE_GINAC
43 using namespace GiNaC;
45 #endif // ndef NO_NAMESPACE_GINAC
47 #include "input_parser.h"
49 #ifndef NO_NAMESPACE_GINAC
51 #endif // ndef NO_NAMESPACE_GINAC
53 // Table of all used symbols
54 typedef map<string, ex> sym_tab;
58 static int lexer_input(char *buf, int max_size);
59 #define YY_INPUT(buf, result, max_size) (result = lexer_input(buf, max_size))
62 /* The code output by flex doesn't work well with namespaces, so we're doing it this way */
63 %option prefix="ginac_yy"
77 [ \t]+ /* skip whitespace */
80 Pi yylval = Pi; return T_LITERAL;
81 gamma yylval = gamma; return T_LITERAL;
82 Catalan yylval = Catalan; return T_LITERAL;
83 FAIL yylval = *new fail(); return T_LITERAL;
84 I yylval = I; return T_NUMBER;
85 Digits yylval = (long)Digits; return T_DIGITS;
91 ">=" return T_GREATEREQ;
93 /* matrix delimiters */
94 \[\[ return T_MATRIX_BEGIN;
95 \]\] return T_MATRIX_END;
101 {D}+{E} yylval = numeric(yytext); return T_NUMBER;
105 if (syms.find(yytext) == syms.end())
106 syms[yytext] = *(new symbol(yytext));
107 yylval = syms[yytext];
111 /* everything else */
121 // The string from which we will read
122 static string lexer_string;
124 // The current position within the string
125 static int curr_pos = 0;
127 // Input function that reads from string
128 static int lexer_input(char *buf, int max_size)
130 int actual = lexer_string.length() - curr_pos;
131 if (actual > max_size)
135 lexer_string.copy(buf, actual, curr_pos);
140 // EOF encountered, terminate the scanner
146 #ifndef NO_NAMESPACE_GINAC
148 #endif // ndef NO_NAMESPACE_GINAC
150 // Set the input string
151 void set_lexer_string(const string &s)
157 // Set the list of predefined symbols
158 void set_lexer_symbols(ex l)
161 if (!is_ex_exactly_of_type(l, lst))
163 for (int i=0; i<l.nops(); i++) {
164 if (is_ex_exactly_of_type(l.op(i), symbol))
165 syms[ex_to_symbol(l.op(i)).getname()] = l.op(i);
169 #ifndef NO_NAMESPACE_GINAC
171 #endif // ndef NO_NAMESPACE_GINAC