%a 5000 letter [A-Za-z] digit [0-9]+ id [a-zA-Z][a-zA-Z0-9_]* %% " " ; \n ; \{ comment=1; \} comment=0; \+ if(!(comment)) return('+'); \- if(!(comment)) return('-'); \* if(!(comment)) return('*'); \/ if(!(comment)) return('/'); \= if(!(comment)) return('='); \< if(!(comment)) return('<'); \> if(!(comment)) return('>'); \( if(!(comment)) return('('); \) if(!(comment)) return(')'); \[ if(!(comment)) return('['); \] if(!(comment)) return(']'); \, if(!(comment)) return(','); \: if(!(comment)) return(':'); \; if(!(comment)) return(';'); \' if(!(comment)) return('\''); \# if(!(comment)) return('#'); \$ if(!(comment)) return('$'); \:\= if(!(comment)) return(tkasg()); \<\> if(!(comment)) return(tkne()); \<\= if(!(comment)) return(tkle()); \>\= if(!(comment)) return(TKGE); \.\. if(!(comment)) return(TKDTDT); \. if(!(comment)) return('.'); [Aa][Bb][Ss][Oo][Ll][Uu][Tt][Ee] if(!(comment)) return(TKABSOLUTE); [Aa][Nn][Dd] if(!(comment)) return(TKAND); [Aa][Rr][Rr][Aa][Yy] if(!(comment)) return(TKARRAY); [Bb][Ee][Gg][Ii][Nn] if(!(comment)) return(tkbegin()); [Cc][Aa][Ss][Ee] if(!(comment)) return(TKCASE); [Cc][Oo][Nn][Ss][Tt] if(!(comment)) return(TKCONST); [Cc][Hh][Aa][Rr] if(!(comment)) return(TKCHAR); [Dd][Ii][Vv] if(!(comment)) return(TKDIV); [Dd][Oo] if(!(comment)) return(TKDO); [Dd][Oo][Ww][Nn][Tt][Oo] if(!(comment)) return(TKDOWNTO); [Ee][Ll][Ss][Ee] if(!(comment)) return(TKELSE); [Ee][Nn][Dd] if(!(comment)) return(TKEND); [Ee][Xx][Tt][Ee][Rr][Nn][Aa][Ll] if(!(comment)) return(TKEXTERNAL); [Ff][Ii][Ll][Ee] if(!(comment)) return(TKFILE); [Ff][Oo][Rr][Ww][Aa][Rr][Dd] if(!(comment)) return(TKFORWARD); [Ff][Oo][Rr] if(!(comment)) return(TKFOR); [Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn] if(!(comment)) return(TKFUNCTION); [Gg][Oo][Tt][Oo] if(!(comment)) return(TKGOTO); [Ii][Nn][Ll][Ii][Nn][Ee] if(!(comment)) return(TKINLINE); [Ii][Ff] if(!(comment)) return(TKIF); [Ii][Nn] if(!(comment)) return(TKIN); [Ll][Aa][Bb][Ee][Ll] if(!(comment)) return(TKLABEL); [Mm][Oo][Dd] if(!(comment)) return(TKMOD); [Nn][Ii][Ll] if(!(comment)) return(TKNIL); [Nn][Oo][Tt] if(!(comment)) return(TKNOT); [Oo][Vv][Ee][Rr][Ll][Aa][Yy] if(!(comment)) return(TKOVERLAY); [Oo][Ff] if(!(comment)) return(TKOF); [Oo][Rr] if(!(comment)) return(TKOR); [Pp][Aa][Cc][Kk][Ee][Dd] if(!(comment)) return(TKPACKED); [Pp][Rr][Oo][Cc][Ee][Dd][Uu][Rr][Ee] if(!(comment)) return(tkprocedure()); [Pp][Rr][Oo][Gg][Rr][Aa][Mm] if(!(comment)) return(tkprogram()); [Rr][Ee][Cc][Oo][Rr][Dd] if(!(comment)) return(TKRECORD); [Rr][Ee][Pp][Ee][Aa][Tt] if(!(comment)) return(TKREPEAT); [Ss][Ee][Tt] if(!(comment)) return(TKSET); [Ss][Hh][Ll] if(!(comment)) return(TKSHL); [Ss][Hh][Rr] if(!(comment)) return(TKSHR); [Ss][Tt][Rr][Ii][Nn][Gg] if(!(comment)) return(TKSTRING); [Tt][Hh][Ee][Nn] if(!(comment)) return(TKTHEN); [Tt][Yy][Pp][Ee] if(!(comment)) return(TKTYPE); [Tt][Oo] if(!(comment)) return(TKTO); [Tt][Ee][Xx][Tt] if(!(comment)) return(TKTEXT); [Uu][Nn][Tt][Ii][Ll] if(!(comment)) return(TKUNTIL); [Vv][Aa][Rr] if(!(comment)) return(tkvar()); [Ww][Hh][Ii][Ll][Ee] if(!(comment)) return(TKWHILE); [Ww][Ii][Tt][Hh] if(!(comment)) return(TKWITH); [Xx][Oo][Rr] if(!(comment)) return(TKXOR); [Rr][Ee][Aa][Ll] if(!(comment)) return(TKREAL); [Bb][Oo][Oo][Ll][Ee][Aa][Nn] if(!(comment)) return(TKBOOLEAN); [Ii][Nn][Tt][Ee][Gg][Ee][Rr] if(!(comment)) return(TKINTEGER); [Rr][Ee][Aa][Dd][Ll][Nn] if(!(comment)) return(TKREADLN); [Ww][Rr][Ii][Tt][Ee][Ll][Nn] if(!(comment)) return(TKWRITELN); [Rr][Ee][Aa][Dd] if(!(comment)) return(TKREAD); [Ww][Rr][Ii][Tt][Ee] if(!(comment)) return(TKWRITE); [Tt][Rr][Uu][Ee] if(!(comment)) return(TKTRUE); [Ff][Aa][Ll][Ss][Ee] if(!(comment)) return(TKFALSE); {id} if(!(comment)) return(stelookup()); {digit} if(!(comment)) return(stilookup()); \$[0-9A-Fa-f]+ if(!(comment)) return(stilookup()); [0-9]+\.[0-9]*([Ee][-+]?[0-9]+)? if(!(comment)) return(strlookup()); \.[0-9]+([Ee][-+]?[0-9]+)? if(!(comment)) return(strlookup()); \#[0-9]+ if(!(comment)) return(stringlookup()); \^[A-Za-z] if(!(comment)) return(stringlookup()); \'.*\' if(!(comment)) return(stringlookup()); %% /***************************************************/ int tkprocedure() { int debug= 0; if (debug) printf ("\n saw procedure token \n"); else ; return(TKPROCEDURE); } /*********************/ int tkasg() { int debug= 0; if (debug) printf ("\n saw := token \n"); else ; return(TKASG); } /********************/ int tkne() { int debug= 0; if (debug) printf ("\n saw ne token \n"); else ; return(TKNE); } /********************/ int tkle() { int debug= 0; if (debug) printf ("\n saw le token \n"); else ; return(TKLE); } /******************/ int tkbegin() { int debug= 0; if (debug) printf ("\n saw begin token \n"); else ; return(TKBEGIN); } /****************/ int tkvar() { int debug= 0; if (debug) printf ("\n saw var token \n"); else ; return(TKVAR); } /*****************************************************/ int tkprogram() { int debug=0; if (debug) printf (" saw program token \n"); else ; return(TKPROGRAM); } /*****************************************/ int stelookup() { int debug=0; int len=0; int yes=1; int no= 0; int found; int keep_searching; if (debug) printf ("\n in stelookup yytext= %s ident_index=%d",yytext,ident_index); else ; ident_index =0; keep_searching = yes; found = no; while (keep_searching) { if (ident_index > symtable_last) keep_searching = no; else if (symtable[ident_index] != NULL ) if (strcmp(symtable[ident_index],yytext) != 0) ident_index++; else { found=yes; keep_searching = no; } else keep_searching = no; } if (!(found)) { symtable[symtable_last] =(char *) malloc(strlen(yytext)+1); strcpy(symtable[symtable_last],yytext); symtable_last++; } return(ident); } /**********************************************************/ int stringlookup() { int debug=0; int yes=1; int no= 0; int found; int keep_searching; string_index =0; keep_searching = yes; found = no; while (keep_searching) { if (string_index > string_last) keep_searching = no; else if (stringtable[string_index] != NULL ) if (strcmp(stringtable[string_index],yytext) != 0) string_index++; else { found=yes; keep_searching = no; } else keep_searching = no; } if (!(found)) { stringtable[string_last] = (char *) malloc(strlen(yytext)+1); strcpy (stringtable[string_last],yytext); string_last++; } return(string); } /***************************************************************/ int stilookup() { int yes=1; int no= 0; int found; int keep_searching; int_index =0; keep_searching = yes; found = no; while (keep_searching) { if (int_index > inttable_last) keep_searching = no; else if (inttable[int_index] != NULL ) if (strcmp(inttable[int_index],yytext) != 0) int_index++; else { found=yes; keep_searching = no; } else keep_searching = no; } if (!(found)) { inttable[inttable_last] = (char *) malloc(strlen(yytext)+1); strcpy(inttable[inttable_last],yytext); inttable_last++; } return(integer); } /*******************************************************/ int strlookup() { int yes=1; int no= 0; int found; int keep_searching; real_index =0; keep_searching = yes; found = no; while (keep_searching) { if (real_index > realtable_last) keep_searching = no; else if (realtable[real_index] != NULL ) if (strcmp(realtable[real_index],yytext) != 0) real_index++; else { found=yes; keep_searching = no; } else keep_searching = no; } if (!(found)) { realtable[realtable_last] = (char *) malloc(strlen(yytext)+1); strcpy(realtable[realtable_last],yytext); realtable_last++; } return(real); }