2 /*--------------------------------------------------------------------+
4 |--------------------------------------------------------------------|
6 |--------------------------------------------------------------------|
7 | First version: 03/04/2012 |
8 +--------------------------------------------------------------------+
10 +--------------------------------------------------------------------------+
11 | / __)( ) /__\ ( \/ ) |
12 | ( (__ )(__ /(__)\ \ / Chunky Loop Alteration wizardrY |
13 | \___)(____)(__)(__)(__) |
14 +--------------------------------------------------------------------------+
15 | Copyright (C) 2012 University of Paris-Sud |
17 | This library is free software; you can redistribute it and/or modify it |
18 | under the terms of the GNU Lesser General Public License as published by |
19 | the Free Software Foundation; either version 2.1 of the License, or |
20 | (at your option) any later version. |
22 | This library is distributed in the hope that it will be useful but |
23 | WITHOUT ANY WARRANTY; without even the implied warranty of |
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
25 | General Public License for more details. |
27 | You should have received a copy of the GNU Lesser General Public License |
28 | along with this software; if not, write to the Free Software Foundation, |
29 | Inc., 51 Franklin Street, Fifth Floor, |
30 | Boston, MA 02110-1301 USA |
32 | Clay, the Chunky Loop Alteration wizardrY |
33 | Written by Joel Poudroux, joel.poudroux@u-psud.fr |
34 +--------------------------------------------------------------------------*/
40 #include <clay/array.h>
41 #include <clay/list.h>
42 #include <clay/macros.h>
44 void clay_scanner_free();
45 void clay_scanner_initialize();
47 extern int is_in_a_list;
52 //extern YYLTYPE clay_yylloc;
53 //extern YYSTYPE clay_yylval;;
59 #define YY_USER_ACTION yylloc.first_line = yylloc.last_line = yylineno; \
60 yylloc.first_column = yycolumn; yylloc.last_column = yycolumn + yyleng - 1; \
62 yylval.str = strdup(yytext);
64 //#define YY_USER_ACTION clay_yylloc.first_line = clay_yylloc.last_line = clay_yylineno;
66 //%option outfile="scanner.c" header-file="scanner.h"
70 %option prefix="clay_yy"
74 SEPARATOR ([ \t]|\xc2\xa0)*
78 {SEPARATOR}#(.|{SEPARATOR})*\n { return COMMENT; }
81 clay_yylval.ival = atoi(clay_yytext);
95 [a-zA-Z_][a-zA-Z0-9_]*{SEPARATOR}\({SEPARATOR}\) {
97 clay_yytext[strlen(clay_yytext)-1] = '\0';
98 char *tmp = trim(clay_yytext);
100 tmp[strlen(tmp)-1] = '\0';
101 clay_yylval.sval = strdup(trim(tmp));
102 return IDENT_FUNCTION_NO_ARGS;
105 [a-zA-Z_][a-zA-Z0-9_]*{SEPARATOR}\( {
107 clay_yytext[strlen(clay_yytext)-1] = '\0';
108 clay_yylval.sval = strdup(trim(clay_yytext));
109 return IDENT_FUNCTION;
112 [a-zA-Z_][a-zA-Z0-9_]* {
113 clay_yylval.sval = strdup(clay_yytext);
120 . { return clay_yytext[0]; }
126 * clay_scanner_free function:
127 * this function frees the memory allocated for the scanner. It frees
128 * flex's buffer (it supposes there is only one buffer) since flex does
129 * never free it itself.
130 * WARNING: this is probably *not* portable...
132 void clay_scanner_free() {
133 clay_yy_delete_buffer(YY_CURRENT_BUFFER);
134 free(yy_buffer_stack);
138 * clay_scanner_initialize function:
139 * this function initialises the scanner global variables with default values.
141 void clay_scanner_initialize() {
142 clay_yy_flush_buffer(YY_CURRENT_BUFFER);
145 char *trim(char *str) {
147 // http://stackoverflow.com/questions/122616/how-do-i-trim-leading-trailing-whitespace-in-a-standard-way
150 // Trim leading space
151 while(isspace(*str)) str++;
153 if(*str == 0) // All spaces?
156 // Trim trailing space
157 end = str + strlen(str) - 1;
158 while(end > str && isspace(*end)) end--;
160 // Write new null terminator