source: git/Singular/scanner.l @ 057e93c

spielwiese
Last change on this file since 057e93c was 057e93c, checked in by Hans Schönemann <hannes@…>, 26 years ago
* Fri Feb 27 15:02:10 MET 1998 hannes new input scheme: many modifications to febase.h, febase.inc, febase.cc, scanner.l, grammar.y, iplib.cc, ipshell.{h,cc} git-svn-id: file:///usr/local/Singular/svn/trunk@1183 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 12.1 KB
Line 
1%{
2/****************************************
3*  Computer Algebra System SINGULAR     *
4****************************************/
5/* $Id: scanner.l,v 1.9 1998-02-27 14:06:24 Singular Exp $ */
6#include <stdio.h>
7#include <string.h>
8#include <stdlib.h>
9#include <ctype.h>
10
11#include "mod2.h"
12#include "tok.h"
13#include "stype.h"
14#include "ipshell.h"
15#include "mmemory.h"
16#include "febase.h"
17
18int feReadLine(char* b, int l);
19#define ALLOC(a) Alloc((a))
20int yylineno  = 0;
21int noeof = 0;
22static int blocknest = 0;
23extern char * yytext;
24//extern unsigned char * yytext;
25extern int yyleng;
26extern BOOLEAN noringvars;
27extern int inerror;
28
29static char * dupyytext()
30{
31  //int i = strlen((char *)yytext);
32  //if (i>0) yytext[i-1] = '\0';
33  if (yyleng>0) yytext[yyleng-1] = '\0';
34  return mstrdup((char *)yytext);
35}
36
37static char * dupyytextNL()
38{
39  int i = yyleng;//strlen((char *)yytext);
40  char * rc = (char*)AllocL( 3 + i );
41  if (i>0)
42  {
43    yytext[i-1] = '\0';
44    strcpy( rc, (char *)yytext );
45  }
46  else
47    i++;
48  rc[i-1] = '\n';
49  rc[i] = '\n';
50  rc[i+1] = '\0';
51  return rc;
52}
53
54  #undef YY_DECL
55  #define YY_DECL int yylex(YYSTYPE* lvalp)
56
57  #undef yywrap
58  extern "C" {
59  int yywrap() { return exitVoice(); }
60  }
61
62  #undef YY_INPUT
63  #define YY_INPUT(buf,result,max_size) \
64          result = feReadLine( (char *) (buf), (max_size) )
65
66  #undef YY_USER_ACTION
67  #define YY_USER_ACTION \
68          if ((inerror==1)&&(*yytext>=' '))\
69          { Print("   skipping text from `%s`",yytext);inerror=2; }
70
71%}
72
73digit          [0-9]
74letter         [@a-zA-Z\']
75integer        {digit}+
76monom          {letter}+{digit}*
77rgvars         ({digit}+[/])*{digit}+{monom}+
78realnum        {digit}+"."{digit}+("e"[+-]{digit}+)?
79name           ({letter}({letter}*{digit}*_*)*|_)
80parname        #
81
82/* %start START */
83
84%x string
85%x block
86%x blockstr
87%x brace
88%x bracestr
89%x bracket
90%x asstring
91
92%%
93\/\/[^\n]*               { }
94^#![^\n]*                { }
95pause[ \t\n]*[\.;]       { fePause(); }
96while                    { blocknest = 0; noeof = noeof_brace; BEGIN(brace);
97                           return WHILE_CMD;}
98for                      { blocknest = 0; noeof = noeof_brace; BEGIN(brace);
99                           return FOR_CMD;}
100
101("help"|"?")[ \t\n]*     { noeof = noeof_asstring;
102                           BEGIN(asstring);
103                           return HELP_CMD;
104                         }
105
106example[ \t\n]*          { noeof = noeof_asstring;
107                           IsCmd("example",lvalp->i);
108                           BEGIN(asstring);
109                           return EXAMPLE_CMD;
110                         }
111
112proc[ \t]+{name}[ \t]*\( {
113                           char c; char *cp;
114                           lvalp->name = mstrdup(iiProcName((char *)yytext,c,cp));
115                           noeof = noeof_procname;
116                           blocknest = 1;
117                           BEGIN(brace);
118                           return PROC_DEF;
119                         }
120<asstring>[^;\n]+        {
121                           lvalp->name = mstrdup((char *)yytext);
122                           noeof = 0; BEGIN(INITIAL);
123                           return STRINGTOK;
124                         }
125<asstring>;              {
126                           noeof = 0; BEGIN(INITIAL);
127                           return *yytext;
128                         }
129
130<brace>"\""              {
131                           noeof = noeof_string;
132                           BEGIN(bracestr);
133                           yymore();
134                         }
135<brace>"("               { if (blocknest++) yymore(); }
136<brace>[^;\(\)]          { if (blocknest) yymore(); }
137<brace>";"               {
138                           if (blocknest)
139                           {
140                             lvalp->name = dupyytext();
141                             return STRINGTOK;
142                           }
143                         }
144<brace>")"               {
145                           if (--blocknest <= 0)
146                           {
147                             noeof = 0;
148                             BEGIN(INITIAL);
149                             lvalp->name = dupyytext();
150                             return STRINGTOK;
151                           }
152                           yymore();
153                         }
154<bracestr>"\""           {
155                           noeof = noeof_brace;
156                           BEGIN(brace);
157                           yymore();
158                         }
159<bracestr>[^\"]          { yymore(); }
160<bracket>"("             { return '('; }
161<bracket>","             { return ','; }
162<bracket>[ \t\n]*        { ; }
163<bracket>[^\(\), \t\n]*  {
164                           lvalp->name = mstrdup((char *)yytext);
165                           return STRINGTOK;
166                         }
167<bracket>\"[^\"]*\"      {
168                           lvalp->name = mstrdup((char *)yytext);
169                           return STRINGTOK;
170                         }
171<bracket>")"             {
172                           noeof = 0; BEGIN(INITIAL);
173                           return ')';
174                         }
175
176"{"                      {
177                           blocklineno = yylineno;
178                           blocknest = 1;
179                           noeof = noeof_block;
180                           BEGIN(block);
181                         }
182<block>"\""              {
183                           noeof = noeof_string;
184                           BEGIN(blockstr);
185                           yymore();
186                         }
187<blockstr>[^\"]          { yymore(); }
188<blockstr>"\\\\"         { yymore(); }
189<blockstr>"\\\""         { yymore(); }
190<blockstr>"\""           {
191                           noeof = noeof_block;
192                           BEGIN(block);
193                           yymore();
194                         }
195<block>[^\{\}\"]*        { yymore(); }
196<block>"{"               { blocknest++; yymore(); }
197<block>"}"               {
198                           if (--blocknest <= 0)
199                           {
200                             BEGIN(INITIAL);
201                             noeof = 0;
202                             lvalp->name = dupyytextNL();
203                             return BLOCKTOK;
204                           }
205                           yymore();
206                         }
207"\""                     { BEGIN(string); noeof = noeof_string;}
208~                        { return SYS_BREAK; }
209<string>[^\"]            { yymore(); }
210<string>"\\\\"           { yymore(); }
211<string>"\\\""           { yymore(); }
212<string>"\""             {
213                           char * s;
214                           noeof = 0;
215                           BEGIN(INITIAL);
216                           s = lvalp->name = dupyytext();
217                           while (*yytext)
218                           {
219                             if (*yytext == '\\') yytext++;
220                             *s++ = *yytext++;
221                           }
222                           *s++ = *yytext++;
223                           return STRINGTOK;
224                         }
225
226[ \t\r\n]                /* skip whitespace */
227".."                     { return DOTDOT; }
228"::"                     { return COLONCOLON; }
229"--"                     { return MINUSMINUS; }
230"++"                     { return PLUSPLUS  ; }
231"=="                     { return EQUAL_EQUAL; }
232"&&"                     { return '&'; }
233"||"                     { return '|'; }
234"<="                     { return LE; }
235">="                     { return GE; }
236"!"                      { return NOT; }
237"!="                     { return NOTEQUAL; }
238"<>"                     { return NOTEQUAL; }
239"**"                     { return '^'; }
240\\                       { return '\\'; }
241newline                  {
242                           lvalp->name = mstrdup("\n");
243                           return STRINGTOK;
244                         }
245{integer}                {
246                           lvalp->name = (char *)yytext;
247                           if ((currRing!=NULL)
248                           && (strlen(lvalp->name)>MAX_INT_LEN))
249                           {
250                             lvalp->name = mstrdup((char *)yytext);
251                             return RINGVAR;
252                           }
253                           else
254                             return INT_CONST;
255                         }
256{integer}\/{integer}     {
257                           lvalp->name = mstrdup((char *)yytext);
258                           return RINGVAR;
259                         }
260\$                       {
261                           #ifdef HAVE_TCL
262                           if (tclmode)
263                             PrintTCL('Q',0,NULL);
264                           else
265                           #endif
266                           { if (BVERBOSE(0)) printf("\n$Bye.\n"); }
267                           #ifndef macintosh
268                             #ifdef HAVE_FEREAD
269                               #ifdef HAVE_ATEXIT
270                                 fe_reset_input_mode();
271                               #else
272                                 fe_reset_input_mode(0,NULL);
273                               #endif
274                             #else
275                               #ifdef HAVE_READLINE
276                                 fe_reset_input_mode();
277                               #endif
278                             #endif
279                           #endif
280                           #ifdef sun
281                           #ifndef __svr4__
282                           _cleanup();
283                           _exit(0);
284                           #endif
285                           #endif
286                           exit(0);
287                         }
288(quit|exit)[ \t\n]*[\.;]?  {
289                           #ifdef HAVE_TCL
290                             if (tclmode)
291                               PrintTCL('Q',0,NULL);
292                             else
293                           #endif
294                           #ifdef MM_STAT
295                           mmStat(-500);
296                           #endif
297                           { if (BVERBOSE(0)) printf("\nAuf Wiedersehen.\n"); }
298                           #ifndef macintosh
299                             #ifdef HAVE_FEREAD
300                               #ifdef HAVE_ATEXIT
301                                 fe_reset_input_mode();
302                               #else
303                                 fe_reset_input_mode(0,NULL);
304                               #endif
305                             #else
306                               #ifdef HAVE_READLINE
307                                 fe_reset_input_mode();
308                               #endif
309                             #endif
310                           #endif
311                           #ifdef MDEBUG
312                             #ifdef MLIST
313                             mmTestList();
314                             #endif
315                           #endif
316                           #ifdef sun
317                           #ifndef __svr4__
318                           _cleanup();
319                           _exit(0);
320                           #endif
321                           #endif
322                           exit(0);
323                         }
324
325{rgvars}|{realnum}       {
326                           lvalp->name = mstrdup((char *)yytext);
327                           return RINGVAR;
328                         }
329
330({parname}|{name})       {
331                           /* {name} */
332                           int rc=0;
333                           if (yytext[strlen((char *)yytext)-1] == '\n')
334                           {
335                             yytext[strlen((char *)yytext)-1] = '\0';
336                           }
337                           if (yyleng > 1)
338                           {
339                             rc = IsCmd((char *)yytext,lvalp->i);
340                             if (rc) return rc;
341                           }
342                           lvalp->name = mstrdup((char *)yytext);
343                           return UNKNOWN_IDENT;
344                         }
345
346.                       {
347                           /*if (*yytext == '\n') REJECT;*/
348                           lvalp->i = *yytext;   /* token has own value */
349                           return *yytext;
350                         }
351%%
352
353void * myynewbuffer()
354{
355  void * oldb = yy_current_buffer;
356  yy_switch_to_buffer(yy_create_buffer(NULL, YY_BUF_SIZE));
357  return oldb;
358}
359
360void myyoldbuffer(void * oldb)
361{
362  yy_delete_buffer(yy_current_buffer);
363  yy_switch_to_buffer((YY_BUFFER_STATE)oldb);
364  //yy_flush_buffer((YY_BUFFER_STATE)oldb);
365}
Note: See TracBrowser for help on using the repository browser.