source: vis_dev/vis-2.3/src/io/io.l @ 80

Last change on this file since 80 was 14, checked in by cecile, 13 years ago

vis2.3

File size: 7.9 KB
RevLine 
[14]1%{
2/**CFile***********************************************************************
3
4  FileName    [io.l]
5
6  PackageName [io]
7
8  Synopsis    [Lexical analyzer for BLIF-MV.]
9
10  Description []
11
12  SeeAlso     []
13
14  Author      [Yuji Kukimoto, Rajeev Ranjan, Huey-Yih Wang]
15
16  Copyright   [Copyright (c) 1994-1996 The Regents of the Univ. of California.
17  All rights reserved.
18
19  Permission is hereby granted, without written agreement and without license
20  or royalty fees, to use, copy, modify, and distribute this software and its
21  documentation for any purpose, provided that the above copyright notice and
22  the following two paragraphs appear in all copies of this software.
23
24  IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
25  DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
26  OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
27  CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29  THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
30  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN
32  "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE
33  MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.]
34
35******************************************************************************/
36
37#include "ioYacc.h"
38
39/*---------------------------------------------------------------------------*/
40/* Constant declarations                                                     */
41/*---------------------------------------------------------------------------*/
42
43#define IoMAXSTACKDEPTH (32)
44
45/*---------------------------------------------------------------------------*/
46/* Stucture declarations                                                     */
47/*---------------------------------------------------------------------------*/
48
49
50/*---------------------------------------------------------------------------*/
51/* Type declarations                                                         */
52/*---------------------------------------------------------------------------*/
53
54
55/*---------------------------------------------------------------------------*/
56/* Variable declarations                                                     */
57/*---------------------------------------------------------------------------*/
58
59YY_BUFFER_STATE globalFilePtrStack[IoMAXSTACKDEPTH];
60int globalCurrentStackDepth = 0;
61
62/*---------------------------------------------------------------------------*/
63/* Macro declarations                                                        */
64/*---------------------------------------------------------------------------*/
65
66
67/**AutomaticStart*************************************************************/
68
69/*---------------------------------------------------------------------------*/
70/* Static function prototypes                                                */
71/*---------------------------------------------------------------------------*/
72
73/**AutomaticEnd***************************************************************/
74
75static char * _IoFileNameExtract(char *string);
76
77%}
78
79/*---------------------------------------------------------------------------*/
80/* Lexical analyzer rules                                                    */
81/*---------------------------------------------------------------------------*/
82
83%option noyywrap
84
85/* -, =, (, ), {, }, ! and ; are intentionally removed from symbol
86   - is for dashes in tables
87   = is for the = construct in tables
88   ( and ) are for lists in tables
89   { and } are for ranges in tables
90   ! is for complements in tables
91   ; is for delimitters in CTL formulas
92removing - has another effect. Since - is not a symbol, -> in the table
93construct is always found by the lexer
94 */
95blank  [ \t\r\b]
96alpha  [A-Za-z]
97number [0-9]
98symbol [\^\?\|\/\[\]\+\*\$\<\>~@\_#\$%\:\"\'\.]
99/*symbol [\^\?\|\/\[\]\+\*\$\<\>~@\_#\$%\:\;\"\'\.]*/
100/*symbol [\^\?\|\/\+\*\$\<\>~@\_#\$%\:\;\"\'\.]*/
101alnumsymbol  {alpha}|{number}|{symbol}
102alnumsymbolblank  {alnumsymbol}|{blank}
103
104%%
105
106"->"    {
107        return ARROW;
108        }       
109"="     {
110        return ASSIGN;
111        }
112^{blank}*\n     {
113                globalLineNumber++;
114                continue;
115                }
116\n      {
117        globalLineNumber++;
118        return NEWLINE;
119        }
120\\\n{blank}*\n  {
121                globalLineNumber += 2;
122                return NEWLINE;
123                }
124\\$             {
125#ifdef __cplusplus
126                (void)yyinput();
127#else
128                (void)input();
129#endif
130                globalLineNumber++;
131                continue;
132                }
133
134\.include{blank}+{alnumsymbol}*\n {
135                        char *fileName, *realFileName;
136
137                        fileName = _IoFileNameExtract(IoYytext);
138                        if (globalCurrentStackDepth >= IoMAXSTACKDEPTH){
139                           error_append("Error: .include nested too deeply.\n");
140                           IoError();
141                        }
142                        globalFilePtrStack[globalCurrentStackDepth++] = YY_CURRENT_BUFFER;
143                        IoYyin = Cmd_FileOpen(fileName,"r",&realFileName,1);
144                        if (IoYyin == NIL(FILE)) {
145                                error_append("Error: Include file ");
146                                error_append(fileName);
147                                error_append(" is not found.\n");
148                                IoError();
149                        }
150                        IoYy_switch_to_buffer(IoYy_create_buffer(IoYyin,YY_BUF_SIZE));
151                        BEGIN(INITIAL);
152                        continue;
153                        }
154<<EOF>>         {
155                if (--globalCurrentStackDepth < 0){
156                yyterminate();
157                }
158                else {
159                  IoYy_delete_buffer(YY_CURRENT_BUFFER);
160                  IoYy_switch_to_buffer(globalFilePtrStack[globalCurrentStackDepth]);
161                }
162                }
163                 
164
165\.{alpha}*      {
166                if (strcmp(IoYytext,".model") == 0) {
167                        return MODEL;
168                }
169                else if (strcmp(IoYytext,".inputs") == 0) {
170                        return INPUTS;
171                }
172                else if (strcmp(IoYytext,".outputs") == 0) {
173                        return OUTPUTS;
174                }
175                else if (strcmp(IoYytext, ".mv" ) == 0 ){
176                        return MV;
177                }
178                else if (strcmp(IoYytext,".latch") == 0) {
179                        return LATCH;
180                }
181                else if (strcmp(IoYytext,".table") == 0 || strcmp(IoYytext,".names") == 0) {
182                        return NAMES;
183                }
184                else if (strcmp(IoYytext,".reset") == 0 || strcmp(IoYytext,".r") == 0) {
185                        return RESET;
186                }
187                else if (strcmp(IoYytext,".subckt") == 0) {
188                        return SUBCKT;
189                }
190                else if (strcmp(IoYytext,".default") == 0 || strcmp(IoYytext,".def") == 0) {
191                        return DEFAULT;
192                }
193                else if (strcmp(IoYytext,".root") == 0) {
194                        return ROOT;
195                }
196                else if (strcmp(IoYytext,".end") == 0) {
197                        return END;
198                }
199                else {
200                        error_append("Error: Unknown construct ");
201                        error_append(IoYytext);
202                        error_append("\n");
203                        IoError();
204                }
205                }
206{alnumsymbol}+  {
207                return IDENTIFIER;
208                }
209^{blank}*#[^\n]*\n      {
210                /* for lines containing only comments can be skipped */
211                globalLineNumber++;
212                continue;
213                }
214{blank}+        {
215                /* skip white spaces */
216                continue;
217                }
218#[^\n]*\n               {
219                        /* for lines containing meaningful info
220                        followed by comments; should return NEWLINE */
221                        globalLineNumber++;
222                        return NEWLINE;
223                        }
224.       {
225        return IoYytext[0];
226        }
227
228%%
229
230
231/*---------------------------------------------------------------------------*/
232/* Definition of exported functions                                          */
233/*---------------------------------------------------------------------------*/
234
235
236/*---------------------------------------------------------------------------*/
237/* Definition of internal functions                                          */
238/*---------------------------------------------------------------------------*/
239
240/*---------------------------------------------------------------------------*/
241/* Definition of static functions                                            */
242/*---------------------------------------------------------------------------*/
243
244/**Function********************************************************************
245
246  Synopsis    [Chops off the initial .include from a given string.]
247
248  Description []
249
250  SideEffects []
251
252  SeeAlso     []
253
254******************************************************************************/
255
256static char *
257_IoFileNameExtract(char *string)
258{
259  char *fileName;
260
261  fileName = string + strlen(".include ");
262  fileName[strlen(fileName)-1] = '\0';
263  return fileName;
264}
Note: See TracBrowser for help on using the repository browser.