From 18c87e98bf4cd6b0d0834ea7ac6dc5d1489fe58d Mon Sep 17 00:00:00 2001 From: John Johansen Date: Thu, 16 Feb 2012 07:59:23 -0800 Subject: [PATCH] Enable the parser to pass the next token to be returned to the lexer Currently the parser can not directly influence the lexer output. This limits the grammar and also how the parser can be invoked. Allow the parser to pass the next TOKEN that the lexer will return. This is has two uses: It allows us to trick the bison parser into having multiple start symbols, allowing us to say invoke the parser on an individual network or file rule. It also allows the semantic analysis of the parser to change the language recognized. This can be leveraged to overcome some of the limitation of bison's LALR parse generator. Signed-off-by: John Johansen Acked-by: Kees Cook --- parser/parser.h | 5 +++++ parser/parser_lex.l | 9 +++++++++ parser/parser_yacc.y | 2 ++ 3 files changed, 16 insertions(+) diff --git a/parser/parser.h b/parser/parser.h index 346620abf..7d71fd89a 100644 --- a/parser/parser.h +++ b/parser/parser.h @@ -25,6 +25,11 @@ #include "libapparmor_re/apparmor_re.h" #include "libapparmor_re/aare_rules.h" +/* Global variable to pass token to lexer. Will be replaced by parameter + * when lexer and parser are made reentrant + */ +extern int parser_token; + typedef enum pattern_t pattern_t; struct flagval { diff --git a/parser/parser_lex.l b/parser/parser_lex.l index a2c27da16..0c9323bd7 100644 --- a/parser/parser_lex.l +++ b/parser/parser_lex.l @@ -222,6 +222,15 @@ LT_EQUAL <= %% +%{ +/* Copied directly into yylex function */ + if (parser_token) { + int t = parser_token; + parser_token = 0; + return t; + } +%} + { {WS}+ { /* Eat whitespace */ } \<([^\> \t\n]+)\> { /* */ diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y index af56a2013..aaf5f4d36 100644 --- a/parser/parser_yacc.y +++ b/parser/parser_yacc.y @@ -69,6 +69,8 @@ struct value_list { struct value_list *next; }; +int parser_token = 0; + void free_value_list(struct value_list *list); struct cod_entry *do_file_rule(char *namespace, char *id, int mode, char *link_id, char *nt);