source: git/modules/tools/scanner.l @ 1832501

spielwiese
Last change on this file since 1832501 was 1832501, checked in by Kai Krüger <krueger@…>, 25 years ago
*** empty log message *** git-svn-id: file:///usr/local/Singular/svn/trunk@2949 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.4 KB
Line 
1%{
2/****************************************
3*  Computer Algebra System SINGULAR     *
4****************************************/
5/* $Id: scanner.l,v 1.2 1999-03-17 12:41:31 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;
29procdefv proclist = NULL;
30moddef module_def;
31cfilesv c_filelist = NULL;
32
33extern "C"
34{
35  int yywrap();
36}
37
38%}
39
40digit          [0-9]
41letter         [@a-zA-Z\']
42name           ({letter}({letter}*{digit}*_*)*|_)
43fname          ({letter}({letter}*{digit}*_*.)*|_)
44letters        ({letter}|{digit}|[_./#%^*:,])
45string         ({letters}*)
46comment        [\/][\/]
47dolar          [$]
48symbols        [~!@#$%^&*()_+-={}\\\|\[\];:,<.>/\?\' \n\~\`\r]
49aletters       ({letter}|{digit}|{symbols}|{dolar}|{escquote})
50strings        ({aletters}*)
51quote          [\"]
52escquote       (\\\")
53taborspace     [ \t]
54tos            ({taborspace}*)
55eq             (=|{tos}+=|=+{tos}|{tos}+=+{tos})
56
57/* %start START */
58
59%x pdef
60%x comment
61
62%%
63(\/\/[^\n]*)|(^#![^\n]*)|([ \t]) { }
64\/\/*        { old_state = YYSTATE; BEGIN(comment); }
65
66(module+{eq}+\"+{name}\") {
67             char *buff = (char *)malloc(yyleng+4);
68             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
69             module_def.name = (char *)malloc(strlen(buff)+1);
70             strcpy(module_def.name, buff);
71             strcat(buff, ".cc");
72             c_filelist = Add2files(c_filelist,buff);
73             free(buff);
74           }
75
76(version+{eq}+\"+{strings}\") {
77             char *buff = (char *)malloc(yyleng);
78             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
79             module_def.version = (char *)malloc(strlen(buff)+1);
80             strcpy(module_def.version, buff);
81             make_version(module_def.version, &module_def);
82             free(buff);
83           }
84
85(helpfile+{eq}+\"+{fname}\") {
86             char *buff = (char *)malloc(yyleng);
87             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
88             module_def.helpfile = (char *)malloc(strlen(buff)+1);
89             strcpy(module_def.helpfile, buff);
90             free(buff);
91           }
92
93(cxxsource+{eq}+{fname}) {
94             char *buff = (char *)malloc(yyleng);
95             sscanf( yytext, "%*[^=]=%s", buff);
96             c_filelist = Add2files(c_filelist,buff);
97             free(buff);
98           }
99
100(info+{eq}+\"+{strings}\") {
101             char *buff = (char *)malloc(yyleng);
102             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
103             module_def.info = (char *)malloc(strlen(buff)+1);
104             strcpy(module_def.info, buff);
105             free(buff);
106           }
107
108
109(proc+{tos}+{name})|({tos}+proc+{tos}+{name}) {
110             char proc[256];
111             old_state = YYSTATE;
112             BEGIN(pdef);
113             proc[0]='\0';
114             sscanf( yytext, "%*[^p]proc %s", proc);
115             if(strlen(proc)<1) sscanf( yytext, "proc %s", proc);
116             proclist = Add2proclist(proclist, proc);
117             //printf("proc: %s\n", proc);
118           }
119
120<pdef>[ \t]  { }
121<pdef>\(     {
122             }
123<pdef>{name}+, {
124             char param[256], n2[32];
125             int cmd;
126             param[0]='\0';
127             sscanf( yytext, "%[^,],", param);
128             cmd = IsCmd(param, tok);
129             if(cmd!=0)AddParam(proclist, param, decl2str(tok,n2), tok);
130             else printf("proc '%s': Invalid parameter %s.\n",
131                         proclist->procname, param);
132           }
133<pdef>{name}+\)+{eq}+{name} {
134             char param[256], n2[32],funcname[256];
135             int cmd;
136             BEGIN(old_state);
137             memset(funcname, '\0', 256);
138             param[0]='\0';
139             sscanf( yytext, "%[^)])%*[^=]=%s", param, funcname);
140             if(strlen(funcname)<=0)
141                sscanf( yytext, "%[^)])=%s", param, funcname);
142             proclist->funcname = (char *)malloc(strlen(funcname)+1);
143             strcpy(proclist->funcname, funcname);
144             cmd = IsCmd(param, tok);
145             if(cmd!=0)AddParam(proclist, param, decl2str(tok,n2), tok);
146             else printf("proc '%s': Invalid parameter %s.\n",
147                         proclist->procname, param);
148           }
149<pdef>\)+{eq}+{name}|{eq}+{tos}+{name} {
150             char funcname[256];
151             BEGIN(old_state);
152             sscanf( yytext, "%*[^=]=%s", funcname);
153             if(strlen(funcname)<=0)
154                sscanf( yytext, "=%s", funcname);
155             proclist->funcname = (char *)malloc(strlen(funcname)+1);
156             strcpy(proclist->funcname, funcname);
157           }
158
159<pdef>.      { }
160
161<comment>\*\/            { BEGIN(old_state); }
162<comment>\n              { yylineno++; }
163<comment>.               { }
164
165
166\n                       { yylineno++; }
167\r                       { }
168.                        { }
169
170%%
171
172extern "C" {
173  int yywrap() {
174    //printf("yywrap()\n");
175    return 1;
176  }
177}
178
179main( int argc, char *argv[] )
180{
181  ++argv, --argc;  /* skip over program name */
182  if ( argc > 0 )
183     yyin = fopen( argv[0], "rb" );
184  else
185     yyin = stdin;
186  module_def.name=NULL;
187  module_def.version=NULL;
188  module_def.info=NULL;
189  module_def.helpfile=NULL;
190  yylex();
191  PrintProclist(proclist);
192  generate_mod(proclist, &module_def, c_filelist);
193  mod_create_makefile(&module_def, c_filelist);
194
195}
Note: See TracBrowser for help on using the repository browser.