string_nr.l revision 1.1 1 1.1 christos /*
2 1.1 christos * This file is part of flex.
3 1.1 christos *
4 1.1 christos * Redistribution and use in source and binary forms, with or without
5 1.1 christos * modification, are permitted provided that the following conditions
6 1.1 christos * are met:
7 1.1 christos *
8 1.1 christos * 1. Redistributions of source code must retain the above copyright
9 1.1 christos * notice, this list of conditions and the following disclaimer.
10 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 christos * notice, this list of conditions and the following disclaimer in the
12 1.1 christos * documentation and/or other materials provided with the distribution.
13 1.1 christos *
14 1.1 christos * Neither the name of the University nor the names of its contributors
15 1.1 christos * may be used to endorse or promote products derived from this software
16 1.1 christos * without specific prior written permission.
17 1.1 christos *
18 1.1 christos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 1.1 christos * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 1.1 christos * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.1 christos * PURPOSE.
22 1.1 christos */
23 1.1 christos
24 1.1 christos %{
25 1.1 christos /* A template scanner file to build "scanner.c". */
26 1.1 christos #include <stdio.h>
27 1.1 christos #include <stdlib.h>
28 1.1 christos #include "config.h"
29 1.1 christos
30 1.1 christos #define NUMBER 200
31 1.1 christos #define WORD 201
32 1.1 christos
33 1.1 christos %}
34 1.1 christos
35 1.1 christos %option 8bit prefix="test"
36 1.1 christos %option nounput nomain nodefault noyywrap noinput
37 1.1 christos %option warn
38 1.1 christos
39 1.1 christos
40 1.1 christos %%
41 1.1 christos
42 1.1 christos [[:space:]]+ { }
43 1.1 christos [[:digit:]]+ { printf("NUMBER "); fflush(stdout);}
44 1.1 christos [[:alpha:]]+ { printf("WORD "); fflush(stdout);}
45 1.1 christos . {
46 1.1 christos fprintf(stderr,"*** Error: Unrecognized character '%c' while scanning.\n",
47 1.1 christos yytext[0]);
48 1.1 christos yyterminate();
49 1.1 christos }
50 1.1 christos
51 1.1 christos <<EOF>> { printf("<<EOF>>\n"); yyterminate();}
52 1.1 christos
53 1.1 christos %%
54 1.1 christos
55 1.1 christos
56 1.1 christos #define INPUT_STRING_1 "1234 foo bar"
57 1.1 christos #define INPUT_STRING_2 "1234 foo bar *@&@&###@^$#&#*"
58 1.1 christos
59 1.1 christos int main(void);
60 1.1 christos
61 1.1 christos int
62 1.1 christos main ()
63 1.1 christos {
64 1.1 christos char * buf;
65 1.1 christos int len;
66 1.1 christos YY_BUFFER_STATE state;
67 1.1 christos
68 1.1 christos
69 1.1 christos /* Scan a good string. */
70 1.1 christos printf("Testing: yy_scan_string(%s): ",INPUT_STRING_1); fflush(stdout);
71 1.1 christos state = yy_scan_string ( INPUT_STRING_1 );
72 1.1 christos yylex();
73 1.1 christos yy_delete_buffer(state);
74 1.1 christos
75 1.1 christos /* Scan only the first 12 chars of a string. */
76 1.1 christos printf("Testing: yy_scan_bytes(%s): ",INPUT_STRING_2); fflush(stdout);
77 1.1 christos state = yy_scan_bytes ( INPUT_STRING_2, 12 );
78 1.1 christos yylex();
79 1.1 christos yy_delete_buffer(state);
80 1.1 christos
81 1.1 christos /* Scan directly from a buffer.
82 1.1 christos We make a copy, since the buffer will be modified by flex.*/
83 1.1 christos printf("Testing: yy_scan_buffer(%s): ",INPUT_STRING_1); fflush(stdout);
84 1.1 christos len = strlen(INPUT_STRING_1) + 2;
85 1.1 christos buf = (char*)malloc( len );
86 1.1 christos strcpy( buf, INPUT_STRING_1);
87 1.1 christos buf[ len -2 ] = 0; /* Flex requires two NUL bytes at end of buffer. */
88 1.1 christos buf[ len -1 ] =0;
89 1.1 christos
90 1.1 christos state = yy_scan_buffer( buf, len );
91 1.1 christos yylex();
92 1.1 christos yy_delete_buffer(state);
93 1.1 christos
94 1.1 christos printf("TEST RETURNING OK.\n");
95 1.1 christos return 0;
96 1.1 christos }
97