summaryrefslogtreecommitdiff
path: root/examples/manual/eof_rules.lex
diff options
context:
space:
mode:
authorWill Estes <wlestes@users.sourceforge.net>2001-05-01 20:47:11 +0000
committerWill Estes <wlestes@users.sourceforge.net>2001-05-01 20:47:11 +0000
commit2eae8800306d74d3507eee2464630a085b211779 (patch)
treea892110dd6ff826cf3691ce0b38615ed6d1fc061 /examples/manual/eof_rules.lex
parent26e78464e71e0d03bf16cda54bcf06a6785e727c (diff)
adding the rest of vern's files
Diffstat (limited to 'examples/manual/eof_rules.lex')
-rw-r--r--examples/manual/eof_rules.lex65
1 files changed, 65 insertions, 0 deletions
diff --git a/examples/manual/eof_rules.lex b/examples/manual/eof_rules.lex
new file mode 100644
index 0000000..b575f2c
--- /dev/null
+++ b/examples/manual/eof_rules.lex
@@ -0,0 +1,65 @@
+/*
+ * eof_rules.lex : An example of using multiple buffers
+ * EOF rules, and start states
+ */
+
+%{
+
+#define MAX_NEST 10
+
+YY_BUFFER_STATE include_stack[MAX_NEST];
+int include_count = -1;
+
+%}
+
+
+%x INCLUDE
+
+%%
+
+^"#include"[ \t]*\" BEGIN(INCLUDE);
+<INCLUDE>\" BEGIN(INITIAL);
+<INCLUDE>[^\"]+ { /* get the include file name */
+ if ( include_count >= MAX_NEST){
+ fprintf( stderr, "Too many include files" );
+ exit( 1 );
+ }
+
+ include_stack[++include_count] = YY_CURRENT_BUFFER;
+
+ yyin = fopen( yytext, "r" );
+ if ( ! yyin ){
+ fprintf( stderr, "Unable to open \"%s\"\n",yytext);
+ exit( 1 );
+ }
+
+ yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
+
+ BEGIN(INITIAL);
+ }
+<INCLUDE><<EOF>>
+ {
+ fprintf( stderr, "EOF in include" );
+ yyterminate();
+ }
+<<EOF>> {
+ if ( include_count <= 0 ){
+ yyterminate();
+ } else {
+ yy_delete_buffer(include_stack[include_count--] );
+ yy_switch_to_buffer(include_stack[include_count] );
+ BEGIN(INCLUDE);
+ }
+ }
+[a-z]+ ECHO;
+.|\n ECHO;
+
+
+
+
+
+
+
+
+
+