next up previous contents
Next: About this document ... Up: Writing QSAS Plug-ins Previous: Appendices

Grammar of QTPL in YACC  

This appendix contains the grammar of QTPL written in YACC (`Yet Another Compiler Compiler') which was used to specify the parser for plug-in templates. It constitutes a concise and unambiguous specification of the QSAS Template Language, and is included as reference material for the technically-inclined. The description of QTPL in section 4 should be quite sufficient for most template-writing purposes.

/***********************************************************************
* SCCS id: @(#)parser.y	1.9 11:44:39 12 Dec 1996 
***********************************************************************/

/* Tokens: most are untyped as they don't have associated attributes.
   VARIABLE and QUOTED_TEXT do have attributes, and return information
   about themselves through symbol-table nodes.  */

%token         INTERNAL                /* 'INTERNAL' */
%token         EXTERNAL                /* 'EXTERNAL' */
%token         FILTER                  /* 'FILTER' */

%token <symb>  VARIABLE                /* function or argument name */

%token         ANY_DO                  /* 'ANY_DATA_OBJECT' */
%token         INTEGER                 /* 'INTEGER' */
%token         FLOAT                   /* 'FLOAT' */
%token         STRING                  /* 'STRING' */
%token         TIMETAGS                /* 'TIMETAGS' */
%token         TIME_INTERVAL           /* 'TIME_INTERVAL' */
%token         SCALAR_SERIES           /* 'SCALAR_SERIES' */
%token         VECTOR_SERIES           /* 'VECTOR_SERIES' */
%token         ANY_TS                  /* 'ANY_TIME_SERIES'    */
%token         SCALAR_TS               /* 'SCALAR_TIME_SERIES' */
%token         VECTOR_TS               /* 'VECTOR_TIME_SERIES' */

%token         PUBLIC_NAME             /* 'PUBLIC_NAME'   */
%token         DESCRIPTION             /* 'DESCRIPTION'   */
%token         DEFAULT_VALUE           /* 'DEFAULT_VALUE' */
%token         ENTRY_NAME              /* 'ENTRY_NAME'    */
%token         OBJECT_FILE             /* 'OBJECT_FILE'   */

%token         INPUT                   /* 'INPUT' */
%token         OUTPUT                  /* 'OUTPUT' */

%token <symb>  QUOTED_TEXT             /* ASCII text in double-quotes */


/* Now type declarations for the non-terminals. */

%type  <symb>        function_list
%type  <symb>        function
%type  <func_type>   f_type

%type  <symb>        parameter_list
%type  <symb>        argument_list
%type  <symb>        argument
%type  <arg_type>    arg_type
%type  <var_type>    d_o_type

%type  <symb>        description_list
%type  <symb>        desc_list
%type  <symb>        desc_pair_list
%type  <symb>        desc_pair
%type  <symb>        desc
%type  <desc_type>   desc_type
%type  <symb>        desc_value

%%

/* Grammar rules: "declaration" is the sentence symbol of the grammar. */

declaration           :      function_list
                      ;

function_list         :      function  { $$ = $1 ; }
                      |      function_list function
                             {yyerror("List of plug-ins not supported");}
                      ;

function              :      f_type VARIABLE '(' parameter_list ')'
                                '{' description_list '}'
                            {
                             $$ = $2;
                             $$->type = Q_FUNCTION;
                             $$->u.f = create_qtpl_function();
                             $$->u.f->type = $1;
                             $$->u.f->name = $2->name;
                             $$->u.f->args = $4->u.a;
                             qtpl_desc_list_apply($$, $7);
                             qtpls_print_node($$);
                            }
                      ;

f_type                :      INTERNAL  { $$ = F_INTERNAL; }
                      |      EXTERNAL  { $$ = F_EXTERNAL; }
                      |      FILTER    { $$ = F_FILTER; }
                      ;

parameter_list        :      argument_list  { $$ = $1 ; }
                      |        
                             { $$ = NULL ; }
                      ;

argument_list         :      argument  { $$ = $1 ; }
                      |      argument_list ',' argument
                            {
                             qtpl_arg_join($1, $3->u.a);
                             $$ = $1;
                            }
                      ;

argument              :      arg_type d_o_type VARIABLE
                            {
                             $$ = $3;
                             $$->type = Q_ARGUMENT;
                             $$->u.a = create_qtpl_argument();
                             $$->u.a->next = NULL;
                             $$->u.a->arg_type = $1;
                             $$->u.a->var_type = $2;
                             $$->u.a->name = $3->name;
                            }
                      ;

arg_type              :      INPUT    { $$ = A_INPUT ;  }
                      |      OUTPUT   { $$ = A_OUTPUT ; }
                      ;

d_o_type              :      ANY_DO          { $$ = V_ANY_DO ;        }
                      |      INTEGER         { $$ = V_INTEGER ;       }
                      |      FLOAT           { $$ = V_FLOAT ;         }
                      |      STRING          { $$ = V_STRING ;        }
                      |      TIMETAGS        { $$ = V_TIMETAGS ;      }
                      |      TIME_INTERVAL   { $$ = V_TIME_INTERVAL ; }
                      |      SCALAR_SERIES   { $$ = V_SCALAR_SERIES ; }
                      |      VECTOR_SERIES   { $$ = V_VECTOR_SERIES ; }
                      |      ANY_TS          { $$ = V_ANY_TS ;        }
                      |      SCALAR_TS       { $$ = V_SCALAR_TS ;     }
                      |      VECTOR_TS       { $$ = V_VECTOR_TS ;     }
                      ;


description_list      :      desc_list  { $$ = $1 ; }
                      |
                            { $$ = NULL ; }
                      ;

desc_list             :      desc  { $$ = $1; }
                      |      desc_list desc
                            {
                             qtpl_desc_join ($1, $2->u.d);
                             $$ = $1;
                            }
                      ;

desc                  :      VARIABLE '{' desc_pair_list '}'
                            {
                              qtpl_set_describee ($3->u.d, $1->name);
                              $$ = $3;
                            }
                      ;

desc_pair_list        :      desc_pair  { $$ = $1; }
                      |      desc_pair_list desc_pair
                            {
                             qtpl_desc_join ($1, $2->u.d);
                             $$ = $1;
                            }
                      ;

desc_pair             :      desc_type '{' desc_value '}'
                            {
                              $3->type = Q_DESCRIPTOR;
                              $3->u.d = create_qtpl_descriptor();
                              $3->u.d->type = $1;
                              $3->u.d->next = NULL;
                              $3->u.d->value=$3->name;
                              $$ = $3;
                            }
                      ;

desc_type             :      PUBLIC_NAME    { $$ = D_PUBLIC_NAME ;   }
                      |      DESCRIPTION    { $$ = D_DESCRIPTION ;   }
                      |      DEFAULT_VALUE  { $$ = D_DEFAULT_VALUE ; }
                      |      ENTRY_NAME     { $$ = D_ENTRY_NAME ;    }
                      |      OBJECT_FILE    { $$ = D_OBJECT_FILE ;   }
                      ;

desc_value            :      QUOTED_TEXT  { $$ = $1 ; }
                      ;

%%

/***********************************************************************/



Tony Allen
8/23/1999