3 $Id: scanner.l 23128 2016-07-01 11:58:21Z coelho $
5 Copyright 1989-2016 MINES ParisTech
7 This file is part of PIPS.
9 PIPS is free software: you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
14 PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with PIPS. If not, see <http://www.gnu.org/licenses/>.
27 #include "pips_config.h"
30 /* UICON and ICON must be distinguished from RCON and DCON:
33 Should not be parsed as real constants!
38 /* flex incompatible way of playing with input characters:-)
41 #define YY_INPUT(buf,result,max_size) \
42 { int c = PipsGetc(yyin); result = (c == EOF)? YY_NULL: (buf[0] = c, 1);}
44 #else /* we're not using flex... let us assume some very peculiar lex... */
46 /* the portability of the following macro makes many (:-) assumptions
47 * about lex internals hence should not be very portable...
48 * POSIX states that input cannot be redefined.
49 * the only possible posix implementation would be to refilter the
50 * file through PipsGetc and then to use a standard lex/yacc.
53 #define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):PipsGetc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
55 #endif /* FLEX_SCANNER */
61 #include "parser_private.h"
68 /* yacc generated header file
72 /* stdlib defines abs on solaris 2 */
77 static int line = 1; /* position in pseudo-file... */
87 MANT (({DIG}+\.{DIG}*)|({DIG}*\.{DIG}+))
90 RCON (({MANT}|{UICON}){REXP}?)
91 DCON (({MANT}|{UICON}){DEXP}?)
93 %start TYPEDECLARATION
97 pips_debug(9, "TK_AND\n");
101 pips_debug(9, "TK_INOUT\n");
105 pips_debug(9, "TK_IN\n");
109 pips_debug(9, "TK_OUT\n");
113 pips_debug(9, "TK_EQ\n");
117 pips_debug(9, "TK_EQV\n");
121 pips_debug(9, "TK_GE\n");
125 pips_debug(9, "TK_GT\n");
129 pips_debug(9, "TK_LE\n");
133 pips_debug(9, "TK_LT\n");
137 pips_debug(9, "TK_NE\n");
141 pips_debug(9, "TK_NEQV\n");
145 pips_debug(9, "TK_NOT\n");
149 pips_debug(9, "TK_OR\n");
153 pips_debug(9, "TK_TRUE\n");
157 pips_debug(9, "TK_FALSE\n");
162 int tv = IsCapKeyword(yytext);
163 if (tv == TK_FORMAT) {
164 char * s = FormatValue;
165 while ((*s++ = input()) != '\n') ;
176 BEGIN TYPEDECLARATION;
179 pips_debug(9, "TK_KEYWORD %s %u %d\n",
180 yytext, (unsigned int) yyleng, tv);
184 {ULET}+({DIG}|{ULET})* {
185 pips_debug(9, "TK_NAME %s %u\n", yytext, (unsigned int) yyleng);
186 syn_lval.string = strdup(yytext);
192 pips_debug(9, "TK_ICON %s %u\n", yytext, (unsigned int) yyleng);
193 syn_lval.string = strdup(yytext);
198 pips_debug(9, "TK_RCON %s %u\n", yytext, (unsigned int) yyleng);
199 syn_lval.string = strdup(yytext);
204 pips_debug(9, "TK_DCON %s %u\n", yytext, (unsigned int) yyleng);
205 syn_lval.string = strdup(yytext);
209 \'([^\']|(\'\')|(\\\'))*\' {
210 pips_debug(9, "TK_SCON %s %u\n", yytext, (unsigned int) yyleng);
211 syn_lval.string = strdup(yytext);
215 \"([^\"]|(\"\")|(\\\"))*\" {
216 pips_debug(9, "TK_SCON %s %u\n", yytext, (unsigned int) yyleng);
217 syn_lval.string = strdup(yytext);
222 pips_debug(9, "TK_MINUS\n");
226 pips_debug(9, "TK_PLUS\n");
230 pips_debug(9, "TK_SLASH\n");
234 pips_debug(9, "TK_POWER\n");
238 pips_debug(9, "TK_STAR\n");
242 pips_debug(9, "TK_LPAR\n");
246 pips_debug(9, "TK_RPAR\n");
250 pips_debug(9, "TK_COMMA\n");
254 pips_debug(9, "TK_COLON\n");
258 pips_debug(9, "TK_EQUALS\n");
262 pips_debug(9, "TK_CURRENCY\n");
266 pips_debug(9, "TK_CONCAT\n");
271 pips_debug(9, "TK_EOS\n");
275 /* Ignore carriage return from VMS and Microsoft and Apple?
276 * Not here! It must have been done earlier in the processing.
278 pips_user_warning("illegal character \"%c\" (hexadecimal %#04x)\n",
279 yytext[0], yytext[0]);
280 ParserError("Lexical Analysis",
281 "Check standard Fortran character set.\n");
285 void syn_error(const char * msg)
289 /* Do not use pips_user_warning() to avoid portability issues */
291 user_warning("syn_error", "Syntax error - %s line %d near \"%s\"\n",
294 /* what does it mean? */
295 user_warning("syn_error", "Non analyzed source text stored in logfile\n");
297 while ((c = getc(yyin)) != EOF)
300 /* pas de recouvrement d'erreurs */
301 ParserError("syn_error", "Syntax error\n");
304 void syn_reset_lex(void)
310 /* reset lex... Might be better to read the whole file?
313 # define MMNEWLINE 10
314 syn_previous = MMNEWLINE;