1 | %{ |
---|
2 | /**************************************** |
---|
3 | * Computer Algebra System SINGULAR * |
---|
4 | ****************************************/ |
---|
5 | /* $Id: scanner.l,v 1.1 1998-11-19 15:16:43 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 | |
---|
22 | const char sNoName[]="_"; |
---|
23 | char my_yylinebuf[80]; |
---|
24 | int old_state = 0; |
---|
25 | int yylineno = 1; |
---|
26 | int tok; |
---|
27 | int myynest = -1; |
---|
28 | int traceit = 0; |
---|
29 | procdefv proclist = NULL; |
---|
30 | moddef module_def; |
---|
31 | cfilesv c_filelist = NULL; |
---|
32 | |
---|
33 | extern "C" |
---|
34 | { |
---|
35 | int yywrap(); |
---|
36 | } |
---|
37 | |
---|
38 | %} |
---|
39 | |
---|
40 | digit [0-9] |
---|
41 | letter [@a-zA-Z\'] |
---|
42 | name ({letter}({letter}*{digit}*_*)*|_) |
---|
43 | fname ({letter}({letter}*{digit}*_*.)*|_) |
---|
44 | letters ({letter}|{digit}|[_./#%^*:,]) |
---|
45 | string ({letters}*) |
---|
46 | comment [\/][\/] |
---|
47 | dolar [$] |
---|
48 | symbols [~!@#$%^&*()_+-={}\\\|\[\];:,<.>/\?\' \n\~\`\r] |
---|
49 | aletters ({letter}|{digit}|{symbols}|{dolar}|{escquote}) |
---|
50 | strings ({aletters}*) |
---|
51 | quote [\"] |
---|
52 | escquote (\\\") |
---|
53 | taborspace [ \t] |
---|
54 | tos ({taborspace}*) |
---|
55 | eq (=|{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],n1[32],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],n1[32],n2[32],funcname[256]; |
---|
135 | int cmd; |
---|
136 | BEGIN(old_state); |
---|
137 | param[0]='\0'; |
---|
138 | sscanf( yytext, "%[^)])%*[^=]=%s", param, funcname); |
---|
139 | if(strlen(funcname)<=0) |
---|
140 | sscanf( yytext, "%[^)])=%s", param, funcname); |
---|
141 | proclist->funcname = (char *)malloc(strlen(funcname)+1); |
---|
142 | strcpy(proclist->funcname, funcname); |
---|
143 | cmd = IsCmd(param, tok); |
---|
144 | if(cmd!=0)AddParam(proclist, param, decl2str(tok,n2), tok); |
---|
145 | else printf("proc '%s': Invalid parameter %s.\n", |
---|
146 | proclist->procname, param); |
---|
147 | } |
---|
148 | <pdef>\)+{eq}+{name}|{eq}+{tos}+{name} { |
---|
149 | char funcname[256]; |
---|
150 | int cmd; |
---|
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 | |
---|
172 | extern "C" { |
---|
173 | int yywrap() { |
---|
174 | //printf("yywrap()\n"); |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | main( int argc, char *argv[] ) |
---|
179 | { |
---|
180 | ++argv, --argc; /* skip over program name */ |
---|
181 | if ( argc > 0 ) |
---|
182 | yyin = fopen( argv[0], "rb" ); |
---|
183 | else |
---|
184 | yyin = stdin; |
---|
185 | module_def.name=NULL; |
---|
186 | module_def.version=NULL; |
---|
187 | module_def.info=NULL; |
---|
188 | module_def.helpfile=NULL; |
---|
189 | yylex(); |
---|
190 | //PrintProclist(proclist); |
---|
191 | generate_mod(proclist, &module_def, c_filelist); |
---|
192 | mod_create_makefile(&module_def, c_filelist); |
---|
193 | |
---|
194 | } |
---|