home *** CD-ROM | disk | FTP | other *** search
- /*
- * Lexical Analyzer for SPIKE
- */
- alpha = [A-Za-z]; /* Letters */
- digit = [0-9]; /* Digits */
- prefix = [-[-_.:>+*&%<={}$!|]; /* Prefixes */
- join = [-[-_.:>/*+&%<={}$!|]; /* Connectors */
- alphanum = (alpha|digit|prefix)(alpha|digit|join)*; /* Alphnumeric sequence */
- text = [ -~]; /* All printing characters */
- white = [\r\t\b ]; /* White space */
- eol = [\n]; /* End of the line */
- illegal = [\0-\377]; /* Junk */
-
- %{
- #include "sys$library:stdio.h"
- #include "sys$library:math.h"
- #include "sys$library:ctype.h"
-
- #define lexreturn(x) {return(x);}
-
- char lastyytext[1000],yytext[1000]= "";
- int yyival;
- float yyfval;
-
- STRING uc_command[] = {"CREATE","LOAD","STORE","OBJECT","INSTAN","OBJSYN",
- "DELETE","RENAME","PRINT","PRINTO","STOREO","LOADO",
- "SLOT","SLOTSYN","RENAMES","DELETES","PRINTS","FACET",
- "DELETEF","MSG","RMSG","NOTICE","PUT","GET","APPEND",
- "REMOVE","TOG","STOREG","PUTUP","GETUP","EXIT",
- "KBMS_OPEN_KB","KBMS_CLOSE_KB",
- "KBMS_CREATE_INDEX","KBMS_DEFINE_INDEX",
- "KBMS_FETCH_OBJECTS",
- "COLLECT","STATS","DO","XLISP","XTESTX",""};
-
- STRING lc_command[] = {"create","load","store","object","instan","objsyn",
- "delete","rename","print","printo","storeo","loado",
- "slot","slotsyn","renames","deletes","prints","facet",
- "deletef","msg","rmsg","notice","put","get","append",
- "remove","tog","storeg","putup","getup","exit",
- "kbms_open_kb","kbms_close_kb",
- "kbms_create_index","kbms_define_index",
- "kbms_fetch_objects",
- "collect","stats","do","xlisp","xtestx",""};
-
- INTEGER command_token[] = {CKB,LKB,SKB,OBJ,INJ,SYJ,DBJ,RNJ,PBJ,PBJ,SBJ,LBJ,
- SLT,SYT,RNT,DLT,PLT,FAC,DAC,MSG,RMG,NKB,PUT,GET,
- APP,REM,TOG,STG,PUP,GUP,EXT,
- KOP,KCL,KCI,KDI,KFO,
- GBG,MST,DOT,LSP,TST};
-
- %}
- %%
-
- alphanum {{char *p; BOOLEAN digitp, floatp, alphap; INTEGER i;
- digitp = floatp = alphap = FALSE;
- strcpy(lastyytext, yytext);
- gettoken(yytext, sizeof(yytext));
- if(((i = utl_index(lc_command, yytext)) != -1) ||
- ((i = utl_index(uc_command, yytext)) != -1))
- return(command_token[i]);
- for(p = yytext; *p; p++) {
- /*printf("%c(%o)",*p,*p);*/
- if(isdigit(*p)) digitp = TRUE;
- else if(*p == '.') floatp = TRUE;
- else alphap = TRUE;
- }
- if(alphap) {
- /*printf("'%s' is TEXT\n", yytext);*/
- lexreturn(TEXT);
- } else if(!floatp) {
- yyival = atoi(yytext);
- /*sscanf(yytext,"%d", &yyival);*/
- /*printf("'%s' is ICON with value %d\n", yytext, yyival);*/
-
- lexreturn(ICON);
- } else {
- yyfval = atof(yytext);
- /*sscanf(yytext, "%f", &yyfval);*/
- /*printf("'%s' is FCON with value %f\n", yytext, yyfval);*/
-
- lexreturn(FCON);
- }}}
-
- "\""(text)*"\"" {strcpy(lastyytext, yytext);
- gettoken(yytext, sizeof(yytext));
- strcpy(yytext, yytext+1);
- yytext[strlen(yytext)-1] = '\0';
- lexreturn(STNG);
- }
-
- "'" {strcpy(lastyytext, yytext);
- gettoken(yytext, sizeof(yytext));
- lexreturn(TEXT);
- }
-
- "(" {return(LPR);}
-
- ")" {return(RPR);}
-
- eol {return(EOL);}
-
- "/*" {comment("*/");}
-
- white(white)* {return(LEXSKIP);}
-
- %%
-
- int lexgetc()
- {
- static BOOLEAN virgin = TRUE;
- static int newlines = 2;
- register int c;
-
- if(virgin) {
- printf(" --- SPIKE version 1.7.X ---\n");
- virgin = FALSE;
- }
-
- if(*kbname == 0 && SysKB && SysKB->kbkey)
- strcpy(kbname, SysKB->kbkey);
-
- if(indirect) {
- if((c = getc(iop)) != EOF) {
- if(c == '\\') {
- while((c = getc(iop)) != '\n');
- return(lexgetc());
- } else
- return(c);
- } else {
- if(--indirect)
- rewind(iop);
- else
- fclose(iop);
- return(' ');
- }
- }
-
- if(newlines == 1) {
- newlines = 2;
- return(' ');
- } else if(newlines == 2)
- printf("%s>", kbname);
-
- c = getc(lexin);
-
- if(c == -1)
- exit();
-
- if(c == '\n')
- newlines = 1;
- else
- newlines = 0;
-
- if(c == '\\') {
- while((c = getc(lexin)) != '\n');
- return(lexgetc());
- } else
- return(c);
- }
-