From f6112a24bb312d3cd0f4f74c887b3ae50899850f Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Mon, 1 Apr 2002 04:36:56 +0000 Subject: [PATCH] the parser works properly, but it doesn't do anything yet Original commit message from CVS: * the parser works properly, but it doesn't do anything yet --- gst/parse/Makefile.am | 8 ++++--- gst/parse/grammar.y | 59 ++++++++++++++++++++++++++------------------------- gst/parse/parse.l | 26 +++++++++++++++-------- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/gst/parse/Makefile.am b/gst/parse/Makefile.am index a73cfa7..5af860f 100644 --- a/gst/parse/Makefile.am +++ b/gst/parse/Makefile.am @@ -2,20 +2,22 @@ #libgstparse_la_SOURCES = parse.c grammar.c +BISON = bison -d + noinst_PROGRAMS = grammar grammar_SOURCES = lex.yy.c grammar.tab.c -grammar_CFLAGS = $(GLIB_CFLAGS) -DYYERROR_VERBOSE +grammar_CFLAGS = $(GLIB_CFLAGS) noinst_HEADERS = grammar.tab.h BUILT_SOURCES = grammar.tab.h grammar.tab.c lex.yy.c grammar.tab.h: grammar.y - bison -v -d grammar.y + $(BISON) grammar.y grammar.tab.c: grammar.y - bison -v -d grammar.y + $(BISON) grammar.y lex.yy.c: parse.l flex parse.l diff --git a/gst/parse/grammar.y b/gst/parse/grammar.y index e62fd2e..fb14dd3 100644 --- a/gst/parse/grammar.y +++ b/gst/parse/grammar.y @@ -1,6 +1,8 @@ %{ #include #include +#define YYDEBUG 1 +#define YYERROR_VERBOSE 1 %} %union { @@ -15,35 +17,42 @@ %token INTEGER %token BOOLEAN +%left '{' '}' '(' ')' +%left '!' '=' +%left '+' +%left '.' + +%start graph %% -graph: connection { printf ("primary graph: connection\n"); } - | property_value { printf ("primary graph: prop_value\n"); } - | element { printf ("primary graph: element\n"); } - | graph connection { printf ("adding a connection to the graph\n"); } - | graph property_value { printf ("adding a property=value pair to the graph\n"); } - | graph element { printf ("adding on another element...\n"); } +id: IDENTIFIER {} + ; + +qid: id + | id '.' id ; -property_value: property '=' value { printf ("got property=value\n"); } +value: STRING {} + | FLOAT {} + | INTEGER {} + | BOOLEAN {} ; -property: identifier { printf ("got unadorned property name\n"); } - | identifier '.' identifier { printf ("got qualified property name\n"); } +property_value: qid '=' value ; -value: STRING { printf ("got string\n"); } - | FLOAT { printf ("got float\n"); } - | INTEGER { printf ("got integer\n"); } - | BOOLEAN { printf ("got boolean\n"); } +element: id + | bin ; -element: identifier { printf ("got element\n"); } - | bin { printf ("new element, it's a bin\n"); } +graph: /* empty */ + | graph element + | graph connection + | graph property_value ; -bin: '{' graph '}' { printf ("new thread\n"); } - | identifier '.' '(' graph ')' { printf ("new named bin\n"); } +bin: '{' graph '}' + | id '.' '(' graph ')' ; connection: lconnection @@ -51,22 +60,14 @@ connection: lconnection | bconnection ; -lconnection: pad_name '+' '!' { printf ("got lconnection\n"); } - ; - -rconnection: '!' '+' pad_name { printf ("got rconnection\n"); } - ; - -bconnection: '!' { printf ("got base bconnection\n"); } - | pad_name '+' '!' '+' pad_name { printf ("got bconnection with pads\n"); } - | pad_name ',' bconnection ',' pad_name { printf ("got multiple-pad bconnection\n"); } +lconnection: qid '+' '!' ; -pad_name: identifier { printf ("got pad\n"); } - | identifier '.' identifier { printf ("got named pad\n"); } +rconnection: '!' '+' qid ; -identifier: IDENTIFIER { printf ("matching on identifier\n");} +bconnection: '!' + | qid '+' bconnection '+' qid ; %% diff --git a/gst/parse/parse.l b/gst/parse/parse.l index d0da883..6ecbb0b 100644 --- a/gst/parse/parse.l +++ b/gst/parse/parse.l @@ -5,7 +5,13 @@ #include #include -#define CHAR(x) printf ("char: %c\n", *yytext); return *yytext; +#ifdef DEBUG +# define PRINT(a...) printf(##a) +#else +#define PRINT(a...) +#endif + +#define CHAR(x) PRINT ("char: %c\n", *yytext); return *yytext; %} _integer [[:digit:]]+ @@ -21,20 +27,20 @@ _string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"") { {_integer} { - printf ("An integer: %s (%d)\n", yytext, + PRINT ("An integer: %s (%d)\n", yytext, atoi (yytext)); BEGIN (INITIAL); return INTEGER; } {_float} { - printf ("A float: %s (%g)\n", yytext, atof (yytext)); + PRINT ("A float: %s (%g)\n", yytext, atof (yytext)); BEGIN (INITIAL); return FLOAT; } {_boolean} { - printf ("A boolean: %s (%d)\n", yytext, tolower (*yytext) == 't' ? 1 : 0); + PRINT ("A boolean: %s (%d)\n", yytext, tolower (*yytext) == 't' ? 1 : 0); BEGIN (INITIAL); return BOOLEAN; } @@ -44,20 +50,21 @@ _string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"") yytext++; *(yytext + strlen (yytext) - 1) = '\0'; } - printf ("A string: %s\n", yytext); + PRINT ("A string: %s\n", yytext); BEGIN (INITIAL); return STRING; } - [[:space:]]+ { /* printf ("space: [%s]\n", yytext); */ } + [[:space:]]+ { /* PRINT ("space: [%s]\n", yytext); */ } . { - printf ("unknown: %s\n", yytext); + PRINT ("unknown: %s\n", yytext); } } {_identifier} { - printf ("An identifier: %s\n", yytext); + PRINT ("An identifier: %s\n", yytext); + return IDENTIFIER; } "=" { BEGIN (value); CHAR ('='); } @@ -73,10 +80,11 @@ _string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"") "!" { CHAR ('!'); } "+" { CHAR ('+'); } -[[:space:]]+ { /* printf ("space: [%s]\n", yytext); */ } +[[:space:]]+ { PRINT ("space: [%s]\n", yytext); } . { printf ("unknown: %s\n", yytext); + return *yytext; } %% -- 2.7.4