1/* $NetBSD: scanner.l,v 1.1.1.1 2009/10/26 00:29:11 christos Exp $ */ 2 3/* 4 * This file is part of flex. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE. 24 */ 25 26%{ 27/* A template scanner file to build "scanner.c". */ 28#include <stdio.h> 29#include <stdlib.h> 30#include "config.h" 31/*#include "parser.h" */ 32 33#define err_abort() do{printf("ERROR: flex line %d. input line %d.\n", __LINE__, yylineno); abort();} while(0) 34#define a_ok() do{printf("OK: flex line %d. input line %d.\n", __LINE__, yylineno); return 1;}while(0) 35%} 36 37%option 8bit outfile="scanner.c" prefix="test" 38%option nounput nomain noyywrap 39%option warn 40 41 42%% 43 44^"^alpha:"[[:^alpha:]]+@alpha@\n printf("OK: %s", yytext); ++yylineno; return 1; 45^"^digit:"[[:^digit:]]+@digit@\n printf("OK: %s", yytext); ++yylineno; return 1; 46^"^alnum:"[[:^alnum:]]+@alnum@\n printf("OK: %s", yytext); ++yylineno; return 1; 47^"^upper:"[[:^upper:]]+@upper@\n printf("OK: %s", yytext); ++yylineno; return 1; 48^"^lower:"[[:^lower:]]+@lower@\n printf("OK: %s", yytext); ++yylineno; return 1; 49^"^space:"[[:^space:]]+@space@\n printf("OK: %s", yytext); ++yylineno; return 1; 50^"^blank:"[[:^blank:]]+@blank@\n printf("OK: %s", yytext); ++yylineno; return 1; 51^"^punct:"[[:^punct:]]+@punct@\n printf("OK: %s", yytext); ++yylineno; return 1; 52^"^cntrl:"[[:^cntrl:]]+@cntrl@\n printf("OK: %s", yytext); ++yylineno; return 1; 53^"^xdigit:"[[:^xdigit:]]+@xdigit@\n printf("OK: %s", yytext); ++yylineno; return 1; 54 55^"a-d:"[[:alpha:]]{-}[[:digit:]]+@a-d@\n printf("OK: %s", yytext); ++yylineno; return 1; 56^"l-xyz:"([[:lower:]]{-}[xyz])+@l-xyz@\n printf("OK: %s", yytext); ++yylineno; return 1; 57^"abcd-bc:"([abcd]{-}[bc])+@abcd-bc@\n printf("OK: %s", yytext); ++yylineno; return 1; 58^"abcde-b-c:"([abcde]{-}[b]{-}[c])+@abcde-b-c@\n printf("OK: %s", yytext); ++yylineno; return 1; 59^"^XY-^XYZ:"([^XY]{-}[^XYZ])+@^XY-^XYZ@\n printf("OK: %s", yytext); ++yylineno; return 1; 60 61^"a+d:"([[:alpha:]]{+}[[:digit:]])+"@a+d@"\n a_ok(); 62^"a-u+Q:"([[:alpha:]]{-}[[:upper:]]{+}[Q])+"@a-u+Q@"\n a_ok(); 63 64^"ia:"(?i:a)+@ia@\n printf("OK: %s", yytext); ++yylineno; return 1; 65^"iabc:"(?i:abc)+@iabc@\n printf("OK: %s", yytext); ++yylineno; return 1; 66^"ia-c:"(?i:[a-c]+)@ia-c@\n printf("OK: %s", yytext); ++yylineno; return 1; 67 68 /* We don't want this one to match. */ 69^"check-a:"(?i:(?-i:A))@\n err_abort(); 70^"check-a:"(?i:(?-i:(?i:A)))@\n printf("OK: %s", yytext); ++yylineno; return 1; 71 72 /* We don't want this one to match. */ 73^"dot-all-1:"(?-s:XXX.*)@dot-all-1@\n err_abort(); 74^"dot-all-1:"(?s:XXX.*)@dot-all-1@\n a_ok(); 75 76^"x1:"(?x: a | b )+@x1@\n a_ok(); 77^"x2:"(?x: a | 78 (?# Comment ) 79 b 80 )+@x2@\n a_ok(); 81 82 83.|\n { err_abort(); } 84%% 85 86int main(void); 87 88int 89main () 90{ 91 yyin = stdin; 92 yyout = stdout; 93 while (yylex()) 94 ; 95 printf("TEST RETURNING OK.\n"); 96 return 0; 97} 98