the parser works properly, but it doesn't do anything yet

Original commit message from CVS:
* the parser works properly, but it doesn't do anything yet
This commit is contained in:
Andy Wingo 2002-04-01 04:36:56 +00:00
parent 832f0a7852
commit f6112a24bb
3 changed files with 52 additions and 41 deletions

View 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

View file

@ -1,6 +1,8 @@
%{
#include <glib.h>
#include <stdio.h>
#define YYDEBUG 1
#define YYERROR_VERBOSE 1
%}
%union {
@ -15,35 +17,42 @@
%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 {}
;
property_value: property '=' value { printf ("got property=value\n"); }
qid: id
| id '.' id
;
property: identifier { printf ("got unadorned property name\n"); }
| identifier '.' identifier { printf ("got qualified property name\n"); }
value: STRING {}
| FLOAT {}
| INTEGER {}
| BOOLEAN {}
;
value: STRING { printf ("got string\n"); }
| FLOAT { printf ("got float\n"); }
| INTEGER { printf ("got integer\n"); }
| BOOLEAN { printf ("got boolean\n"); }
property_value: qid '=' value
;
element: identifier { printf ("got element\n"); }
| bin { printf ("new element, it's a bin\n"); }
element: id
| bin
;
bin: '{' graph '}' { printf ("new thread\n"); }
| identifier '.' '(' graph ')' { printf ("new named bin\n"); }
graph: /* empty */
| graph element
| graph connection
| graph property_value
;
bin: '{' graph '}'
| id '.' '(' graph ')'
;
connection: lconnection
@ -51,22 +60,14 @@ connection: lconnection
| bconnection
;
lconnection: pad_name '+' '!' { printf ("got lconnection\n"); }
lconnection: qid '+' '!'
;
rconnection: '!' '+' pad_name { printf ("got rconnection\n"); }
rconnection: '!' '+' qid
;
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");}
bconnection: '!'
| qid '+' bconnection '+' qid
;
%%

View 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;
}
%%