From f24ea41e6f97f6fc4bbe0f87dcf23f34f402c200 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 27 Oct 2005 11:20:21 +0000 Subject: [PATCH] Lex/Flex cdrdao TOC scanner --- parse/toc.L | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 parse/toc.L diff --git a/parse/toc.L b/parse/toc.L new file mode 100644 index 00000000..d4bba123 --- /dev/null +++ b/parse/toc.L @@ -0,0 +1,76 @@ +/* $Id: toc.L,v 1.1 2005/10/27 11:20:21 rocky Exp $ -*- C -*- */ +/* cdrdao TOC scanner */ + +%{ +#undef yywrap +#ifdef STANDALONE +#include +#endif + +#include "toc.tab.h" + + static int debug_lex=0; +%} +%union { + unsigned long int val; /* For returning numbers. */ + char const * str; /* For returning stringss. */ +} + + +integer [[:digit:]]+ + +/* The below isn't octal. I'm just going by the name and pattern + in the cdrdao pacct grammar. */ +stringoctal [[:digit:]]{3} + +spaces [[:blank:]\n\r]+ + +# Need to expand this to include "octal" \000 and embedded quotes. +string \".+\" +%% +{integer} { + /*"*/ + return Integer; +} + +{stringoctal} { + /*"*/ + return StringOctal; +} + +{spaces} { + return Spaces; +} + +%% + +#if STANDALONE +int +main( int argc, const char **argv ) +{ + int token; + + ++argv, --argc; /* skip over program name */ + debug_lex = 1; + if ( argc > 0 ) + yyin = fopen( argv[0], "r" ); + else + yyin = stdin; + + while ((token=yylex()) != EOF) { + switch (token) { + case StringOctal: + printf("StringOctal\n"); + break; + case Spaces: + printf("Spaces\n"); + break; + case Integer: + printf("Integer\n"); + break; + default: ; + } + } + return 0; +} +#endif