source: git/modules/tools/scanner.l @ 4e859f5

spielwiese
Last change on this file since 4e859f5 was 4e859f5, checked in by Kai Krüger <krueger@…>, 25 years ago
major internal changes of handling definition git-svn-id: file:///usr/local/Singular/svn/trunk@2968 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.0 KB
Line 
1%{
2/****************************************
3*  Computer Algebra System SINGULAR     *
4****************************************/
5/* $Id: scanner.l,v 1.3 1999-03-24 13:04:21 krueger Exp $ */
6#include <stdio.h>
7#include <string.h>
8#include <stdlib.h>
9#include <ctype.h>
10
11#include "modgen.h"
12#include <mod2.h>
13#include <febase.h>
14#include <grammar.h>
15#include <ipid.h>
16#include <ipshell.h>
17#include <mmemory.h>
18#include <structs.h>
19#include <subexpr.h>
20#include <tok.h>
21
22const char sNoName[]="_";
23char       my_yylinebuf[80];
24int old_state = 0;
25int yylineno = 1;
26int tok;
27int  myynest = -1;
28int  traceit = 0;
29moddef module_def;
30
31extern "C"
32{
33  int yywrap();
34}
35
36%}
37
38digit          [0-9]
39letter         [@a-zA-Z\']
40name           ({letter}({letter}*{digit}*_*)*|_)
41fname          ({letter}({letter}*{digit}*_*.)*|_)
42letters        ({letter}|{digit}|[_./#%^*:,])
43string         ({letters}*)
44comment        [\/][\/]
45dolar          [$]
46symbols        [~!@#$%^&*()_+-={}\\\|\[\];:,<.>/\?\' \n\~\`\r]
47aletters       ({letter}|{digit}|{symbols}|{dolar}|{escquote})
48strings        ({aletters}*)
49quote          [\"]
50escquote       (\\\")
51taborspace     [ \t]
52tos            ({taborspace}*)
53eq             (=|{tos}+=|=+{tos}|{tos}+=+{tos})
54
55/* %start START */
56
57%x pdef
58%x comment
59
60%%
61(\/\/[^\n]*)|(^#![^\n]*)|([ \t]) { }
62\/\/*        { old_state = YYSTATE; BEGIN(comment); }
63
64(module+{eq}+\"+{name}\") {
65             char *buff = (char *)malloc(yyleng+4);
66             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
67             module_def.name = (char *)malloc(strlen(buff)+1);
68             strcpy(module_def.name, buff);
69             strcat(buff, ".cc");
70             Add2files(&module_def,buff);
71             free(buff);
72           }
73
74(version+{eq}+\"+{strings}\") {
75             char *buff = (char *)malloc(yyleng);
76             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
77             module_def.version = (char *)malloc(strlen(buff)+1);
78             strcpy(module_def.version, buff);
79             make_version(module_def.version, &module_def);
80             free(buff);
81           }
82
83(helpfile+{eq}+\"+{fname}\") {
84             char *buff = (char *)malloc(yyleng);
85             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
86             module_def.helpfile = (char *)malloc(strlen(buff)+1);
87             strcpy(module_def.helpfile, buff);
88             free(buff);
89           }
90
91(cxxsource+{eq}+{fname}) {
92             char *buff = (char *)malloc(yyleng);
93             sscanf( yytext, "%*[^=]=%s", buff);
94             Add2files(&module_def,buff);
95             free(buff);
96           }
97
98(info+{eq}+\"+{strings}\") {
99             char *buff = (char *)malloc(yyleng);
100             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
101             module_def.info = (char *)malloc(strlen(buff)+1);
102             strcpy(module_def.info, buff);
103             free(buff);
104           }
105
106
107(proc+{tos}+{name}+{tos}+{name})|({tos}+proc+{tos}+{name}+{tos}+{name}) {
108             char proc[256], ret_val[256], n2[32];
109             int cmd;
110             memset(proc, '\0', 256);
111             memset(ret_val, '\0', 256);
112             memset(n2, '\0', 32);
113             old_state = YYSTATE;
114             BEGIN(pdef);
115             sscanf( yytext, "%*[^p]proc %s %s", ret_val, proc);
116             if(strlen(proc)<1) sscanf( yytext, "proc %s %s", ret_val, proc);
117             printf("'%s'\n", yytext);
118             printf("R: proc '%s' '%s'\n", ret_val, proc);
119             cmd = IsCmd(ret_val, tok);
120             if(cmd!=0)
121                Add2proclist(&module_def, proc, ret_val,
122                                          decl2str(tok,n2), tok);
123             else printf("proc '%s': Invalid return parameter %s.\n",
124                         module_def.procs[module_def.proccnt-1].procname,
125                         ret_val);
126           }
127
128(proc+{tos}+{name})|({tos}+proc+{tos}+{name}) {
129             char proc[256];
130             old_state = YYSTATE;
131             BEGIN(pdef);
132             proc[0]='\0';
133             sscanf( yytext, "%*[^p]proc %s", proc);
134             if(strlen(proc)<1) sscanf( yytext, "proc %s", proc);
135             Add2proclist(&module_def, proc, "none", "NONE", 0);
136           }
137
138<pdef>[ \t]  { }
139<pdef>\(     {
140             }
141<pdef>{name}+, {
142             char param[256], n2[32];
143             int cmd;
144             memset(n2, '\0', 32);
145             memset(param, '\0', 256);
146             sscanf( yytext, "%[^,],", param);
147             cmd = IsCmd(param, tok);
148             if(cmd!=0)AddParam(&module_def,
149                                param, decl2str(tok,n2), tok);
150             else printf("proc '%s': Invalid parameter %s.\n",
151                         module_def.procs[module_def.proccnt-1].procname,
152                         param);
153           }
154<pdef>{name}+\)+{eq}+{name} {
155             char param[256], n2[32],funcname[256];
156             int cmd;
157             BEGIN(old_state);
158             memset(param, '\0', 256);
159             memset(n2, '\0', 32);
160             memset(funcname, '\0', 256);
161             sscanf( yytext, "%[^)])%*[^=]=%s", param, funcname);
162             if(strlen(funcname)<=0)
163                sscanf( yytext, "%[^)])=%s", param, funcname);
164             free(module_def.procs[module_def.proccnt-1].funcname);
165             module_def.procs[module_def.proccnt-1].funcname =
166                (char *)malloc(strlen(funcname)+1);
167             memset(module_def.procs[module_def.proccnt-1].funcname,
168                    '\0', strlen(funcname)+1);
169             memcpy(module_def.procs[module_def.proccnt-1].funcname,
170                    funcname, strlen(funcname));
171             cmd = IsCmd(param, tok);
172             if(cmd!=0)AddParam(&module_def,
173                                param, decl2str(tok,n2), tok);
174             else printf("proc '%s': Invalid parameter %s.\n",
175                         module_def.procs[module_def.proccnt-1].procname, param);
176           }
177<pdef>\)+{eq}+{name}|{eq}+{tos}+{name} {
178             char funcname[256];
179             BEGIN(old_state);
180             sscanf( yytext, "%*[^=]=%s", funcname);
181             if(strlen(funcname)<=0)
182                sscanf( yytext, "=%s", funcname);
183             free(module_def.procs[module_def.proccnt-1].funcname);
184             module_def.procs[module_def.proccnt-1].funcname =
185                (char *)malloc(strlen(funcname)+1);
186             memset(module_def.procs[module_def.proccnt-1].funcname,
187                    '\0', strlen(funcname)+1);
188             memcpy(module_def.procs[module_def.proccnt-1].funcname,
189                    funcname, strlen(funcname));
190           }
191
192<pdef>.      { }
193
194<comment>\*\/            { BEGIN(old_state); }
195<comment>\n              { yylineno++; }
196<comment>.               { }
197
198
199\n                       { yylineno++; }
200\r                       { }
201.                        { }
202
203%%
204
205extern "C" {
206  int yywrap() {
207    //printf("yywrap()\n");
208    return 1;
209  }
210}
211
212main( int argc, char *argv[] )
213{
214  ++argv, --argc;  /* skip over program name */
215  if ( argc > 0 )
216     yyin = fopen( argv[0], "rb" );
217  else
218     yyin = stdin;
219  module_def.name=NULL;
220  module_def.version=NULL;
221  module_def.info=NULL;
222  module_def.helpfile=NULL;
223  module_def.procs=NULL;
224  module_def.proccnt = 0;
225  module_def.files = NULL;
226  module_def.filecnt = 0;
227  yylex();
228  PrintProclist(&module_def);
229  generate_mod(&module_def);
230  mod_create_makefile(&module_def);
231
232}
Note: See TracBrowser for help on using the repository browser.