next up previous contents
Next: About this document ... Up: Design And implementation of Previous: Scanner - the input   Contents


Parser - the input file for Bison

Below there is the input file for Bison, to generate the parser which parses Osiris datafile in Controller module to load up stored logic.

The generated parser cooperates with the scanner described in Appendix E.

%{

/* C declarations */

#include <gtk/gtk.h>
#include <glib.h>
#include "../opensave.h"

/* verbose error reporting */

#define YYERROR_VERBOSE

/* global variables */

extern FILE *yyin;
extern GList *yylist;

%}

/* bison declarations */

%union{
  gint integer;
  gint32 int32;
  gchar *string;
  graph_object *obj;
  enum type_of_object type;
  GList *list;
}

/* terminals */
%token <string> STRING
%token <integer> INTEGER

%token PREAMBLE "<?xml version=\"1.0\"?>"
%token OSIRISB "<osiris>"
%token OSIRISE "</osiris>"
%token PROJECTB "<project>"
%token PROJECTE "</project>"
%token OUTPUTFNB "<outputfn>"
%token OUTPUTFNE "</outputfn>"
%token VALIDATORB "<validator>"
%token VALIDATORE "</validator>"
%token GENERATORB "<generator>"
%token GENERATORE "</generator>"
%token LAUNCHERB  "<launcher>"
%token LAUNCHERE  "</launcher>"
%token OBJECTB "<object>"
%token OBJECTE "</object>"
%token IDB "<id>"
%token IDE "</id>"
%token XB "<x>"
%token XE "</x>"
%token YB "<y>"
%token YE "</y>"
%token WIDTHB "<width>"
%token WIDTHE "</width>"
%token HEIGHTB "<height>"
%token HEIGHTE "</height>"
%token TYPEB "<type>"
%token TYPEE "</type>"
%token COLSB "<cols>"
%token COLSE "</cols>"
%token ROWSB "<rows>"
%token ROWSE "</rows>"
%token TABLEB "<table>"
%token TABLEE "</table>"
%token CONNECTIONB "<connection>"
%token CONNECTIONE "</connection>"
%token LASTIDB "<lastid>"
%token LASTIDE "</lastid>"

/* non terminals */

%type <int32> id
%type <integer> x
%type <integer> y
%type <integer> width
%type <integer> height
%type <integer> cols
%type <integer> rows
%type <list> table
%type <obj> object
%type <type> type
%type <list> connection
%type <string> output_filename
%type <string> validator_fn
%type <string> generator_fn
%type <string> launcher_fn
%type <string> table_contents
%type <obj> connection_contents
%type <int32> lastid

%%

/* grammar rules */

preamble:  PREAMBLE OSIRISB body OSIRISE
;

body:    project
|        body object
;

project: PROJECTB
          output_filename
          validator_fn
          generator_fn
          launcher_fn
          lastid
         PROJECTE 
{ 
  output_filename=$2;
  validator_fn=$3;
  generator_fn=$4;
  launcher_fn=$5;
  last_ID=$6;
}
;

lastid: LASTIDB INTEGER LASTIDE {$$=$2;}

output_filename: OUTPUTFNB
                  STRING
                 OUTPUTFNE {$$=g_strdup($2);}
;

validator_fn: VALIDATORB
               STRING
              VALIDATORE {$$=g_strdup($2);}
;

generator_fn: GENERATORB
               STRING
              GENERATORE {$$=g_strdup($2);}
;

launcher_fn: LAUNCHERB
              STRING
             LAUNCHERE {$$=g_strdup($2);}
;

object: OBJECTB
         id
         x
         y
         width
         height
         type
         cols
         rows
         table
         connection
        OBJECTE     
{$$=restore_object($2,$3,$4,$5,$6,$7,$8,$9,$10,$11);}
;


id: IDB INTEGER IDE {$$=$2;}
;

x: XB INTEGER XE {$$=$2;}
;

y: YB INTEGER YE {$$=$2;}
;

width: WIDTHB INTEGER WIDTHE {$$=$2;}
;

height: HEIGHTB INTEGER HEIGHTE {$$=$2;}
;

type: TYPEB STRING TYPEE 
      {$$=(strcmp($2,"action")==0?ACTION:ATTRIBUTE);}
;

cols: COLSB
       INTEGER
      COLSE {$$=$2;}
;

rows: ROWSB
       INTEGER
      ROWSE {$$=$2;}
;

table: TABLEB table_contents TABLEE 
               {$$=g_list_append(NULL,$2);}
|      table TABLEB table_contents TABLEE
               {$$=g_list_append($1,$3);}
;

table_contents:               {$$=NULL;}
|                 STRING      {$$=g_strdup($1);}
|                 INTEGER     {$$=g_strdup_printf("%d",$1);}
;
 
connection: CONNECTIONB connection_contents CONNECTIONE
                 {$$=g_list_append(NULL,NULL);
                  $$=g_list_append($$,$2);}
|           connection CONNECTIONB connection_contents CONNECTIONE 
                 {$$=g_list_append($1,$3);}
;   

connection_contents:             {$$=NULL;}
|                    object      {$$=$1;}
;

%%

/* additional C code */



Igor Wojnicki 2001-02-21