]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gstreamer0-10.git/commitdiff
add (incomplete) flex/bison-based parser to cvs the tokenizer is functional, but...
authorAndy Wingo <wingo@pobox.com>
Sun, 31 Mar 2002 21:09:17 +0000 (21:09 +0000)
committerAndy Wingo <wingo@pobox.com>
Sun, 31 Mar 2002 21:09:17 +0000 (21:09 +0000)
Original commit message from CVS:
add (incomplete) flex/bison-based parser to cvs

the tokenizer is functional, but the grammar definition is bad. this
probably breaks distcheck somehow, but hey.

configure.ac
gst/Makefile.am
gst/parse/.gitignore [new file with mode: 0644]
gst/parse/Makefile.am [new file with mode: 0644]
gst/parse/grammar.y [new file with mode: 0644]
gst/parse/parse.l [new file with mode: 0644]

index 5262bbb623bd41acd5b44bf1825d19d1c0aa22fa..16f36d012b798168558c4e2a8653659d983ae78c 100644 (file)
@@ -385,10 +385,11 @@ Makefile
 include/Makefile
 gst/Makefile
 gst/gstversion.h
-gst/types/Makefile
-gst/elements/Makefile
 gst/autoplug/Makefile
+gst/elements/Makefile
+gst/parse/Makefile
 gst/schedulers/Makefile
+gst/types/Makefile
 libs/Makefile
 libs/gst/Makefile
 libs/gst/bytestream/Makefile
index ac40feb0a1436eccc5531743873966274cd0abde..ddc82cf4f71187d0beca798106653728b2bc7462 100644 (file)
@@ -45,8 +45,8 @@ endif
 EXTRA_libgstreamer_la_SOURCES = gstcpuid_i386.s gstmarshal.list gstxml.c gsttypefind.c gstparse.c gstautoplug.c gsttrace.c
 
 # cheap trick to build . first...
-SUBDIRS = . types elements $(GST_AUTOPLUG_DIRS) schedulers
-DIST_SUBDIRS = types elements autoplug schedulers
+SUBDIRS = . $(GST_AUTOPLUG_DIRS) elements schedulers types
+DIST_SUBDIRS = autoplug elements parse types schedulers
 
 libcothreads_la_SOURCES = cothreads.c
 libgstreamer_la_SOURCES =              \
