unoidl2

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/unoidl2.git/
Log | Files | Refs

parse.y (9608B)


      1 /* uno idl file parser */
      2 /*
      3    This file is part of unoidl2.
      4 
      5    unoidl2 is free software: you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by
      7    the Free Software Foundation, either version 3 of the License, or
      8    (at your option) any later version.
      9 
     10    unoidl2 is distributed in the hope that it will be useful,
     11    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13    GNU General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License
     16    along with unoidl2.  If not, see <http://www.gnu.org/licenses/>.
     17 */
     18 
     19 %{
     20 #include "unoidl2.h"
     21 
     22 #include <stdio.h>
     23 #include <string.h>
     24 
     25 void yyerror(const char *str)
     26 {
     27   fprintf(stderr,"error: %s\n",str);
     28 }
     29 
     30 int yywrap()
     31 {
     32   return 1;
     33 }
     34 
     35 extern int yylex(void);
     36 
     37 extern const Any NIL;
     38 extern const Any T;
     39 
     40 Any ast;
     41 
     42 #define YYSTYPE Any
     43 
     44 Any mk_relative(Any x);
     45 
     46 %}
     47 
     48 %token TRUE FALSE ID BOOL INT OCT HEX REAL
     49 %token EQ LT LE GT GE PLUS MINUS MUL DIV MOD
     50 %token OR XOR AND LSHIFT RSHIFT NOT SCOPE SEMICOLON
     51 %token LPAR RPAR LSQUARE RSQUARE LCURLY RCURLY COMMA COLON
     52 
     53 %token ATTRIBUTE BOUND CASE CONST CONSTANTS CONSTRAINED DEFAULT ENUM
     54 %token EXCEPTION INTERFACE MAYBEAMBIGUOUS MAYBEDEFAULT MAYBEVOID MODULE
     55 %token NEEDS OBSERVES OPTIONAL PROPERTY RAISES READONLY REMOVEABLE SERVICE
     56 %token SEQUENCE SINGLETON STRUCT SWITCH TRANSIENT TYPEDEF UNION ANY BOOLEAN
     57 %token BYTE CHAR DOUBLE HYPER LONG SHORT FLOAT STRING TYPE UNSIGNED VOID IN
     58 %token OUT INOUT ONEWAY GET SET PUBLISHED ELLIPSIS
     59 %token REMOVABLE
     60 
     61 %token METHOD CONSTRUCTOR RELATIVE ABSOLUTE TEMPLATE EXP DEFTEMPLATE
     62 %token DEFINTERFACE
     63 
     64 %%
     65 
     66 ast: declarations {ast = $1};
     67 nil: /* empty */ {$$ = NIL;};
     68 declaration: defenum | defstruct | deftemplate | defexception
     69    | interface_forward | definterface | deftype | constant
     70    | constants | defmodule | interface_service
     71    | accumulated_service | interface_singleton
     72    | service_singleton;
     73 published: nil | PUBLISHED {$$ = T;};
     74 defenum: published ENUM identifier LCURLY enum_members RCURLY SEMICOLON
     75    {$$ = cons4($2, $3, $1, $5)};
     76 enum_members: enum_member {$$ = list1($1);}
     77    | enum_member COMMA enum_members {$$ = cons($1, $3);};
     78 enum_member: identifier | identifier EQ exp {$$ = list2($1, $3);};
     79 defstruct: published STRUCT identifier single_inheritance
     80    LCURLY struct_members RCURLY SEMICOLON {$$ = cons5($2, $3, $1, $4, $6);};
     81 single_inheritance: nil | COLON name {$$ = $2};
     82 struct_members: struct_member {$$ = list1($1);}
     83    | struct_member struct_members {$$ = cons($1, $2);};
     84 struct_member: type identifier SEMICOLON {$$ = list2($2, $1);};
     85 deftemplate: published STRUCT identifier LT identifiers GT
     86    LCURLY template_members RCURLY SEMICOLON
     87    {$$ = cons5(mk(DEFTEMPLATE, "deftemplate"), $3, $1, $5, $8);};
     88 identifiers: identifier {$$ = list1($1);}
     89    | identifier COMMA identifiers {$$ = cons($1, $3)};
     90 template_members: template_member {$$ = list1($1);}
     91    | template_member template_members {$$ = cons($1, $2);};
     92 template_member: struct_member | parametric_member;
     93 parametric_member: identifier identifier SEMICOLON {$$ = list2($2, $1);};
     94 defexception: published EXCEPTION identifier single_inheritance
     95    LCURLY struct_members_opt RCURLY SEMICOLON {$$ = cons5($2, $3, $1, $4, $6);};
     96 struct_members_opt: nil | struct_members;
     97 interface_forward: published INTERFACE name SEMICOLON {$$ = list3($2, $3, $1);};
     98 definterface: published INTERFACE identifier single_inheritance
     99    LCURLY interface_members RCURLY SEMICOLON
    100    {$$ = cons5(mk(DEFINTERFACE, "definterface"), $3, $1, $4, $6);};
    101 interface_members: nil | interface_member interface_members {$$ = cons($1, $2);};
    102 interface_member: interface_inheritance | attribute | interface_forward | defmethod;
    103 interface_inheritance: optional INTERFACE name SEMICOLON {$$ = list3($2, $3, $1);};
    104 optional: nil | LSQUARE OPTIONAL RSQUARE {$$ = $2;};
    105 attribute: attribute_flags type identifier attribute_accesses_opt SEMICOLON
    106    {$$ = cons5(mk(ATTRIBUTE, "attribute"), $2, $3, $1, $4);};
    107 attribute_flags: LSQUARE attribute_flags1 RSQUARE {$$ = $2;};
    108 attribute_flags1: attribute_flags2a ATTRIBUTE attribute_flags2b {$$ = nconc2($1, $3);};
    109 attribute_flags2a: nil | attribute_flag COMMA attribute_flags2a {$$ = cons($1, $3);};
    110 attribute_flags2b: nil | COMMA attribute_flag attribute_flags2b {$$ = cons($2, $3);};
    111 attribute_flag: BOUND | READONLY;
    112 attribute_accesses_opt: nil | LCURLY attribute_accesses2 RCURLY {$$ = $2};
    113 attribute_accesses2: attribute_access {$$ = list1($1);}
    114    | attribute_access attribute_accesses2 {$$ = cons($1, $2);};
    115 attribute_access: attribute_get | attribute_set;
    116 attribute_get: GET exception_spec SEMICOLON {$$ = list2($1, $2);};
    117 attribute_set: SET exception_spec SEMICOLON {$$ = list2($1, $2);};
    118 exception_spec: RAISES LPAR names RPAR {$$ = $3;};
    119 names: name {$$ = list1($1);} | name COMMA names {$$ = cons($1, $3);};
    120 defmethod: oneway type_opt identifier LPAR method_params_opt RPAR
    121    exception_spec_opt SEMICOLON
    122    {$$ = cons6(mk(METHOD, "method"), $3, $1, $2, $5, $7);};
    123 oneway: nil | LSQUARE ONEWAY RSQUARE {$$ = T;};
    124 type_opt: nil | type;
    125 method_params_opt: nil | method_params;
    126 method_params: method_param {$$ = list1($1);}
    127    | method_param COMMA method_params {$$ = cons($1, $3);};
    128 method_param: LSQUARE direction RSQUARE type identifier {$$ = list3($2, $5, $4);};
    129 exception_spec_opt: nil | exception_spec;
    130 direction: IN | OUT | INOUT;
    131 deftype: published TYPEDEF type identifier SEMICOLON {$$ = list4($2, $4, $1, $3);};
    132 constant: published const_decl {$$ = list2($1, $2);};
    133 const_decl: CONST type identifier EQ exp SEMICOLON {$$ = list4($1, $3, $2, $5);};
    134 constants: published CONSTANTS identifier LCURLY const_decls RCURLY SEMICOLON
    135    {$$ = cons4($2, $3, $1, $5);};
    136 const_decls: nil | const_decl const_decls {$$ = cons($1, $2);};
    137 defmodule: MODULE identifier LCURLY declarations RCURLY SEMICOLON
    138    {$$ = cons3($1, $2, $4)};
    139 declarations: nil | declaration declarations {$$ = cons($1, $2);};
    140 interface_service: published SERVICE identifier colon_name_opt
    141    constructors_block SEMICOLON {$$ = cons5($2, $3, $1, $4, $5);};
    142 colon_name_opt: nil | COLON name {$$ = $2;};
    143 constructors_block: nil | LCURLY constructors RCURLY {$$ = $2;};
    144 constructors: nil | constructor constructors {$$ = cons($1, $2);};
    145 constructor: identifier LPAR constructor_params_opt RPAR
    146    exception_spec_opt SEMICOLON
    147    {$$ = cons4(mk(CONSTRUCTOR, "constructor"), $1, $3, $5);};
    148 constructor_params_opt: nil | constructor_params;
    149 constructor_params: rest_param | ctor_params;
    150 ctor_params: ctor_param {$$ = list1($1);}
    151    | ctor_param COMMA ctor_params {$$ = cons($1, $3);};
    152 rest_param: LSQUARE IN RSQUARE ANY ELLIPSIS identifier {$$ = list4($2, $6, $4, $5);};
    153 ctor_param: LSQUARE IN RSQUARE type identifier {$$ = list3($2, $5, $4);};
    154 accumulated_service: published SERVICE identifier colon_name_opt
    155    LCURLY service_member service_members RCURLY SEMICOLON
    156    {$$ = list5($2, $3, $1, $4, cons($6, $7));};
    157 service_members: nil | service_member service_members {$$ = cons($1, $2);};
    158 service_member: service_inheritance | interface_inheritance | property;
    159 service_inheritance: optional SERVICE name SEMICOLON {$$ = list3($2, $3, $1);};
    160 property: property_flags type identifier SEMICOLON
    161    {$$ = list4(mk(PROPERTY, "property"), $3, $2, $1);};
    162 property_flags: LSQUARE property_flags1 RSQUARE {$$ = $2;};
    163 property_flags1: property_flags2a PROPERTY property_flags2b {$$ = nconc2($1, $3);};
    164 property_flags2a: nil | property_flag COMMA property_flags2a {$$ = cons($1, $3);};
    165 property_flags2b: nil | COMMA property_flag property_flags2b {$$ = cons($2, $3);};
    166 property_flag: BOUND | CONSTRAINED | MAYBEAMBIGUOUS | MAYBEDEFAULT
    167    | MAYBEVOID | OPTIONAL | READONLY | REMOVABLE | TRANSIENT;
    168 interface_singleton: published SINGLETON identifier COLON name SEMICOLON
    169    {$$ = list4($2, $3, $1, $5);};
    170 service_singleton: published SINGLETON identifier
    171    LCURLY SERVICE name SEMICOLON RCURLY SEMICOLON
    172    {$$ = list5($2, $3, $1, $6, T);};
    173 type: simple_type {$$ = list1($1);} | unsigned_type | sequence_type
    174    | template_type | name;
    175 simple_type: VOID | BOOLEAN | BYTE | SHORT | LONG | HYPER | FLOAT | DOUBLE
    176    | CHAR | STRING | TYPE | ANY;
    177 unsigned_type: UNSIGNED SHORT {$$ = list2($1, $2);}
    178    | UNSIGNED LONG {$$ = list2($1, $2);}
    179    | UNSIGNED HYPER {$$ = list2($1, $2);};
    180 sequence_type: SEQUENCE LT type GT {$$ = list2($1, $3);};
    181 template_type: name LT type types GT
    182    {$$ = list3(mk(TEMPLATE, "template"), $1, cons($3, $4));};
    183 types: nil | COMMA type types {$$ = cons($2, $3);};
    184 exp: exp_top {$$ = list2(mk(EXP, "exp"), $1);};
    185 exp_top: xor_exp | exp OR xor_exp {$$ = list3($2, $1, $3);};
    186 xor_exp: and_exp | xor_exp XOR and_exp {$$ = list3($2, $1, $3);};
    187 and_exp: shift_exp | and_exp AND shift_exp {$$ = list3($2, $1, $3);};
    188 shift_exp: add_exp | shift_exp shift_op add_exp {$$ = list3($2, $1, $3);};
    189 shift_op: LSHIFT | RSHIFT;
    190 add_exp: mul_exp | add_exp add_op mul_exp {$$ = list3($2, $1, $3);};
    191 add_op: PLUS | MINUS;
    192 mul_exp: unary_exp | mul_exp mul_op unary_exp {$$ = list3($2, $1, $3);};
    193 mul_op: MUL | DIV | MOD;
    194 unary_exp: primary_exp | unary_op primary_exp {$$ = list2($1, $2);};
    195 unary_op: PLUS | MINUS | NOT;
    196 primary_exp: name | literal | LPAR exp RPAR {$$ = $2;};
    197 literal: BOOL | INT | OCT | HEX | REAL;
    198 name: relname {$$ = mk_relative($1);}
    199    | SCOPE relname {$$ = cons(mk(ABSOLUTE, "absolute"), $2);};
    200 relname: identifier {$$ = list1($1);} | identifier SCOPE relname {$$ = cons($1, $3);};
    201 identifier: ID
    202    | GET {$$ = mk(ID, "get");}
    203    | SET {$$ = mk(ID, "set");}
    204    | PUBLISHED {$$ = mk(ID, "published");};
    205 
    206 %%