/* pascal.l MR 11/06/98 12/06/98 14/06/98 */ /* Lex input file for a Pascal lexical analyzer. */ /* Looted from Aho, Sethi, Ullman, 196, p.109, and */ /* from gnu flex man page version 2.5, April 1995. */ /* Use flex option -i (case insensitive). */ /* Run flex as follows: flex -i pascal.l */ /* Then compile as follows: gcc lex.yy.c -o scanpascal -lfl */ digit [0-9] letter [a-z_] id {letter}({letter}|{digit})* number {digit}+(\.{digit}+)?(e[+\-])?({digit}+)? comment (\{[^}]*\})|(\/\/.*\n) strliteral (\'[^']*\')|(\"[^"]*\") charliteral \#{digit}+ h_keyword unit|program|uses|interface|implementation y_keyword type|object|record|array|file|class|set v_keyword var|const m_keyword packed|stdcall|external|name p_keyword procedure|function s1 if|then|else|case|for|to|downto|do|while|repeat|until|with s2 break|continue|exit|halt s_keyword {s1}|{s2} g_keyword label|goto f_keyword new|dispose t1 variant|char|string t2 integer|byte|word|cardinal|shortint|smallint|longint t3 boolean|bytebool|wordbool|longbool t4 real|single|double|extended t_keyword {t1}|{t2}|{t3}|{t4} interp ","|";"|".."|":"|"of" dot "." op1 ":="|"="|"<>"|"<"|"<="|">"|">="|"in"|"is" op2 "-"|"*"|"/"|"div"|"mod"|"as"|"and"|"shl"|"shr" op3 "or"|"xor"|"+"|"-" op4 "^"|"@"|"not" operator {op1}|{op2}|{op3}|{op4} wbracket begin|end rbracket "("|")" abracket "["|"]" builtin_k nil|true|false|maxint|input|output f1 dec|inc|odd|pred|succ|ord|low|high|chr|round|trunc f2 int|inttostr|inttohex|strtoint|strtointdef|val|str f3 strpas|strpcopy|strplcopy f4 floattodecimal|floattostr|floattostrf|floattotext f5 floattotextfmt|strtofloat|texttofloat f6 include|exclude f7 read|readln|write|writeln|get|reset|put|rewrite|eof|beep f8 assign|close f9 abs|cos|sin|acrtan|exp|ln|sqrt|sqr /* ... and many others ... */ builtin_f {f1}|{f2}|{f3}|{f4}|{f5}|{f6}|{f7}|{f8}|{f9} %% /* The output of the scanner has the lines the same as the pascal input */ /* file. Each symbol in the input is replaced with Cxxxx in the */ /* output, where C = a character specific for the kind of symbol */ /* and xxxx = the string value of the symbol exactly as in the input. */ {comment} /* Eat up comments. Debug: { printf( "$C(%s) ", yytext ); } */ [ \t]+ /* Eat up white space */ \n { printf( "\n" ); } {h_keyword} { printf( "H%s ", yytext ); } {y_keyword} { printf( "Y%s ", yytext ); } {v_keyword} { printf( "V%s ", yytext ); } {p_keyword} { printf( "P%s ", yytext ); } {m_keyword} { printf( "M%s ", yytext ); } {s_keyword} { printf( "S%s ", yytext ); } {g_keyword} { printf( "G%s ", yytext ); } {f_keyword} { printf( "F%s ", yytext ); } {t_keyword} { printf( "T%s ", yytext ); } {number} { printf( "N%s ", yytext ); } {strliteral} { printf( "L... ", yytext ); } {charliteral} { printf( "C%s ", yytext ); } {operator} { printf( "o%s ", yytext ); } {interp} { printf( "i%s ", yytext ); } {wbracket} { printf( "w%s ", yytext ); } {rbracket} { printf( "r%s ", yytext ); } {abracket} { printf( "a%s ", yytext ); } {dot} { printf( "d%s ", yytext ); } {builtin_k} { printf( "K%s ", yytext ); } {builtin_f} { printf( "B%s ", yytext ); } {id} { printf( "I%s ", yytext ); } . { printf( "?%s ", yytext ); } %%