diff --git a/gst/parse/.gitignore b/gst/parse/.gitignore
new file mode 100644 (file)
index 0000000..679f5b6
--- /dev/null
@@ -0,0 +1,6 @@
+grammar
+grammar.output
+grammar.tab.c
+grammar.tab.h
+lex.yy.c
+parse.c
diff --git a/gst/parse/Makefile.am b/gst/parse/Makefile.am
new file mode 100644 (file)
index 0000000..a73cfa7
--- /dev/null
@@ -0,0 +1,21 @@
+#noinst_LTLIBRARIES = libgstparse.la
+
+#libgstparse_la_SOURCES = parse.c grammar.c
+
+noinst_PROGRAMS = grammar
+
+grammar_SOURCES = lex.yy.c grammar.tab.c
+grammar_CFLAGS = $(GLIB_CFLAGS) -DYYERROR_VERBOSE
+
+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
+
+grammar.tab.c: grammar.y
+       bison -v -d grammar.y
+
+lex.yy.c: parse.l
+       flex parse.l
diff --git a/gst/parse/grammar.y b/gst/parse/grammar.y
new file mode 100644 (file)
index 0000000..e62fd2e
--- /dev/null
@@ -0,0 +1,92 @@
+%{
+#include <glib.h>
+#include <stdio.h>
+%}
+
+%union {
+    double d;
+    gboolean b;
+    gint i;
+    gchar *s;
+}
+
+%token <s> IDENTIFIER STRING
+%token <d> FLOAT
+%token <i> INTEGER
+%token <b> BOOLEAN
+
+%%
+
+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"); }
+        ;
+
+property_value: property '=' value        { printf ("got property=value\n"); }
+        ;
+
+property:       identifier                { printf ("got unadorned property name\n"); }
+        |       identifier '.' identifier { printf ("got qualified property name\n"); }
+        ;
+
+value:          STRING                    { printf ("got string\n"); }
+        |       FLOAT                     { printf ("got float\n"); }
+        |       INTEGER                   { printf ("got integer\n"); }
+        |       BOOLEAN                   { printf ("got boolean\n"); }
+        ;
+
+element:        identifier                { printf ("got element\n"); }
+        |       bin                       { printf ("new element, it's a bin\n"); }
+        ;
+
+bin:            '{' graph '}'             { printf ("new thread\n"); }
+        |       identifier '.' '(' graph ')' { printf ("new named bin\n"); }
+        ;
+
+connection:     lconnection
+        |       rconnection
+        |       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"); }
+        ;
+
+pad_name:       identifier                { printf ("got pad\n"); }
+        |       identifier '.' identifier { printf ("got named pad\n"); }
+        ;
+
+identifier:     IDENTIFIER                { printf ("matching on identifier\n");}
+        ;
+
+%%
+
+extern FILE *yyin;
+
+int
+yyerror (const char *s)
+{
+  printf ("error: %s\n", s);
+  return -1;
+}
+
+int main (int argc, char **argv)
+{
+    ++argv, --argc;  /* skip over program name */
+    if ( argc > 0 )
+        yyin = fopen (argv[0], "r");
+    else
+        yyin = stdin;
+    
+    return yyparse();
+}
diff --git a/gst/parse/parse.l b/gst/parse/parse.l
new file mode 100644 (file)
index 0000000..d0da883
--- /dev/null
@@ -0,0 +1,82 @@
+%{
+#include <math.h>
+#include <ctype.h>
+#include <string.h>
+#include <glib.h>
+#include <grammar.tab.h>
+
+#define CHAR(x) printf ("char: %c\n", *yytext); return *yytext;
+%}
+
+_integer [[:digit:]]+
+_float [[:digit:]]+"."*[[:digit:]]*
+_number {_integer}|{_float}
+_boolean "true"|"false"|"TRUE"|"FALSE"
+_identifier [[:alpha:]][[:alnum:]\-_]*
+_string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"")
+
+%x value
+%option noyywrap
+%%
+
+<value>{
+    {_integer} {
+        printf ("An integer: %s (%d)\n", yytext,
+                atoi (yytext));
+        BEGIN (INITIAL);
+        return INTEGER;
+    }
+    
+    {_float}   {
+        printf ("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);
+        BEGIN (INITIAL);
+        return BOOLEAN;
+    }
+    
+    {_string} {
+        if (*yytext == '"') {
+            yytext++;
+            *(yytext + strlen (yytext) - 1) = '\0';
+        }
+        printf ("A string: %s\n", yytext);
+        BEGIN (INITIAL);
+        return STRING;
+    }
+    
+    [[:space:]]+ { /* printf ("space: [%s]\n", yytext); */ }
+    
+    . {
+        printf ("unknown: %s\n", yytext);
+    }
+}
+
+{_identifier} {
+    printf ("An identifier: %s\n", yytext);
+}
+
+"=" { BEGIN (value); CHAR ('='); }
+"@" { CHAR ('@'); }
+"." { CHAR ('.'); }
+"," { CHAR (','); }
+"{" { CHAR ('{'); }
+"}" { CHAR ('}'); }
+"[" { CHAR ('['); }
+"]" { CHAR (']'); }
+"(" { CHAR ('('); }
+")" { CHAR (')'); }
+"!" { CHAR ('!'); }
+"+" { CHAR ('+'); }
+
+[[:space:]]+ { /* printf ("space: [%s]\n", yytext); */ }
+
+. {
+    printf ("unknown: %s\n", yytext);
+}
+
+%%