From 832f0a78522dda79c857fa8ebfef55b14c436c26 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Sun, 31 Mar 2002 21:09:17 +0000 Subject: [PATCH] add (incomplete) flex/bison-based parser to cvs the tokenizer is functional, but the grammar definition is bad. this ... 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 | 5 +-- gst/Makefile.am | 4 +-- gst/parse/.gitignore | 6 ++++ gst/parse/Makefile.am | 21 ++++++++++++ gst/parse/grammar.y | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ gst/parse/parse.l | 82 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 gst/parse/.gitignore create mode 100644 gst/parse/Makefile.am create mode 100644 gst/parse/grammar.y create mode 100644 gst/parse/parse.l diff --git a/configure.ac b/configure.ac index 5262bbb..16f36d0 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/gst/Makefile.am b/gst/Makefile.am index ac40feb..ddc82cf 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -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 index 0000000..679f5b6 --- /dev/null +++ b/gst/parse/.gitignore @@ -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 index 0000000..a73cfa7 --- /dev/null +++ b/gst/parse/Makefile.am @@ -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 index 0000000..e62fd2e --- /dev/null +++ b/gst/parse/grammar.y @@ -0,0 +1,92 @@ +%{ +#include +#include +%} + +%union { + double d; + gboolean b; + gint i; + gchar *s; +} + +%token IDENTIFIER STRING +%token FLOAT +%token INTEGER +%token 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 index 0000000..d0da883 --- /dev/null +++ b/gst/parse/parse.l @@ -0,0 +1,82 @@ +%{ +#include +#include +#include +#include +#include + +#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 +%% + +{ + {_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); +} + +%% -- 2.7.4