form a semantic representation of the pipeline in preparation for actual instantiation.
authorAndy Wingo <wingo@pobox.com>
Mon, 1 Apr 2002 06:30:39 +0000 (06:30 +0000)
committerAndy Wingo <wingo@pobox.com>
Mon, 1 Apr 2002 06:30:39 +0000 (06:30 +0000)
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

gst/parse/Makefile.am
gst/parse/grammar.y
gst/parse/parse.l
gst/parse/types.h [new file with mode: 0644]

index 5af860f..0f19ed6 100644 (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
 
index fb14dd3..08eba24 100644 (file)
@@ -1,6 +1,7 @@
 %{
 #include <glib.h>
 #include <stdio.h>
+#include "types.h"
 #define YYDEBUG 1
 #define YYERROR_VERBOSE 1
 %}
     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
 %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 '+'
 %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 '+' '!'          { $$ = g_new0 (connection_t, 1);
+                                       $$->src = $1->id1;
+                                       $$->src_pads = g_list_append ($$->src_pads, $1->id2);
+                                     }
         ;
 
-lconnection:    qid '+' '!'
+rconnection:    '!' '+' qid          { $$ = g_new0 (connection_t, 1);
+                                       $$->sink = $3->id1;
+                                       $$->sink_pads = g_list_append ($$->src_pads, $3->id2);
+                                     }
         ;
 
-rconnection:    '!' '+' 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);
+                                     }
         ;
 
-bconnection:    '!'
-        |       qid '+' bconnection '+' qid
+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);
+                                     }
         ;
 
 %%
@@ -88,6 +144,10 @@ int main (int argc, char **argv)
         yyin = fopen (argv[0], "r");
     else
         yyin = stdin;
-    
+
+#ifdef DEBUG
+    yydebug = 1;
+#endif
+
     return yyparse();
 }
index 6ecbb0b..cb32ac1 100644 (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
diff --git a/gst/parse/types.h b/gst/parse/types.h
new file mode 100644 (file)
index 0000000..a227ca7
--- /dev/null
@@ -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;