#libgstparse_la_SOURCES = parse.c grammar.c
+BISON = bison -d
+
noinst_PROGRAMS = grammar
grammar_SOURCES = lex.yy.c grammar.tab.c
-grammar_CFLAGS = $(GLIB_CFLAGS) -DYYERROR_VERBOSE
+grammar_CFLAGS = $(GLIB_CFLAGS)
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
+ $(BISON) grammar.y
grammar.tab.c: grammar.y
- bison -v -d grammar.y
+ $(BISON) grammar.y
lex.yy.c: parse.l
flex parse.l
%{
#include <glib.h>
#include <stdio.h>
+#define YYDEBUG 1
+#define YYERROR_VERBOSE 1
%}
%union {
%token <i> INTEGER
%token <b> BOOLEAN
+%left '{' '}' '(' ')'
+%left '!' '='
+%left '+'
+%left '.'
+
+%start graph
%%
-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"); }
+id: IDENTIFIER {}
+ ;
+
+qid: id
+ | id '.' id
;
-property_value: property '=' value { printf ("got property=value\n"); }
+value: STRING {}
+ | FLOAT {}
+ | INTEGER {}
+ | BOOLEAN {}
;
-property: identifier { printf ("got unadorned property name\n"); }
- | identifier '.' identifier { printf ("got qualified property name\n"); }
+property_value: qid '=' value
;
-value: STRING { printf ("got string\n"); }
- | FLOAT { printf ("got float\n"); }
- | INTEGER { printf ("got integer\n"); }
- | BOOLEAN { printf ("got boolean\n"); }
+element: id
+ | bin
;
-element: identifier { printf ("got element\n"); }
- | bin { printf ("new element, it's a bin\n"); }
+graph: /* empty */
+ | graph element
+ | graph connection
+ | graph property_value
;
-bin: '{' graph '}' { printf ("new thread\n"); }
- | identifier '.' '(' graph ')' { printf ("new named bin\n"); }
+bin: '{' graph '}'
+ | id '.' '(' graph ')'
;
connection: lconnection
| 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"); }
+lconnection: qid '+' '!'
;
-pad_name: identifier { printf ("got pad\n"); }
- | identifier '.' identifier { printf ("got named pad\n"); }
+rconnection: '!' '+' qid
;
-identifier: IDENTIFIER { printf ("matching on identifier\n");}
+bconnection: '!'
+ | qid '+' bconnection '+' qid
;
%%
#include <glib.h>
#include <grammar.tab.h>
-#define CHAR(x) printf ("char: %c\n", *yytext); return *yytext;
+#ifdef DEBUG
+# define PRINT(a...) printf(##a)
+#else
+#define PRINT(a...)
+#endif
+
+#define CHAR(x) PRINT ("char: %c\n", *yytext); return *yytext;
%}
_integer [[:digit:]]+
<value>{
{_integer} {
- printf ("An integer: %s (%d)\n", yytext,
+ PRINT ("An integer: %s (%d)\n", yytext,
atoi (yytext));
BEGIN (INITIAL);
return INTEGER;
}
{_float} {
- printf ("A float: %s (%g)\n", yytext, atof (yytext));
+ PRINT ("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);
+ PRINT ("A boolean: %s (%d)\n", yytext, tolower (*yytext) == 't' ? 1 : 0);
BEGIN (INITIAL);
return BOOLEAN;
}
yytext++;
*(yytext + strlen (yytext) - 1) = '\0';
}
- printf ("A string: %s\n", yytext);
+ PRINT ("A string: %s\n", yytext);
BEGIN (INITIAL);
return STRING;
}
- [[:space:]]+ { /* printf ("space: [%s]\n", yytext); */ }
+ [[:space:]]+ { /* PRINT ("space: [%s]\n", yytext); */ }
. {
- printf ("unknown: %s\n", yytext);
+ PRINT ("unknown: %s\n", yytext);
}
}
{_identifier} {
- printf ("An identifier: %s\n", yytext);
+ PRINT ("An identifier: %s\n", yytext);
+ return IDENTIFIER;
}
"=" { BEGIN (value); CHAR ('='); }
"!" { CHAR ('!'); }
"+" { CHAR ('+'); }
-[[:space:]]+ { /* printf ("space: [%s]\n", yytext); */ }
+[[:space:]]+ { PRINT ("space: [%s]\n", yytext); }
. {
printf ("unknown: %s\n", yytext);
+ return *yytext;
}
%%