update isl for change in representation of isl_constraint
[ppcg.git] / clan / source / scanner.l
blob1a8c20928bfc0028e0563f227ed5c66403e16514
2    /*+------- <| --------------------------------------------------------**
3     **         A                     Clan                                **
4     **---     /.\   -----------------------------------------------------**
5     **   <|  [""M#                 scanner.l                             **
6     **-   A   | #   -----------------------------------------------------**
7     **   /.\ [""M#         First version: 30/04/2008                     **
8     **- [""M# | #  U"U#U  -----------------------------------------------**
9          | #  | #  \ .:/
10          | #  | #___| #
11  ******  | "--'     .-"  ******************************************************
12  *     |"-"-"-"-"-#-#-##   Clan : the Chunky Loop Analyzer (experimental)     *
13  ****  |     # ## ######  *****************************************************
14  *      \       .::::'/                                                       *
15  *       \      ::::'/     Copyright (C) 2008 Cedric Bastoul                  *
16  *     :8a|    # # ##                                                         *
17  *     ::88a      ###      This is free software; you can redistribute it     *
18  *    ::::888a  8a ##::.   and/or modify it under the terms of the GNU Lesser *
19  *  ::::::::888a88a[]:::   General Public License as published by the Free    *
20  *::8:::::::::SUNDOGa8a::. Software Foundation, either version 3 of the       *
21  *::::::::8::::888:Y8888:: License, or (at your option) any later version.    *
22  *::::':::88::::888::Y88a::::::::::::...                                      *
23  *::'::..    .   .....   ..   ...  .                                          *
24  * This software is distributed in the hope that it will be useful, but       *
25  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
26  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
27  * for more details.                                                          *
28  *                                                                            *
29  * You should have received a copy of the GNU Lesser General Public License   *
30  * along with software; if not, write to the Free Software Foundation, Inc.,  *
31  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA                     *
32  *                                                                            *
33  * Clan, the Chunky Loop Analyzer                                             *
34  * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr                         *
35  *                                                                            *
36  ******************************************************************************/
40    #include <stdlib.h>
41    #include <string.h>
42    #include <clan/macros.h>
43    #include <clan/vector.h>
44    #include <clan/matrix.h>
45    #include <parser.h>
47    void yyerror(char *);
48    int  clan_scanner(int, char *, char *);
50    extern int           parser_recording; /**< Do we record what we read ? */
51    extern char *        parser_record;    /**< What we record */
52    extern clan_symbol_p parser_symbol;    /**< Top of the symbol table */
54    int  scanner_parsing = CLAN_FALSE;     /**< Do we parse or not ? */
55    int  scanner_comment = 0;              /**< Comment nesting depth */
56    char scanner_latest_text[SCOPLIB_MAX_STRING]; /**< Latest text read */
59 %x LINECOMMENT
60 %x FULLCOMMENT
64 <FULLCOMMENT>"*/"      {
65                          scanner_comment --;
66                          if (scanner_comment == 0)
67                            BEGIN INITIAL;   /* Quit any mode */
68                        }
69 <FULLCOMMENT>"/*"      { scanner_comment ++; }
70 <FULLCOMMENT>.         ; /* Do nothing */
72 <LINECOMMENT>\n        { BEGIN INITIAL;     /* Quit any mode */ }
73 <LINECOMMENT>.         ; /* Do nothing */
75 [ \t\n]*               ; /* Skip whitespaces */
76 "//"                   { BEGIN LINECOMMENT; /* Enter LINECOMMENT mode */ }
77 "/*"                   {
78                          BEGIN FULLCOMMENT; /* Enter FULLCOMMENT mode */
79                          scanner_comment ++;
80                        }
81 "#pragma"[ ]+"scop"    { scanner_parsing = CLAN_TRUE;  /* Start parsing */ }
82 "#pragma"[ ]+"endscop" { scanner_parsing = CLAN_FALSE; /* Stop  parsing */ }
83 "#pragma"[ ]+"local-vars" { return clan_scanner(PRAGMALOCALVARS, yytext,"PRAGMALOCALVARS");   }
84 "#pragma"[ ]+"live-out" { return clan_scanner(PRAGMALIVEOUT, yytext,"PRAGMALIVEOUT");   }
85 "if"                   { return clan_scanner(IF,       yytext,"IF");   }
86 "else"                 { return clan_scanner(ELSE,     yytext,"ELSE"); }
87 "for"                  { return clan_scanner(FOR,      yytext,"FOR");  }
88 "min"                  { return clan_scanner(MIN,      yytext,"min");  }
89 "max"                  { return clan_scanner(MAX,      yytext,"max");  }
90 "ceild"                { return clan_scanner(CEILD,  yytext,"ceild");  }
91 "floord"               { return clan_scanner(FLOORD, yytext,"floord");  }
93 [_A-Za-z]"."[A-Za-z0-9_]* |
94 [_A-Za-z]"->"[A-Za-z0-9_]* |
95 [_A-Za-z][A-Za-z0-9_]* {
96                          char * word;
97                          word = (char *)malloc((strlen(yytext)+1)*sizeof(char));
98                          strcpy(word,yytext);
99                          yylval.symbol = word;
100                          return clan_scanner(ID,yytext,"ID");
101                        }
102 [0-9]+"."[0-9]*[d,f]*        { return clan_scanner(REAL,yytext,"REAL"); }
103 [0-9]+                 {
104                          yylval.value = atoi(yytext) ;
105                          return clan_scanner(INTEGER,yytext,"INTEGER");
106                        }
108 "("                    { return clan_scanner(syRPARENTHESIS,   yytext,"(");  }
109 ")"                    { return clan_scanner(syLPARENTHESIS,   yytext,")");  }
110 "["                    { return clan_scanner(syRBRACKET,       yytext,"[");  }
111 "]"                    { return clan_scanner(syLBRACKET,       yytext,"]");  }
112 "{"                    { return clan_scanner(syRBRACE,         yytext,"{");  }
113 "}"                    { return clan_scanner(syLBRACE,         yytext,"}");  }
114 ","                    { return clan_scanner(syCOMMA,          yytext,",");  }
115 ";"                    { return clan_scanner(sySEMICOLON,      yytext,";");  }
116 "."                    { return clan_scanner(syPOINT,          yytext,".");  }
117 "->"                   { return clan_scanner(syARROW,          yytext,"->"); }
118 ":"                    { return clan_scanner(opCOLON,          yytext,":");  }
119 "!"                    { return clan_scanner(opNOT,            yytext,"!");  }
120 "?"                    { return clan_scanner(opQMARK,          yytext,"?");  }
121 "++"                   { return clan_scanner(opINCREMENTATION, yytext,"++"); }
122 "--"                   { return clan_scanner(opDECREMENTATION, yytext,"--"); }
123 "+="                   { return clan_scanner(opPLUSEQUAL,      yytext,"+="); }
124 "-="                   { return clan_scanner(opMINUSEQUAL,     yytext,"-="); }
125 "*="                   { return clan_scanner(opMULTIPLYEQUAL,  yytext,"*="); }
126 "/="                   { return clan_scanner(opDIVIDEEQUAL,    yytext,"/="); }
127 "|="                   { return clan_scanner(opOREQUAL,        yytext,"|="); }
128 "^="                   { return clan_scanner(opCOMPEQUAL,      yytext,"^="); }
129 "&="                   { return clan_scanner(opANDEQUAL,       yytext,"&="); }
130 "%="                   { return clan_scanner(opMODEQUAL,       yytext,"%="); }
131 "=="                   { return clan_scanner(opEQUAL,          yytext,"=="); }
132 "<="                   { return clan_scanner(opLEQ,            yytext,"<="); }
133 ">="                   { return clan_scanner(opGEQ,            yytext,">="); }
134 "<"                    { return clan_scanner(opLOWER,          yytext,"<");  }
135 ">"                    { return clan_scanner(opGREATER,        yytext,">");  }
136 "+"                    { return clan_scanner(opPLUS,           yytext,"+");  }
137 "-"                    { return clan_scanner(opMINUS,          yytext,"-");  }
138 "*"                    { return clan_scanner(opMULTIPLY,       yytext,"*");  }
139 "/"                    { return clan_scanner(opDIVIDE,         yytext,"/");  }
140 "%"                    { return clan_scanner(opMOD,            yytext,"%");  }
141 "&"                    { return clan_scanner(opAND,            yytext,"&");  }
142 "&&"                   { return clan_scanner(opLAND,           yytext,"&&"); }
143 "|"                    { return clan_scanner(opOR,             yytext,"|");  }
144 "||"                   { return clan_scanner(opLOR,            yytext,"||"); }
145 "^"                    { return clan_scanner(opCOMP,           yytext,"^");  }
146 "="                    { return clan_scanner(opASSIGNMENT,     yytext,"=");  }
148 .                      { if (scanner_parsing == CLAN_TRUE)
149                          {
150                             //if (CLAN_DEBUG)
151                             //   printf("Lex: Unknown character (%s)\n",yytext);
152                            //yyerror("Lex: Unknown character");
153                          }
154                        }
158 int yywrap(void)
160   return 1;
165  * clan_scanner function:
166  * This function achieves some basic work when Lex recognize something: it
167  * prints a log information if necessary for debugging, it updates the string
168  * scanner_latest_text with the string that have been read and returns the
169  * token if we are scanning a SCoP or the special token IGNORE otherwise.
170  * \param token   The token code to send to Yacc for the Lex item.
171  * \param text    The textual Lex item.
172  * \param message A string to be printed for debugging.
173  **
174  * - 30/04/2008: first version.
175  */
177 int clan_scanner(int token, char * text, char * message)
179   //if (CLAN_DEBUG)
180   //  printf("Lex: %s (%s)\n",message,text);
182   sprintf(scanner_latest_text,"%s",text);
183   if (parser_recording)
184     strcat(parser_record,text);
186   if (scanner_parsing == CLAN_TRUE)
187     return token;
188   else
189     return IGNORE;