On 02/14/2012 11:14 AM, Kees Cook wrote: > Hi John, > > On Tue, Feb 14, 2012 at 09:32:28AM -0800, John Johansen wrote: >> 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 <[email protected]> >> --- >> parser/parser.h | 5 +++++ >> parser/parser_lex.l | 9 +++++++++ >> parser/parser_yacc.y | 3 +++ >> 3 files changed, 17 insertions(+), 0 deletions(-) >> >> diff --git a/parser/parser.h b/parser/parser.h >> index 346620a..7d71fd8 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 e4f8f66..87ede55 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; >> + } >> +%} >> + >> <INCLUDE>{ >> {WS}+ { /* Eat whitespace */ } >> \<([^\> \t\n]+)\> { /* <filename> */ >> diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y >> index af56a20..2a4fa5d 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); >> @@ -77,6 +79,7 @@ void add_local_entry(struct codomain *cod); >> >> %} >> >> + >> %token TOK_ID >> %token TOK_CONDID >> %token TOK_CARET > > Needless whitespace addition in this chunk. Otherwise, looks fine to me. > yep, and drat another one I didn't catch
thanks > -Kees > -- AppArmor mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
