diff --git a/b2/boom.c b/b2/boom.c index 1d194c3..d3dde4a 100644 --- a/b2/boom.c +++ b/b2/boom.c @@ -15,8 +15,7 @@ #include #include - -extern int yyparse(void); +#include "lang.h" static void usage(const char *name) @@ -47,6 +46,6 @@ int main(int argc, char **argv) default: usage(*argv); } - (void) yyparse(); + parse_hierarchy(); return 0; } diff --git a/b2/lang.h b/b2/lang.h new file mode 100644 index 0000000..f0c966a --- /dev/null +++ b/b2/lang.h @@ -0,0 +1,19 @@ +/* + * lang.h - Things lang.l and lang.y export + * + * Copyright 2012 by Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#ifndef LANG_H +#define LANG_H + +void parse_hierarchy(void); +void parse_characteristics(void); + +#endif /* !LANG_H */ diff --git a/b2/lang.l b/b2/lang.l index 907ffdb..85c777c 100644 --- a/b2/lang.l +++ b/b2/lang.l @@ -17,14 +17,41 @@ #include "param.h" #include "chr.h" #include "y.tab.h" +#include "lang.h" +extern int yyparse(void); + +static int start_token; static int lineno = 1; + +void parse_hierarchy(void) +{ + start_token = START_HIERARCHY; + yyparse(); +} + + +void parse_characteristics(void) +{ + start_token = START_CHAR; + yyparse(); +} + %} %% +%{ + if (start_token) { + int tmp = start_token; + + start_token = 0; + return tmp; + } +%} + [-_A-Za-z0-9()+./]+ { yylval.s = unique(yytext); return WORD; } diff --git a/b2/lang.y b/b2/lang.y index 41c99b7..b34bb45 100644 --- a/b2/lang.y +++ b/b2/lang.y @@ -71,6 +71,7 @@ static const struct field *top_field(void) }; +%token START_HIERARCHY START_CHAR %token TOK_LE TOK_GE %token WORD @@ -86,11 +87,15 @@ static const struct field *top_field(void) %% all: - rule + START_HIERARCHY hierarchy + ; + +hierarchy: + nameset hierarchy + | rule { field_dump(stderr, $1); } - | nameset all ; nameset: