[33d539] | 1 | %{ |
---|
| 2 | /**************************************** |
---|
| 3 | * Computer Algebra System SINGULAR * |
---|
| 4 | ****************************************/ |
---|
[c2da0a] | 5 | /* $Id: libparse.l,v 1.7 1998-04-20 10:05:54 krueger Exp $ */ |
---|
[33d539] | 6 | #include <stdio.h> |
---|
| 7 | #include <string.h> |
---|
| 8 | #include <stdlib.h> |
---|
| 9 | #include <ctype.h> |
---|
| 10 | #ifdef STANDALONE_PARSER |
---|
| 11 | # include "utils.h" |
---|
| 12 | # define HAVE_LIBPARSER |
---|
| 13 | //# define YYLPDEBUG 3 |
---|
| 14 | #else |
---|
| 15 | # include "mod2.h" |
---|
| 16 | # include "subexpr.h" |
---|
| 17 | # include "grammar.h" |
---|
| 18 | # include "ipshell.h" |
---|
| 19 | # include "ipid.h" |
---|
| 20 | # include "tok.h" |
---|
| 21 | # include "febase.h" |
---|
| 22 | # include "mmemory.h" |
---|
| 23 | #endif |
---|
[c2da0a] | 24 | #include "libparse.h" |
---|
[33d539] | 25 | |
---|
| 26 | #ifdef HAVE_LIBPARSER |
---|
| 27 | #define YY_SKIP_YYWRAP |
---|
| 28 | |
---|
[5480da] | 29 | typedef enum { LP_NONE, LP_INFO, LP_VERSION} lib_cmds; |
---|
| 30 | |
---|
[33d539] | 31 | int libread(FILE* f, char* buf, int max_size); |
---|
| 32 | int current_pos(int i); |
---|
[5480da] | 33 | void print_version(lp_modes mode, char *p); |
---|
| 34 | void copy_string(lp_modes mode); |
---|
| 35 | void make_version(char *p, int what); |
---|
[33d539] | 36 | |
---|
| 37 | int brace1 = 0; /* { } */ |
---|
| 38 | int brace2 = 0; /* ( ) */ |
---|
| 39 | int brace3 = 0; /* [ ] */ |
---|
| 40 | int quote = 0; /* " */ |
---|
| 41 | int offset = 0; |
---|
[c2da0a] | 42 | BOOLEAN p_static = FALSE; |
---|
[33d539] | 43 | int old_state = 0; |
---|
[5480da] | 44 | lib_cmds last_cmd = LP_NONE; |
---|
[33d539] | 45 | |
---|
| 46 | char libnamebuf[128]; |
---|
[5480da] | 47 | char *text_buffer; |
---|
| 48 | long string_start; |
---|
[33d539] | 49 | |
---|
| 50 | char *yylp_buffer_start; |
---|
| 51 | int yylplineno = 1; |
---|
| 52 | |
---|
| 53 | char *yylp_errlist[]= { |
---|
| 54 | "", |
---|
| 55 | "missing close bracket ')' for proc definition in line %d.", /* 1 */ |
---|
| 56 | "missing close bracket ')' for procbody in line %d.", /* 2 */ |
---|
| 57 | "missing close bracket ']' for procbody in line %d.", /* 3 */ |
---|
| 58 | "too many ')' closed brackets in line %d.", /* 4 */ |
---|
| 59 | "too many ']' closed brackets in line %d.", /* 5 */ |
---|
| 60 | "missing close bracket ')' for example in line %d.", /* 6 */ |
---|
| 61 | "missing close bracket ']' for example in line %d.", /* 7 */ |
---|
| 62 | "cannot assign charater in line %d to any group.", /* 8 */ |
---|
| 63 | "there must be a quote missing somewhere before line %d.", /* 9 */ |
---|
| 64 | "missing close bracket '}' at end of library in line %d.", /* 10 */ |
---|
| 65 | "missing close bracket ')' at end of library in line %d.", /* 11 */ |
---|
[5480da] | 66 | "missing close bracket ']' at end of library in line %d.", /* 12 */ |
---|
[33d539] | 67 | NULL |
---|
| 68 | }; |
---|
| 69 | int yylp_errno = 0; |
---|
| 70 | |
---|
| 71 | #define YYLP_ERR_NONE 0 |
---|
| 72 | #define YYLP_DEF_BR2 1 |
---|
| 73 | #define YYLP_BODY_BR2 2 |
---|
| 74 | #define YYLP_BODY_BR3 3 |
---|
| 75 | #define YYLP_BODY_TMBR2 4 |
---|
| 76 | #define YYLP_BODY_TMBR3 5 |
---|
| 77 | #define YYLP_EX_BR2 6 |
---|
| 78 | #define YYLP_EX_BR3 7 |
---|
| 79 | #define YYLP_BAD_CHAR 8 |
---|
| 80 | #define YYLP_MISSQUOT 9 |
---|
| 81 | #define YYLP_MISS_BR1 10 |
---|
| 82 | #define YYLP_MISS_BR2 11 |
---|
| 83 | #define YYLP_MISS_BR3 12 |
---|
| 84 | |
---|
[56459d] | 85 | #ifdef __MWERKS__ |
---|
[d336d53] | 86 | #ifdef __cplusplus |
---|
| 87 | extern "C" { |
---|
| 88 | #endif |
---|
| 89 | #ifdef macintosh |
---|
| 90 | int fileno(FILE *stream); |
---|
| 91 | FILE *fdopen(int filedes, char *type); |
---|
| 92 | long ftell(FILE *fp); |
---|
| 93 | long tell(int filedes); |
---|
| 94 | int isatty(int filedes); |
---|
[56459d] | 95 | #else |
---|
| 96 | int _fileno(FILE *stream); |
---|
| 97 | FILE *_fdopen(int filedes, char *type); |
---|
| 98 | long _ftell(FILE *fp); |
---|
| 99 | long _tell(int filedes); |
---|
| 100 | int _isatty(int filedes); |
---|
| 101 | #define fileno _fileno |
---|
| 102 | #define fdopen _fdopen |
---|
| 103 | #define ftell _ftell |
---|
| 104 | #define tell _tell |
---|
| 105 | #define isatty _isatty |
---|
[d336d53] | 106 | #endif /* macintosh */ |
---|
| 107 | #ifdef __cplusplus |
---|
| 108 | } |
---|
| 109 | #endif |
---|
[56459d] | 110 | #endif |
---|
[d336d53] | 111 | |
---|
[33d539] | 112 | #ifdef STANDALONE_PARSER |
---|
| 113 | procinfov pi; |
---|
| 114 | printpi(procinfov pi); |
---|
| 115 | pi_clear(procinfov pi); |
---|
| 116 | extern "C" { |
---|
| 117 | int yylpwrap(); |
---|
| 118 | } |
---|
| 119 | #else /* STANDALONE_PARSER */ |
---|
[56459d] | 120 | idhdl h0; |
---|
| 121 | # define pi IDPROC(h0) |
---|
[d636ad] | 122 | extern "C" |
---|
| 123 | { |
---|
| 124 | int yylpwrap(); |
---|
| 125 | } |
---|
[33d539] | 126 | extern libstackv library_stack; |
---|
| 127 | #endif /* STANDALONE_PARSER */ |
---|
| 128 | |
---|
[5480da] | 129 | #define SET_DEF_END(mode, pi, p) \ |
---|
| 130 | if ( mode == LOAD_LIB) pi->data.s.def_end = p; |
---|
| 131 | #define SET_HELP_START(mode, pi, p) \ |
---|
| 132 | if ( mode == LOAD_LIB) pi->data.s.help_start = p; \ |
---|
[33d539] | 133 | |
---|
[5480da] | 134 | #define SET_BODY_START(mode, pi, l, p) \ |
---|
| 135 | if ( mode == LOAD_LIB) { \ |
---|
| 136 | pi->data.s.body_lineno = l; \ |
---|
[33d539] | 137 | pi->data.s.body_start = p; \ |
---|
| 138 | } |
---|
[5480da] | 139 | #define SET_BODY_END(mode, pi, p) \ |
---|
| 140 | if ( mode == LOAD_LIB) { \ |
---|
| 141 | pi->data.s.body_end = p-1; \ |
---|
| 142 | pi->data.s.proc_end = p-1; \ |
---|
[33d539] | 143 | } |
---|
| 144 | |
---|
[5480da] | 145 | #define SET_EXAMPLE_START(mode, pi, l, p) \ |
---|
| 146 | if ( mode == LOAD_LIB) { \ |
---|
| 147 | pi->data.s.example_lineno = l; \ |
---|
[33d539] | 148 | pi->data.s.example_start = p; \ |
---|
| 149 | } |
---|
[5480da] | 150 | #define SET_PROC_END(mode, pi, p) \ |
---|
| 151 | if ( mode == LOAD_LIB) { \ |
---|
| 152 | pi->data.s.proc_end = p-1; \ |
---|
[33d539] | 153 | if(pi->data.s.body_end==0) pi->data.s.body_end = p-1; \ |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | #undef YY_DECL |
---|
[5480da] | 157 | #define YY_DECL int yylex(char *newlib, char *libfile, \ |
---|
| 158 | lib_style_types *lib_style, \ |
---|
[d336d53] | 159 | lp_modes mode) |
---|
[33d539] | 160 | |
---|
| 161 | #undef YY_INPUT |
---|
| 162 | #define YY_INPUT(buf,result,max_size) \ |
---|
| 163 | if ( ((result = libread( (yyin), (char *) buf, max_size )) < 0 ) \ |
---|
| 164 | && ferror( yyin ) ) \ |
---|
| 165 | YY_FATAL_ERROR( "read in flex scanner failed" ); |
---|
| 166 | |
---|
| 167 | #define YY_USER_INIT { \ |
---|
| 168 | BEGIN(header); \ |
---|
| 169 | yylplineno = 1; \ |
---|
| 170 | yylp_errno = 0; \ |
---|
[5480da] | 171 | *lib_style = OLD_LIBSTYLE; \ |
---|
[33d539] | 172 | strcpy(libnamebuf,"(**unknown version**)"); \ |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | #if 0 |
---|
| 176 | <pbody>proc[ \t]+{name} { |
---|
| 177 | printf("MISSING: PROC-cmd found. ERROR!\n"); } |
---|
| 178 | <pbody>example[ \t]*\n { |
---|
| 179 | yylplineno++; |
---|
| 180 | printf("MISSING: EXAMPLE-cmd found. ERROR!\n"); } |
---|
| 181 | #endif |
---|
| 182 | %} |
---|
| 183 | |
---|
| 184 | digit [0-9] |
---|
| 185 | letter [@a-zA-Z\'] |
---|
| 186 | name ({letter}({letter}*{digit}*_*)*|_) |
---|
| 187 | letters ({letter}|{digit}|[_./#%^*:,]) |
---|
| 188 | string ({letters}*) |
---|
| 189 | comment [\/][\/] |
---|
[795d89] | 190 | dolar [$] |
---|
[d336d53] | 191 | symbols [~!@#$%^&*()_+-={}\\\|\[\];:,<.>/\?\' \n\~\`\r] |
---|
[5480da] | 192 | aletters ({letter}|{digit}|{symbols}|{dolar}|{escquote}) |
---|
| 193 | strings ({aletters}*) |
---|
| 194 | quote [\"] |
---|
| 195 | escquote (\\\") |
---|
| 196 | taborspace [ \t] |
---|
| 197 | tos ({taborspace}*) |
---|
[33d539] | 198 | |
---|
| 199 | /* %start START */ |
---|
| 200 | |
---|
| 201 | %x header |
---|
| 202 | %x help |
---|
| 203 | %x libcmd |
---|
| 204 | %x pdef |
---|
| 205 | %x phead |
---|
| 206 | %x pbody |
---|
| 207 | %x pstr |
---|
| 208 | %x pexample |
---|
| 209 | %x pestr |
---|
| 210 | %x string |
---|
| 211 | %x comment |
---|
| 212 | |
---|
| 213 | %% |
---|
| 214 | (\/\/[^\n]*)|(^#![^\n]*)|([ \t]) { } |
---|
[5480da] | 215 | \/\/* { old_state = YYSTATE; BEGIN(comment); } |
---|
| 216 | |
---|
| 217 | info=+"\"" { old_state = YYSTATE; quote++; BEGIN(string); |
---|
| 218 | string_start = current_pos(yyleng); |
---|
| 219 | *lib_style = NEW_LIBSTYLE; |
---|
| 220 | last_cmd = LP_INFO; |
---|
| 221 | } |
---|
[33d539] | 222 | |
---|
[5480da] | 223 | (version=+{quote}+{strings}+{quote})|(version+{tos}+=+{quote}+{strings}+{quote})|(version+{tos}+=+{tos}+{quote}+{strings}+{quote})|(version=+{tos}+{quote}+{strings}+{quote}) { |
---|
| 224 | if ( mode != GET_INFO ) { |
---|
| 225 | make_version(yytext,1); |
---|
| 226 | #ifdef STANDALONE_PARSER |
---|
| 227 | printf("Version:%s;\n", libnamebuf); |
---|
| 228 | #else |
---|
[d336d53] | 229 | //text_buffer = mstrdup(libnamebuf); |
---|
| 230 | print_version(mode, libnamebuf); |
---|
[5480da] | 231 | #endif |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | |
---|
[c2da0a] | 235 | static { p_static=TRUE; } |
---|
[33d539] | 236 | |
---|
| 237 | (proc[ \t]+{name})|([ \t]proc[ \t]+{name}) { |
---|
[5480da] | 238 | char proc[256]; |
---|
| 239 | BEGIN(pdef); |
---|
[c2da0a] | 240 | #if YYLPDEBUG > 0 |
---|
[5480da] | 241 | printf("Newlib:%s\n", newlib); |
---|
[33d539] | 242 | #endif |
---|
| 243 | #ifdef STANDALONE_PARSER |
---|
[c2da0a] | 244 | if ( pi != NULL ) { |
---|
| 245 | printpi(pi); |
---|
| 246 | pi_clear(pi); |
---|
| 247 | } |
---|
| 248 | pi = (procinfo *)malloc(sizeof(procinfo)); |
---|
| 249 | iiInitSingularProcinfo(pi, newlib, yytext+5, yylplineno, |
---|
[5480da] | 250 | current_pos(0), p_static); |
---|
[33d539] | 251 | #else STANDALONE_PARSER |
---|
[5480da] | 252 | if( mode == LOAD_LIB) { |
---|
| 253 | proc[0]='\0'; |
---|
| 254 | sscanf( yytext, "%*[^p]proc %s", proc); |
---|
| 255 | if(strlen(proc)<1) sscanf( yytext, "proc %s", proc); |
---|
[56459d] | 256 | h0 = enterid( mstrdup(proc), myynest, PROC_CMD, |
---|
[5480da] | 257 | &idroot, FALSE ); |
---|
[56459d] | 258 | if (h0!=NULL) { |
---|
| 259 | iiInitSingularProcinfo(IDPROC(h0), newlib, proc, |
---|
[5480da] | 260 | yylplineno, current_pos(0),p_static); |
---|
| 261 | if (BVERBOSE(V_LOAD_PROC)) |
---|
| 262 | Warn( " proc %s loaded", proc ); |
---|
| 263 | } |
---|
[33d539] | 264 | #endif STANDALONE_PARSER |
---|
[5480da] | 265 | SET_DEF_END(mode, pi, current_pos(yyleng+1)); |
---|
[33d539] | 266 | #if YYLPDEBUG |
---|
[5480da] | 267 | printf("PROC %d at %d/%d: (%d) %s\n", p_static, |
---|
| 268 | yylplineno, current_pos(0), brace1, yytext); |
---|
[33d539] | 269 | #endif |
---|
[c2da0a] | 270 | p_static=FALSE; |
---|
| 271 | #ifndef STANDALONE_PARSER |
---|
[5480da] | 272 | } |
---|
[c2da0a] | 273 | #endif STANDALONE_PARSER |
---|
[5480da] | 274 | } |
---|
| 275 | example { |
---|
| 276 | BEGIN(pexample); |
---|
| 277 | SET_EXAMPLE_START(mode, pi, yylplineno, current_pos(0)); |
---|
[33d539] | 278 | #if YYLPDEBUG |
---|
[5480da] | 279 | printf("EXAMPLE at %d/%d (%d)\n", yylplineno, |
---|
| 280 | current_pos(0), brace1); |
---|
[33d539] | 281 | #endif |
---|
[5480da] | 282 | } |
---|
[33d539] | 283 | |
---|
[5480da] | 284 | LIB[ \t]+"\"" { quote++; |
---|
| 285 | BEGIN(libcmd); |
---|
| 286 | } |
---|
[33d539] | 287 | |
---|
[5480da] | 288 | <header>({comment}+{tos}+{dolar}+Id:+{string}+[^\n]*)|({comment}+{tos}+{dolar}+Header:+{string}+[^\n]*) { |
---|
| 289 | make_version(yytext, 0); |
---|
[d336d53] | 290 | //print_version(mode, ""); |
---|
| 291 | #if YYLPDEBUG > 1 |
---|
| 292 | printf("+(id)HEAD:%s\n", yytext); |
---|
| 293 | #endif |
---|
[5480da] | 294 | } |
---|
[d336d53] | 295 | <header>(^{comment}+[^\n]*) { |
---|
[33d539] | 296 | #if YYLPDEBUG > 1 |
---|
[d336d53] | 297 | printf("+(cmt)HEAD:%s\n", yytext); |
---|
[33d539] | 298 | #endif |
---|
[5480da] | 299 | } |
---|
[d336d53] | 300 | <header>(^#![^\n]*) { |
---|
[33d539] | 301 | #if YYLPDEBUG > 1 |
---|
[5480da] | 302 | printf("-HEAD:%s\n", yytext); |
---|
[33d539] | 303 | #endif |
---|
[5480da] | 304 | } |
---|
| 305 | <header>^proc\ { yyless(0); |
---|
[d336d53] | 306 | //print_version(mode, libfile); |
---|
[5480da] | 307 | BEGIN(INITIAL); |
---|
| 308 | yymore(); |
---|
| 309 | } |
---|
| 310 | <header>(info=\")|(version=\")|(version+{tos}+=\")|(version+{tos}+=+{tos}+\")|(version=+{tos}+\") { yyless(0); |
---|
| 311 | *lib_style = NEW_LIBSTYLE; |
---|
| 312 | BEGIN(INITIAL); |
---|
| 313 | yymore(); |
---|
| 314 | } |
---|
| 315 | |
---|
[33d539] | 316 | <header>^LIB[ \t]+"\"" { quote++; |
---|
[d336d53] | 317 | //print_version(mode, libfile); |
---|
[5480da] | 318 | BEGIN(libcmd); |
---|
| 319 | } |
---|
| 320 | <header>\n { yylplineno++; } |
---|
| 321 | <header>. { |
---|
[33d539] | 322 | #if YYLPDEBUG > 1 |
---|
[5480da] | 323 | printf(" HEAD:%s\n", yytext); |
---|
[33d539] | 324 | #endif |
---|
[d336d53] | 325 | //print_version(mode, libfile); |
---|
[5480da] | 326 | BEGIN(help); |
---|
| 327 | } |
---|
[d336d53] | 328 | <help>(^{comment}+[^\n]*) { |
---|
[33d539] | 329 | #if YYLPDEBUG > 1 |
---|
[5480da] | 330 | printf(" HELP:%s\n", yytext); |
---|
[33d539] | 331 | #endif |
---|
[5480da] | 332 | BEGIN(INITIAL); } |
---|
[d336d53] | 333 | <help>(^#![^\n]*) { |
---|
[33d539] | 334 | #if YYLPDEBUG > 1 |
---|
[5480da] | 335 | printf(" HELP:%s\n", yytext); |
---|
[33d539] | 336 | #endif |
---|
[5480da] | 337 | BEGIN(INITIAL); |
---|
| 338 | } |
---|
[d336d53] | 339 | <help>(info=\")|(version=\")|(version+{tos}+=\")|(version+{tos}+=+{tos}+\")|(version=+{tos}+\") { yyless(0); |
---|
| 340 | *lib_style = NEW_LIBSTYLE; |
---|
| 341 | BEGIN(INITIAL); |
---|
| 342 | yymore(); |
---|
| 343 | } |
---|
[5480da] | 344 | <help>^proc\ { |
---|
| 345 | yyless(0); |
---|
| 346 | //printf("2) proc found.\n"); |
---|
| 347 | BEGIN(INITIAL); |
---|
| 348 | yymore(); |
---|
| 349 | } |
---|
[33d539] | 350 | <help>^LIB[ \t]+"\"" { quote++; |
---|
[5480da] | 351 | BEGIN(libcmd); |
---|
| 352 | } |
---|
[33d539] | 353 | |
---|
[d336d53] | 354 | <help>\n { yylplineno++; } |
---|
[5480da] | 355 | <help>. { |
---|
[33d539] | 356 | #if YYLPDEBUG > 1 |
---|
[5480da] | 357 | printf("-HELP:%s\n", yytext); |
---|
[33d539] | 358 | #endif |
---|
[5480da] | 359 | } |
---|
[33d539] | 360 | |
---|
| 361 | |
---|
| 362 | <libcmd>{string}"\"" { quote--; |
---|
[5480da] | 363 | yytext[yyleng-1] = '\0'; |
---|
[33d539] | 364 | #ifndef STANDALONE_PARSER |
---|
[5480da] | 365 | if ( mode == LOAD_LIB ) { |
---|
| 366 | library_stack->push(newlib, yytext); |
---|
| 367 | } |
---|
[33d539] | 368 | #endif /* STANDALONE_PARSER */ |
---|
| 369 | #if YYLPDEBUG |
---|
[5480da] | 370 | printf("LIB:'%s'\n", yytext); |
---|
[33d539] | 371 | #endif |
---|
[5480da] | 372 | BEGIN(INITIAL); |
---|
| 373 | } |
---|
[33d539] | 374 | |
---|
[5480da] | 375 | <pdef>[ \t] { } |
---|
| 376 | <pdef>\( { |
---|
| 377 | brace2++; |
---|
[33d539] | 378 | #if YYLPDEBUG |
---|
[5480da] | 379 | printf("%s", yytext); |
---|
[33d539] | 380 | #endif |
---|
[5480da] | 381 | } |
---|
| 382 | <pdef>\) { |
---|
| 383 | brace2--; |
---|
[33d539] | 384 | #if YYLPDEBUG |
---|
[5480da] | 385 | printf(">%s<\n", yytext); |
---|
| 386 | printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
[33d539] | 387 | #endif |
---|
[5480da] | 388 | if(brace2<=0) { |
---|
[33d539] | 389 | #if YYLPDEBUG |
---|
[5480da] | 390 | printf("BEGIN(phead){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
[33d539] | 391 | #endif |
---|
[5480da] | 392 | SET_DEF_END(mode, pi, current_pos(yyleng)); |
---|
| 393 | SET_HELP_START(mode, pi, current_pos(yyleng)); |
---|
| 394 | BEGIN(phead); |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | <pdef>"{" { |
---|
| 398 | if(brace2>0) { |
---|
[33d539] | 399 | #if YYLPDEBUG |
---|
[5480da] | 400 | printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
[33d539] | 401 | #endif |
---|
[5480da] | 402 | yylp_errno = YYLP_DEF_BR2; |
---|
| 403 | return(1); |
---|
| 404 | } else { |
---|
| 405 | brace1++; BEGIN(pbody); |
---|
| 406 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
| 407 | } |
---|
| 408 | } |
---|
[d336d53] | 409 | <pdef>\n { yylplineno++; |
---|
| 410 | if(brace2<=0) { |
---|
[33d539] | 411 | #if YYLPDEBUG |
---|
[d336d53] | 412 | printf("BEGIN(phead-2){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
[33d539] | 413 | #endif |
---|
[d336d53] | 414 | SET_HELP_START(mode, pi, current_pos(0)); |
---|
| 415 | BEGIN(phead); |
---|
| 416 | } |
---|
| 417 | } |
---|
[5480da] | 418 | <pdef>. { |
---|
| 419 | if(brace2<=0) { |
---|
| 420 | SET_HELP_START(mode, pi, current_pos(0)); |
---|
| 421 | BEGIN(phead); |
---|
| 422 | } |
---|
| 423 | } |
---|
[33d539] | 424 | |
---|
| 425 | <phead>"\\{" { } |
---|
| 426 | <phead>"{" { |
---|
| 427 | brace1++; BEGIN(pbody); |
---|
| 428 | #if YYLPDEBUG |
---|
| 429 | printf("BEGIN(pbody){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
| 430 | #endif |
---|
[5480da] | 431 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
[33d539] | 432 | #if YYLPDEBUG |
---|
| 433 | printf("BODY at %d/%d", yylplineno, current_pos(0)); |
---|
| 434 | #endif |
---|
| 435 | } |
---|
[d336d53] | 436 | <phead>\n { yylplineno++; } |
---|
[33d539] | 437 | <phead>. { } |
---|
| 438 | |
---|
[d336d53] | 439 | <pbody>({comment}[^\n]*) { } |
---|
[33d539] | 440 | <pbody>"\"" { quote++; old_state = YYSTATE; |
---|
| 441 | BEGIN(string); /* printf("%s", yytext); */ |
---|
| 442 | } |
---|
| 443 | <pbody>"{" { |
---|
| 444 | brace1++; |
---|
| 445 | #if YYLPDEBUG |
---|
| 446 | printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext); |
---|
| 447 | #endif |
---|
| 448 | } |
---|
| 449 | <pbody>"}" { |
---|
| 450 | #if YYLPDEBUG |
---|
| 451 | printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext); |
---|
| 452 | #endif |
---|
| 453 | brace1--; |
---|
| 454 | if(brace2>0) { |
---|
| 455 | yylp_errno = YYLP_BODY_BR2; |
---|
| 456 | return(1); |
---|
| 457 | } |
---|
| 458 | if(brace3>0) { |
---|
| 459 | yylp_errno = YYLP_BODY_BR3; |
---|
| 460 | return(1); |
---|
| 461 | } |
---|
| 462 | if(brace1<=0) { |
---|
[5480da] | 463 | SET_BODY_END(mode, pi, current_pos(yyleng)); |
---|
| 464 | SET_PROC_END(mode, pi, current_pos(yyleng)); |
---|
[33d539] | 465 | #if YYLPDEBUG |
---|
| 466 | printf("-%d\n", current_pos(0)); |
---|
| 467 | #endif |
---|
| 468 | BEGIN(INITIAL); |
---|
| 469 | } |
---|
| 470 | } |
---|
| 471 | <pbody>"(" { |
---|
| 472 | brace2++; /* printf("%s", yytext); */ |
---|
| 473 | } |
---|
| 474 | <pbody>")" { |
---|
| 475 | brace2--; /* printf("%s", yytext); */ |
---|
| 476 | if(brace2<0) { |
---|
| 477 | yylp_errno = YYLP_BODY_TMBR2; |
---|
| 478 | return(1); |
---|
| 479 | } |
---|
| 480 | } |
---|
| 481 | <pbody>"[" { |
---|
| 482 | brace3++; /* printf("%s", yytext); */ |
---|
| 483 | } |
---|
| 484 | <pbody>"]" { |
---|
| 485 | brace3--; /* printf("%s", yytext); */ |
---|
| 486 | if(brace3<0) { |
---|
| 487 | yylp_errno = YYLP_BODY_TMBR3; |
---|
| 488 | return(1); |
---|
| 489 | } |
---|
| 490 | } |
---|
| 491 | <pbody>\n { yylplineno++; } |
---|
| 492 | <pbody>. { } |
---|
| 493 | |
---|
| 494 | <string>"\"" { quote--; |
---|
[5480da] | 495 | copy_string(mode); |
---|
| 496 | last_cmd = LP_NONE; |
---|
[33d539] | 497 | BEGIN(old_state); /* printf("%s", yytext); */ |
---|
| 498 | } |
---|
[5480da] | 499 | <string>(\\\\)|(\\\") { } |
---|
[33d539] | 500 | <string>\n { yylplineno++; } |
---|
| 501 | <string>. { } |
---|
| 502 | |
---|
[d336d53] | 503 | <pexample>(\/\/[^\n]*) { } |
---|
[33d539] | 504 | <pexample>"\"" { quote++; old_state = YYSTATE; |
---|
| 505 | BEGIN(string); /* printf("%s", yytext); */ |
---|
| 506 | } |
---|
| 507 | <pexample>"{" { |
---|
| 508 | brace1++; /* printf("(%d)%s", brace1, yytext); */ |
---|
| 509 | } |
---|
| 510 | <pexample>"}" { |
---|
| 511 | brace1--; /* printf("(%d)%s", brace1, yytext); */ |
---|
| 512 | if(brace1<=0) { |
---|
| 513 | if(brace2>0) { yylp_errno=YYLP_EX_BR2; return(1); } |
---|
| 514 | if(brace3>0) { yylp_errno=YYLP_EX_BR3; return(1); } |
---|
| 515 | BEGIN(INITIAL); |
---|
[5480da] | 516 | SET_PROC_END(mode, pi, current_pos(yyleng)); |
---|
[33d539] | 517 | } |
---|
| 518 | } |
---|
| 519 | <pexample>"(" { |
---|
| 520 | brace2++; /* printf("%s", yytext); */ |
---|
| 521 | } |
---|
| 522 | <pexample>")" { |
---|
| 523 | brace2--; /* printf("%s", yytext); */ |
---|
| 524 | } |
---|
| 525 | <pexample>"[" { |
---|
| 526 | brace3++; /* printf("%s", yytext); */ |
---|
| 527 | } |
---|
| 528 | <pexample>"]" { |
---|
| 529 | brace3--; /* printf("%s", yytext); */ |
---|
| 530 | } |
---|
| 531 | <pexample>\n { yylplineno++; } |
---|
| 532 | <pexample>. { } |
---|
| 533 | |
---|
| 534 | <pestr>"\"" { quote--; |
---|
| 535 | BEGIN(pexample); /* printf("%s", yytext); */ |
---|
| 536 | } |
---|
| 537 | <pestr>\\\\ { } |
---|
| 538 | <pestr>\\\" { } |
---|
| 539 | <pestr>\n { yylplineno++; } |
---|
| 540 | <pestr>. { } |
---|
| 541 | |
---|
| 542 | <comment>\*\/ { BEGIN(old_state); } |
---|
| 543 | <comment>\n { yylplineno++; } |
---|
| 544 | <comment>. { } |
---|
| 545 | |
---|
| 546 | \n { yylplineno++; } |
---|
[c2da0a] | 547 | ; { p_static = FALSE; |
---|
[33d539] | 548 | #if YYLPDEBUG |
---|
| 549 | printf("%s", yytext); |
---|
| 550 | #endif |
---|
| 551 | } |
---|
[c2da0a] | 552 | . { p_static = FALSE; |
---|
[33d539] | 553 | yylp_errno = YYLP_BAD_CHAR; |
---|
| 554 | #if YYLPDEBUG |
---|
[5480da] | 555 | printf("[%s]", yytext); |
---|
[33d539] | 556 | #endif |
---|
| 557 | return(1); |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | %% |
---|
| 561 | |
---|
| 562 | int current_pos(int i) |
---|
| 563 | { |
---|
| 564 | return(i+offset+(int)(yytext-yylp_buffer_start)); |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | int libread(FILE* f, char* buf, int max_size) |
---|
| 568 | { int rc; |
---|
| 569 | |
---|
| 570 | offset = ftell(f); |
---|
| 571 | rc = fread( buf, 1, max_size, f ); |
---|
[d336d53] | 572 | #if YYLPDEBUG >2 |
---|
| 573 | printf("fread: %d of %d\n", rc, max_size); |
---|
| 574 | #endif |
---|
| 575 | #ifdef macintosh |
---|
| 576 | char *p = buf, *q; |
---|
| 577 | while( (q = strchr(p, '\r')) != NULL) { |
---|
| 578 | *q = '\n'; |
---|
| 579 | p = q; |
---|
| 580 | } |
---|
| 581 | #endif |
---|
[33d539] | 582 | yylp_buffer_start = buf; |
---|
| 583 | return rc; |
---|
| 584 | } |
---|
| 585 | |
---|
| 586 | extern "C" { |
---|
| 587 | int yylpwrap() { |
---|
| 588 | //printf("======================= YYWRAP ====================\n"); |
---|
| 589 | if(brace1>0) { yylp_errno=YYLP_MISS_BR1; } |
---|
| 590 | if(brace2>0) { yylp_errno=YYLP_MISS_BR2; } |
---|
| 591 | if(brace3>0) { yylp_errno=YYLP_MISS_BR3; } |
---|
| 592 | if(quote>0) { yylp_errno=YYLP_MISSQUOT; } |
---|
| 593 | /* printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3);/**/ |
---|
| 594 | if(feof(yyin)) return 1; else return 0; |
---|
| 595 | } |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | void reinit_yylp() |
---|
| 599 | { |
---|
| 600 | brace1 = 0; |
---|
| 601 | brace2 = 0; |
---|
| 602 | brace3 = 0; |
---|
| 603 | quote = 0; |
---|
| 604 | yy_init=1; |
---|
| 605 | yy_delete_buffer(yy_current_buffer); |
---|
| 606 | } |
---|
| 607 | |
---|
[5480da] | 608 | void make_version(char *p,int what) |
---|
| 609 | { |
---|
| 610 | char ver[10]; |
---|
| 611 | char date[16]; |
---|
| 612 | ver[0]='?'; ver[1]='.'; ver[2]='?'; ver[3]='\0'; |
---|
| 613 | date[0]='?'; date[1]='\0'; |
---|
| 614 | if(what) sscanf(p,"%*[^=]= %*s %*s %10s %16s",ver,date); |
---|
| 615 | else sscanf(p,"// %*s %*s %10s %16s",ver,date); |
---|
| 616 | strcpy(libnamebuf,"("); |
---|
| 617 | strcat(libnamebuf,ver); |
---|
| 618 | strcat(libnamebuf,","); |
---|
| 619 | strcat(libnamebuf,date); |
---|
| 620 | strcat(libnamebuf,")"); |
---|
| 621 | // printf("ID=(%d)%s; \n", what, p); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | void copy_string(lp_modes mode) |
---|
| 625 | { |
---|
[c2da0a] | 626 | #ifndef STANDALONE_PARSER |
---|
[5480da] | 627 | if((last_cmd == LP_INFO)&&(mode == GET_INFO)) { |
---|
| 628 | long current_location = ftell(yylpin); |
---|
| 629 | int len = (int)(current_pos(0) - string_start); |
---|
| 630 | fseek(yylpin, string_start, SEEK_SET); |
---|
[d336d53] | 631 | text_buffer = (char *)AllocL(len+1); |
---|
[5480da] | 632 | fread(text_buffer, len, 1, yylpin); |
---|
| 633 | fseek(yylpin, current_location, SEEK_SET); |
---|
| 634 | } |
---|
[c2da0a] | 635 | #endif /* STANDALONE_PARSER */ |
---|
[5480da] | 636 | } |
---|
| 637 | |
---|
[33d539] | 638 | void print_init() |
---|
| 639 | { |
---|
| 640 | printf("Init=%d\n", yy_init); |
---|
| 641 | } |
---|
| 642 | |
---|
[5480da] | 643 | void print_version(lp_modes mode, char *p) |
---|
[33d539] | 644 | { |
---|
| 645 | #ifdef STANDALONE_PARSER |
---|
[5480da] | 646 | //printf("loading %s%s", p, libnamebuf); |
---|
[33d539] | 647 | #else |
---|
[5480da] | 648 | if ( mode == LOAD_LIB ) { |
---|
[d336d53] | 649 | if (BVERBOSE(V_LOAD_LIB) && p!=NULL ) Print(" %s...", p); |
---|
| 650 | //Warn( "loading %s%s", p, libnamebuf); |
---|
[5480da] | 651 | } |
---|
[33d539] | 652 | #endif |
---|
| 653 | } |
---|
| 654 | |
---|
| 655 | #ifdef STANDALONE_PARSER |
---|
| 656 | main( int argc, char *argv[] ) |
---|
| 657 | { |
---|
[5480da] | 658 | lib_style_types lib_style; |
---|
[33d539] | 659 | ++argv, --argc; /* skip over program name */ |
---|
| 660 | if ( argc > 0 ) |
---|
[5480da] | 661 | yyin = fopen( argv[0], "rb" ); |
---|
[33d539] | 662 | else |
---|
| 663 | yyin = stdin; |
---|
| 664 | |
---|
| 665 | printf( " %-15s %20s %s,%s %s,%s %s,%s\n", "Library", |
---|
| 666 | "function", "line", "start-eod", "line", "body-eop", |
---|
| 667 | "line", "example-eoe"); |
---|
[5480da] | 668 | yylplex(argv[0], argv[0], &lib_style); |
---|
[33d539] | 669 | if(yylp_errno) { |
---|
[c2da0a] | 670 | printf("ERROR accured: [%d] ", yylp_errno); |
---|
[33d539] | 671 | printf(yylp_errlist[yylp_errno], yylplineno); |
---|
| 672 | printf("\n"); |
---|
| 673 | } |
---|
| 674 | else if(pi!=NULL) printpi(pi); |
---|
| 675 | } |
---|
| 676 | |
---|
| 677 | #endif /* STANDALONE_PARSER */ |
---|
| 678 | #endif /* HAVE_LIBPARSE */ |
---|