summaryrefslogtreecommitdiff
path: root/glcpp
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-06-16 16:26:28 -0700
committerKenneth Graunke <kenneth@whitecape.org>2010-06-21 11:31:55 -0700
commite0e429fca3f1f67e5d18f0989fd2dcc0d23a6bb9 (patch)
treeaba5c93dcd8c235ae6378d15565824dec2eabebe /glcpp
parentb673ff91abec7d0ddb09a1fcddc734c3425eb8eb (diff)
glcpp: Build a reentrant parser.
Diffstat (limited to 'glcpp')
-rw-r--r--glcpp/glcpp-lex.l14
-rw-r--r--glcpp/glcpp-parse.y12
-rw-r--r--glcpp/glcpp.h2
3 files changed, 15 insertions, 13 deletions
diff --git a/glcpp/glcpp-lex.l b/glcpp/glcpp-lex.l
index 933d9f4..06bde3f 100644
--- a/glcpp/glcpp-lex.l
+++ b/glcpp/glcpp-lex.l
@@ -29,7 +29,7 @@
#include "glcpp-parse.h"
%}
-%option reentrant noyywrap
+%option bison-bridge reentrant noyywrap
%option extra-type="glcpp_parser_t *"
%option prefix="glcpp_"
@@ -66,7 +66,7 @@ NON_STARS_THEN_STARS [^*]*[*]+
/* glcpp doesn't handle #extension, #version, or #pragma directives.
* Simply pass them through to the main compiler's lexer/parser. */
{HASH}(extension|version|pragma).*\n {
- yylval.str = xtalloc_strdup (yyextra, yytext);
+ yylval->str = xtalloc_strdup (yyextra, yytext);
return OTHER;
}
@@ -130,17 +130,17 @@ NON_STARS_THEN_STARS [^*]*[*]+
}
{DECIMAL_INTEGER} {
- yylval.str = xtalloc_strdup (yyextra, yytext);
+ yylval->str = xtalloc_strdup (yyextra, yytext);
return INTEGER_STRING;
}
{OCTAL_INTEGER} {
- yylval.str = xtalloc_strdup (yyextra, yytext);
+ yylval->str = xtalloc_strdup (yyextra, yytext);
return INTEGER_STRING;
}
{HEXADECIMAL_INTEGER} {
- yylval.str = xtalloc_strdup (yyextra, yytext);
+ yylval->str = xtalloc_strdup (yyextra, yytext);
return INTEGER_STRING;
}
@@ -185,7 +185,7 @@ NON_STARS_THEN_STARS [^*]*[*]+
}
{IDENTIFIER} {
- yylval.str = xtalloc_strdup (yyextra, yytext);
+ yylval->str = xtalloc_strdup (yyextra, yytext);
return IDENTIFIER;
}
@@ -194,7 +194,7 @@ NON_STARS_THEN_STARS [^*]*[*]+
}
{OTHER}+ {
- yylval.str = xtalloc_strdup (yyextra, yytext);
+ yylval->str = xtalloc_strdup (yyextra, yytext);
return OTHER;
}
diff --git a/glcpp/glcpp-parse.y b/glcpp/glcpp-parse.y
index fde9b92..8119de3 100644
--- a/glcpp/glcpp-parse.y
+++ b/glcpp/glcpp-parse.y
@@ -133,13 +133,15 @@ _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser);
#define yylex glcpp_parser_lex
static int
-glcpp_parser_lex (glcpp_parser_t *parser);
+glcpp_parser_lex (YYSTYPE *yylval, glcpp_parser_t *parser);
static void
glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
%}
+%pure-parser
+
%parse-param {glcpp_parser_t *parser}
%lex-param {glcpp_parser_t *parser}
@@ -1449,13 +1451,13 @@ _define_function_macro (glcpp_parser_t *parser,
}
static int
-glcpp_parser_lex (glcpp_parser_t *parser)
+glcpp_parser_lex (YYSTYPE *yylval, glcpp_parser_t *parser)
{
token_node_t *node;
int ret;
if (parser->lex_from_list == NULL) {
- ret = glcpp_lex (parser->scanner);
+ ret = glcpp_lex (yylval, parser->scanner);
/* XXX: This ugly block of code exists for the sole
* purpose of converting a NEWLINE token into a SPACE
@@ -1501,7 +1503,7 @@ glcpp_parser_lex (glcpp_parser_t *parser)
{
macro_t *macro;
macro = hash_table_find (parser->defines,
- yylval.str);
+ yylval->str);
if (macro && macro->is_function) {
parser->newline_as_space = 1;
parser->paren_count = 0;
@@ -1519,7 +1521,7 @@ glcpp_parser_lex (glcpp_parser_t *parser)
return NEWLINE;
}
- yylval = node->token->value;
+ *yylval = node->token->value;
ret = node->token->type;
parser->lex_from_node = node->next;
diff --git a/glcpp/glcpp.h b/glcpp/glcpp.h
index 0d43f0b..3441ab8 100644
--- a/glcpp/glcpp.h
+++ b/glcpp/glcpp.h
@@ -163,7 +163,7 @@ void
glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader);
int
-glcpp_lex (yyscan_t scanner);
+glcpp_lex (YYSTYPE *lvalp, yyscan_t scanner);
int
glcpp_lex_destroy (yyscan_t scanner);