From 012295f94c4b02d2683072d9aa6ab56f81409507 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 12 May 2010 13:19:23 -0700 Subject: [PATCH] Simplify lexer significantly (remove all stateful lexing). We are able to remove all state by simply passing NEWLINE through as a token unconditionally (as opposed to only passing newline when on a driective line as we did previously). --- glcpp-lex.l | 41 +++++++++-------------------------------- glcpp-parse.y | 6 ++++++ 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/glcpp-lex.l b/glcpp-lex.l index 9ec4deb7185..18d9050d715 100644 --- a/glcpp-lex.l +++ b/glcpp-lex.l @@ -32,9 +32,6 @@ %option reentrant noyywrap %option extra-type="glcpp_parser_t *" -%x ST_DEFINE -%x ST_UNDEF - SPACE [[:space:]] NONSPACE [^[:space:]] NEWLINE [\n] @@ -46,48 +43,28 @@ TOKEN {NONSPACE}+ %% {HASH}define{HSPACE}* { - BEGIN ST_DEFINE; return DEFINE; } -{IDENTIFIER} { - yylval.str = xtalloc_strdup (yyextra, yytext); - return IDENTIFIER; -} - -{TOKEN} { - yylval.str = xtalloc_strdup (yyextra, yytext); - return TOKEN; -} - -\n { - BEGIN INITIAL; - return NEWLINE; -} - -{SPACE}+ - {HASH}undef{HSPACE}* { - BEGIN ST_UNDEF; return UNDEF; } -{IDENTIFIER} { + +{IDENTIFIER} { yylval.str = xtalloc_strdup (yyextra, yytext); return IDENTIFIER; } -\n { - BEGIN INITIAL; - return NEWLINE; -} - -{SPACE}+ - - /* Anything we don't specifically recognize is a stream of tokens */ -{NONSPACE}+ { +{TOKEN} { yylval.str = xtalloc_strdup (yyextra, yytext); return TOKEN; } +\n { + return NEWLINE; +} + +{SPACE}+ + %% diff --git a/glcpp-parse.y b/glcpp-parse.y index 29614fb1a4d..9883a6f9532 100644 --- a/glcpp-parse.y +++ b/glcpp-parse.y @@ -74,11 +74,17 @@ content: talloc_free ($1); } | directive_with_newline +| NEWLINE { + printf ("\n"); + } | content token { _print_resolved_token (parser, $2); talloc_free ($2); } | content directive_with_newline +| content NEWLINE { + printf ("\n"); + } ; directive_with_newline: -- 2.30.2