form a semantic representation of the pipeline in preparation for actual instantiation.

Original commit message from CVS:
* form a semantic representation of the pipeline in preparation for
actual instantiation.

the parser is shaping up quite nicely; it should, in theory, be able to create
all types of pipelines that gstreamer supports
This commit is contained in:
Andy Wingo 2002-04-01 06:30:39 +00:00
parent f6112a24bb
commit 66107d8717
4 changed files with 123 additions and 24 deletions

View file

@ -2,12 +2,13 @@
#libgstparse_la_SOURCES = parse.c grammar.c
BISON = bison -d
BISON = bison -d -v
noinst_PROGRAMS = grammar
grammar_SOURCES = lex.yy.c grammar.tab.c
grammar_CFLAGS = $(GLIB_CFLAGS)
grammar_LDADD = $(GLIB_LIBS)
noinst_HEADERS = grammar.tab.h

View file

@ -1,6 +1,7 @@
%{
#include <glib.h>
#include <stdio.h>
#include "types.h"
#define YYDEBUG 1
#define YYERROR_VERBOSE 1
%}
@ -10,6 +11,11 @@
gboolean b;
gint i;
gchar *s;
graph_t *g;
connection_t *c;
property_t *p;
element_t *e;
hash_t *h;
}
%token <s> IDENTIFIER STRING
@ -17,6 +23,13 @@
%token <i> INTEGER
%token <b> BOOLEAN
%type <s> id
%type <h> qid
%type <g> graph bin
%type <e> element
%type <p> property_value value
%type <c> connection lconnection rconnection qconnection iconnection
%left '{' '}' '(' ')'
%left '!' '='
%left '+'
@ -25,49 +38,92 @@
%start graph
%%
id: IDENTIFIER {}
id: IDENTIFIER
;
qid: id
| id '.' id
qid: id { $$ = g_new0 (hash_t, 1); $$->id2 = $1 }
| id '.' id { $$ = g_new0 (hash_t, 1); $$->id1 = $1; $$->id2 = $3; }
;
value: STRING {}
| FLOAT {}
| INTEGER {}
| BOOLEAN {}
value: STRING { $$ = g_new0 (property_t, 1);
$$->value_type = G_TYPE_STRING; $$->value.s = $1; }
| FLOAT { $$ = g_new0 (property_t, 1);
$$->value_type = G_TYPE_DOUBLE; $$->value.d = $1; }
| INTEGER { $$ = g_new0 (property_t, 1);
$$->value_type = G_TYPE_INT; $$->value.i = $1; }
| BOOLEAN { $$ = g_new0 (property_t, 1);
$$->value_type = G_TYPE_BOOLEAN; $$->value.b = $1; }
;
property_value: qid '=' value
property_value: id '=' value { $$ = $3; $$->name = $1; }
;
element: id
| bin
element: id { $$ = g_new0 (element_t, 1); $$->name = $1; }
;
graph: /* empty */
| graph element
| graph connection
| graph property_value
graph: /* empty */ { $$ = g_new0 (graph_t, 1); }
| graph element { GList *l = $$->connections_pending;
$$ = $1;
$$->elements = g_list_append ($$->elements, $2);
$$->current = $2;
while (l) {
((connection_t*) l->data)->sink = $$->current->name;
l = g_list_next (l);
}
if ($$->connections_pending) {
g_list_free ($$->connections_pending);
$$->connections_pending = NULL;
}
}
| graph bin { $$ = $1; $$->bins = g_list_append ($$->bins, $2); }
| graph connection { $$ = $1; $$->connections = g_list_append ($$->connections, $2);
if (!$2->src)
$2->src = $$->current->name;
if (!$2->sink)
$$->connections_pending = g_list_append ($$->connections_pending, $2);
}
| graph property_value { $$ = $1;
$$->current->property_values = g_list_append ($$->current->property_values,
$2);
}
;
bin: '{' graph '}'
| id '.' '(' graph ')'
bin: '{' graph '}' { $$ = $2; $$->current_bin_type = "gstthread"; }
| id '.' '(' graph ')' { $$ = $4; $$->current_bin_type = $1; }
;
connection: lconnection
| rconnection
| bconnection
| qconnection
| iconnection
;
lconnection: qid '+' '!'
lconnection: qid '+' '!' { $$ = g_new0 (connection_t, 1);
$$->src = $1->id1;
$$->src_pads = g_list_append ($$->src_pads, $1->id2);
}
;
rconnection: '!' '+' qid
rconnection: '!' '+' qid { $$ = g_new0 (connection_t, 1);
$$->sink = $3->id1;
$$->sink_pads = g_list_append ($$->src_pads, $3->id2);
}
;
bconnection: '!'
| qid '+' bconnection '+' qid
qconnection: qid '+' '!' '+' qid { $$ = g_new0 (connection_t, 1);
$$->src = $1->id1;
$$->src_pads = g_list_append ($$->src_pads, $1->id2);
$$->sink = $5->id1;
$$->sink_pads = g_list_append ($$->sink_pads, $5->id2);
}
;
iconnection: '!' { $$ = g_new0 (connection_t, 1); }
| id '+' iconnection '+' id
{ $$ = $3;
$$->src_pads = g_list_append ($$->src_pads, $1);
$$->sink_pads = g_list_append ($$->sink_pads, $5);
}
;
%%
@ -89,5 +145,9 @@ int main (int argc, char **argv)
else
yyin = stdin;
#ifdef DEBUG
yydebug = 1;
#endif
return yyparse();
}

View file

@ -2,7 +2,7 @@
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <glib.h>
#include "types.h"
#include <grammar.tab.h>
#ifdef DEBUG

38
gst/parse/types.h Normal file
View file

@ -0,0 +1,38 @@
#include <glib-object.h>
typedef struct {
gchar *name;
GList *property_values;
} element_t;
typedef struct {
gchar *name;
GType value_type;
union {
gdouble d;
gboolean b;
gint i;
gchar *s;
} value;
} property_t;
typedef struct {
char *src;
char *sink;
GList *src_pads;
GList *sink_pads;
} connection_t;
typedef struct {
element_t *current;
gchar *current_bin_type;
GList *elements;
GList *connections;
GList *connections_pending;
GList *bins;
} graph_t;
typedef struct {
gchar *id1;
gchar *id2;
} hash_t;