2 * pascal.lex: An example PASCAL scanner
12 void yyerror(char *message);
21 alpha_num ({alpha}|{digit})
23 identifier {alpha}{alpha_num}*
24 unsigned_integer {digit}+
25 hex_integer ${hex_digit}{hex_digit}*
26 exponent e[+-]?{digit}+
28 real ({i}\.{i}?|{i}?\.{i}){exponent}?
29 string \'([^'\n]|\'\')+\'
30 bad_string \'([^'\n]|\'\')+
36 <COMMENT1>\n ++line_number;
37 <COMMENT1><<EOF>> yyerror("EOF in comment");
38 <COMMENT1>"}" BEGIN(INITIAL);
42 <COMMENT2>\n ++line_number;
43 <COMMENT2><<EOF>> yyerror("EOF in comment");
44 <COMMENT2>"*)" BEGIN(INITIAL);
47 /* note that FILE and BEGIN are already
48 * defined in FLEX or C so they can't
49 * be used. This can be overcome in
50 * a cleaner way by defining all the
51 * tokens to start with TOK_ or some
62 downto return(DOWNTO);
67 function return(FUNCTION);
76 packed return(PACKED);
77 procedure return(PROCEDURE);
78 program return(PROGRAM);
79 record return(RECORD);
80 repeat return(REPEAT);
90 "<="|"=<" return(LEQ);
91 "=>"|">=" return(GEQ);
95 ".." return(DOUBLEDOT);
97 {unsigned_integer} return(UNSIGNED_INTEGER);
99 {hex_integer} return(HEX_INTEGER);
100 {string} return{STRING};
101 {bad_string} yyerror("Unterminated string");
103 {identifier} return(IDENTIFIER);
105 [*/+\-,^.;:()\[\]] return(yytext[0]);
107 {white_space} /* do nothing */
109 . yyerror("Illegal input");
113 void yyerror(char *message)
115 fprintf(stderr,"Error: \"%s\" in line %d. Token = %s\n",
116 message,line_number,yytext);