%{ /* sd_lex.l definition of lexical box for Etak IIS stack definition language, sd. */ /* The following passes up the strings as the value for the token */ #define LMV yylval=(charptr)strcpy(malloc(strlen(yytext)+1),yytext) /* This is set so high for the major unputs we do when we substitute a define. */ #undef YYLMAX #define YYLMAX 5000 %} %% /* The next line sets the source */ yyin = sd_fd; printf("LEX: sd_fd is %d\n",sd_fd); /* All that follows is handled by lex. */ [ \t]* { /* spaces ignored */ printf("LEX: space\n");} \n { /* linefeeds ignored */ printf("LEX: linefeed\n");} "//"[^\n]*$ { /* comments ignored */ printf("Comment %s\n",yytext);} [oO][tT][hH][eE][rR] { printf("LEX: other\n"); LMV; return OTHER;} [iI][nN][cC][lL][uU][dD][eE] { printf("LEX: include\n"); LMV; return INCLUDE; } [dD][eE][fF][iI][nN][eE] { printf("LEX: define\n"); LMV; return DEFINE; } [v^][^,)]+ { printf("LEX: link\n"); LMV; return LINK; } "$"[^,)(\-#}{\n \t]+ { int i,j,len; for (i=0; i< sd_defs_index; i++) { if (!strcmp(sd_defs[i].name,&yytext[1])) break; } if (i==sd_defs_index) { printf("Bad or undefined macro used, %s. Exiting. \n", yytext); exit(0); } printf("LEX: Substituting: %s\n",sd_defs[i].text); len = strlen(sd_defs[i].text); /* One "unputs" from back to front, so that "input" retrieves it front to back */ for (j=len-1; j >= 0; j--){ unput(sd_defs[i].text[j]); } printf("LEX: Finished substitution, %s\n", yytext); } [^,)(\-#}{\n \t]+ { printf("LEX: NAME, %s\n", yytext); LMV; return NAME; } . { /* pass other characters through */ printf("LEX: other char %s\n", yytext); return yytext[0]; } %% /* yywrap is automatically called upon an end-of-file. It gives us the option of telling lex to stop or giving it new input. In the case below, we check to see if we have been processing an include file (which we set in the yacc code, yyparse, and passed through the "yyin = sd_fd" line above). If so, we continue parsing with the original file. Note that includes can't have includes in this case. In fact, they may only contain defines. */ yywrap() { if (sd_temp_fd) { yyin = sd_fd = sd_temp_fd; sd_temp_fd = 0; return 0; } return 1; }