the parser works properly, but it doesn't do anything yet
authorAndy Wingo <wingo@pobox.com>
Mon, 1 Apr 2002 04:36:56 +0000 (04:36 +0000)
committerAndy Wingo <wingo@pobox.com>
Mon, 1 Apr 2002 04:36:56 +0000 (04:36 +0000)
Original commit message from CVS:
* the parser works properly, but it doesn't do anything yet

gst/parse/Makefile.am
gst/parse/grammar.y
gst/parse/parse.l

index a73cfa7..5af860f 100644 (file)
@@ -2,20 +2,22 @@
 
 #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
index e62fd2e..fb14dd3 100644 (file)
@@ -1,6 +1,8 @@
 %{
 #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
@@ -51,22 +60,14 @@ 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
         ;
 
 %%
index d0da883..6ecbb0b 100644 (file)
@@ -5,7 +5,13 @@
 #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:]]+
@@ -21,20 +27,20 @@ _string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"")
 
 <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;
     }
@@ -44,20 +50,21 @@ _string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"")
             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 ('='); }
@@ -73,10 +80,11 @@ _string ([^[:space:]\"]|"\\\"")+|("\""([^\"]|"\\\"")*"\"")
 "!" { CHAR ('!'); }
 "+" { CHAR ('+'); }
 
-[[:space:]]+ { /* printf ("space: [%s]\n", yytext); */ }
+[[:space:]]+ { PRINT ("space: [%s]\n", yytext); }
 
 . {
     printf ("unknown: %s\n", yytext);
+    return *yytext;
 }
 
 %%