%{ /* sdl_l.l lex definition for stack definition language. */ #undef output #undef input #define output(c) #define YY_INPUT(buf,result,max_size) \ { \ int c = sdl_getc(); \ result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \ } #if 0 #define input() (\ (\ (\ yytchar=\ yysptr>yysbuf?\ U(*--yysptr)\ :sdl_getc()\ ) == 10?\ (yylineno++,yytchar)\ :yytchar\ ) == (unsigned char)EOF?\ 0\ :yytchar\ ) #endif /* The following passes up the strings as the value for the token */ #define LMV strncpy(yylval.text,yytext,((yyleng < MAX_TEXT_LENGTH) ? (yyleng+1) : MAX_TEXT_LENGTH)) #define RPT %} %% [ \t\n]* { int i; /* spaces ignored */ for (i=0;yytext[i];i++){ # ifdef SD_DEBUG_LEX printf("%c",yytext[i]); # endif if (yytext[i] == '\n') { file_lineno++; # ifdef SD_DEBUG_LEX printf("%5d ",file_lineno); # endif } } RPT; } "//"[^\n]*$ { /* comments ignored*/ # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; } -?[0-9]+ { # ifdef SD_DEBUG_LEX printf(yytext); # endif strcpy(yylval.value,yytext); LMV; RPT; return NUMBER; } [cC][iI][fF]"_"[oO][Nn] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return CIF_ON; } [cC][iI][fF]"_"[oO][fF][fF] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return CIF_OFF; } [iI][nN][dD][eE][xX] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return INDEX; } [Ss][yY][mM]"_"[sS][iI][zZ][eE] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return SYM_SIZE; } [gG][iI][vV][eE][nN]"_"[nN][eE][wW] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return GIVEN_NEW; } [cC][aA][rR][dD]"_"[bB][oO][oO][kK] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return CARD_BOOK; } [bB][oO][oO][kK]"_"[eE][nN][tT][rR][iI][eE][sS] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return BOOK_ENTRIES; } [rR][eE][pP][eE][aA][tT]"_"[dD][aA][tT][aA] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return REPEAT_DATA; } [lL][oO][sS][eE]"_"[cC][uU][rR][rR][eE][nN][tT]"_"[eE][nN][tT][rR][yY] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return LOSE_CURRENT_ENTRY; } [nN][eE][xX][tT]"_"[cC][aA][rR][dD] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return NEXT_CARD; } [sS][kK][iI][pP] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return SKIP; } [wW][hH][eE][nN] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return WHEN; } [lL][iI][nN][kK] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return LINK; } [sS][tT][rR][cC][aA][tT] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return STRCAT; } [sS][uU][bB][sS][tT][rR] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return SUBSTR; } [pP][rR][iI][nN][tT] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return PRINT; } [sS][eE][rR]"_"[wW][rR][iI][tT][eE] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return SER_WRITE; } [lL][nN][kK]"_"[wW][rR][iI][tT][eE] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return LNK_WRITE; } [wW][pP][gG]"_"[wW][rR][iI][tT][eE] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return WPG_WRITE; } [tT][oO][cC]"_"[wW][rR][iI][tT][eE] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return TOC_WRITE; } [fF][iI][nN][dD]"_"[uU][nN][iI][tT] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return FIND_UNIT; } [rR][iI][cC][hH]"_"[lL][iI][nN][eE][sS] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return RICH_LINES; } [nN][oO][rR][mM][aA][lL][iI][zZ][eE] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return NORMALIZE; } "BEGIN_STACK" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return BEGIN_STACK; } "NEW_CARD" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return NEW_CARD; } "END" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return END; } [Ee][Rr][Rr][oO][rR] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return ERROR; } "if" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return IF; } "USE" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return USE; } "page" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return PAGE; } "strcmp" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return STRCMP; } "strlen" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return STRLEN; } [sS][tT][rR][cC][pP][yY] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return STRCPY; } "exist" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return EXIST; } "AFTER_ALL" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return AFTER_ALL; } [rR]"epeat" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return REPEAT; } "AFTER_STACK" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return AFTER_STACK; } [sS][oO][rR][tT]"_"[bB][yY] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return SORT_BY; } "NEW_ENTRY" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return NEW_ENTRY; } "USE_RPL" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return USE_RPL; } "break" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return BREAK; } [cC][Oo][Nn][Tt][Ii][Nn][Uu][Ee] { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return CONTINUE; } "<-" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return RPL_ASSIGN; } ">=" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return GTE; } "<=" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return LTE; } "==" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return EQ; } "!=" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return NEQ; } "^" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return TO_THE; } "||" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return OR; } "&&" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return AND; } "++" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return PLUS_PLUS; } "--" { # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return MINUS_MINUS; } \"[^\"\n]*\" {/* " */ int len; /* copy while stripping quotes */ len = strlen(yytext); LMV; strcpy(yylval.value,&yytext[1]); yylval.value[len-2] = '\0'; # ifdef SD_DEBUG_LEX printf(yytext); # endif RPT; return STRING; } [a-zA-Z_:$][a-zA-Z_0-9]* { LMV; RPT; # ifdef SD_DEBUG_LEX printf(yytext); # endif return NAME; } . { /* pass other characters through */ # ifdef SD_DEBUG_LEX printf(yytext); if (yytext[0] < 32) { printf("\npassing control code %d\n",yytext[0]); } # endif RPT; 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. */ void pop_stack(void); yywrap() { return 1; } unsigned char rptbuf[7]; unsigned char given_buf[11]; unsigned char card_buf[11]; unsigned char book_buf[13]; unsigned char sdl_getc() { unsigned char c; c = fgetc(sdl_fd); memcpy(&rptbuf[0],&rptbuf[1],5); rptbuf[5]=c; rptbuf[6]=0; if (!strcasecmp(rptbuf,"repeat")) { p1 = ftell(sdl_fd)-6; } memcpy(&given_buf[0],&given_buf[1],8); given_buf[8]=c; given_buf[9]=0; if (!strcasecmp(given_buf,"given_new")) { p2 = ftell(sdl_fd)-9; } memcpy(&card_buf[0],&card_buf[1],8); card_buf[8]=c; card_buf[9]=0; if (!strcasecmp(card_buf,"card_book")) { p3 = ftell(sdl_fd)-9; } memcpy(&book_buf[0],&book_buf[1],11); book_buf[11]=c; book_buf[12]=0; if (!strcasecmp(book_buf,"book_entries")) { p4 = ftell(sdl_fd)-12; } if (c == (unsigned char) EOF) fd_input_done = 1; return c; } void nl_to_sp(unsigned char* s) { while (*s) { if (*s=='\n' || *s=='\t') { *s=' '; } s++; } }