home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************
- *
- * Copyright (c) 1993 Ke Jin
- *
- * Permission to use, copy, modify, and distribute
- * this software and its documentation without fee
- * is granted, provided that the author's name and
- * this copyright notice are retained.
- *
- * -------------------------------------------------------------
- *
- * dfcscan.h --- the lexical scaner of defunc
- *
- * private variable : yyexpr;
- * yyexprlen;
- * yytext;
- * yypos;
- *
- * private function : yylex();
- *
- ****************************************************************/
-
- #ifndef _DFCSCAN_H
- #define _DFCSCAN_H
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include "dfcsymtable.h"
-
- #ifdef __cplusplus
- extern "C" { /* for c++ */
- #endif
-
- static char* yyexpr;
- static int yyexprlen;
- static char* yytext;
- static int yypos;
-
- #if NeedFunctionPrototypes
- static int yylex(void)
- #else
- static int yylex()
- #endif
- {
- char c;
- int i;
-
- Symbol_record* ptr;
-
- /* --- [ \t] do nothing --------------------------------- */
- for(;yypos<yyexprlen;yypos++)
- {
- c=yyexpr[yypos];
- if(c==' '||c=='\t') continue;
- break;
- }
-
- /* --- {number} return token CONST with value ----------- */
- if(c=='.'||isdigit(c))
- {
- sscanf(yyexpr+yypos, "%lf", &(yylval.value));
- for(;yypos<=yyexprlen;yypos++)
- {
- c=yyexpr[yypos];
- if(c=='.'||isdigit(c)) continue;
- break;
- }
- return CONST;
- }
-
- /* --- {symbol} return token VAR or FNCT with fnctptr --- */
- if(isalpha(c))
- {
- yytext = (char*)malloc(sizeof(char)*(yyexprlen-yypos+1));
- if(yytext==0)
- {
- perror("malloc for token text in module scaner");
- exit(1);
- }
-
- for(i=0;yypos<=yyexprlen;yypos++, i++)
- {
- c=yyexpr[yypos];
- if(isalnum(c))
- {
- yytext[i]=c;
- continue;
- }
- yytext[i]='\0';
- break;
- }
-
- ptr = (Symbol_record*)getsym(yytext);
- if(ptr==0) /* symbol not in table */
- {
- strncpy(yylval.name, yytext, 32);
- return SYM;
- }
-
- switch (ptr->type)
- {
- case arg_symbol:
- yylval.argidx = ptr->content.argidx;
- return ARG;
-
- case fnct_symbol:
- yylval.fnctptr = ptr->content.fnctptr;
- return FNCT;
-
- case const_symbol:
- yylval.value = ptr->content.value;
- return CONST;
- }
- }
-
- /* ------ append a '\n' on end ----------------- */
- if(yypos==yyexprlen) return '\n';
-
- yypos++;
- /* ------ return other characters -------------- */
- return c;
- };
-
- #ifdef __cplusplus
- } /* end for c++ */
- #endif
-
- #endif /* _DFCSCAN_H */
-