Commit 832f0a78 authored by Andy Wingo Wingo's avatar Andy Wingo Wingo

add (incomplete) flex/bison-based parser to cvs the tokenizer is functional,...

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.
parent 06c7e989
......@@ -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
......
......@@ -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 = \
......
grammar
grammar.output
grammar.tab.c
grammar.tab.h
lex.yy.c
parse.c
#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
%{
#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();
}
%{
#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);
}
%%
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment