unoidl2

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

commit 6a5f084f657a73620b0e0e6fa2e07d5c8dc47ec7
parent c5c5aa9ab495ed47116324dde8a6acf8edf4a663
Author: Tomas Hlavaty <tom@logand.com>
Date:   Fri,  2 Dec 2011 00:14:51 +0100

parser compiles

Diffstat:
Mparse.y | 224+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mscan.ll | 14++++++--------
Munoidl2.c | 4++--
3 files changed, 118 insertions(+), 124 deletions(-)

diff --git a/parse.y b/parse.y @@ -18,127 +18,123 @@ extern int yylex(void); Any ast; -%} +extern const Any NIL; +extern const Any T; -%union { - Any a; -} +#define YYSTYPE Any -%token<a> TRUE FALSE ID BOOL INT FLOAT EQ LT LE GT GE PLUS MINUS MUL DIV MOD -%token<a> OR XOR AND LSHIFT RSHIFT NOT SCOPE SEMICOLON -%token<a> LPAR RPAR LSQUARE RSQUARE LCURLY RCURLY COMMA COLON +%} -%token<a> ATTRIBUTE BOUND CASE CONST CONSTANTS CONSTRAINED DEFAULT ENUM -%token<a> EXCEPTION INTERFACE MAYBEAMBIGUOUS MAYBEDEFAULT MAYBEVOID MODULE -%token<a> NEEDS OBSERVES OPTIONAL PROPERTY RAISES READONLY REMOVEABLE SERVICE -%token<a> SEQUENCE SINGLETON STRUCT SWITCH TRANSIENT TYPEDEF UNION ANY BOOLEAN -%token<a> BYTE CHAR DOUBLE HYPER LONG SHORT STRING TYPE UNSIGNED VOID IN -%token<a> OUT INOUT ONEWAY GET SET PUBLISHED ELLIPSIS FLOATING_PT_LITERAL +%token TRUE FALSE ID BOOL INT FLOAT EQ LT LE GT GE PLUS MINUS MUL DIV MOD +%token OR XOR AND LSHIFT RSHIFT NOT SCOPE SEMICOLON +%token LPAR RPAR LSQUARE RSQUARE LCURLY RCURLY COMMA COLON -%type<a> exp xor_exp and_exp shift_exp add_exp mul_exp unary_exp primary_exp -%type<a> shift_op add_op mul_op unary_op name relname literal identifier +%token ATTRIBUTE BOUND CASE CONST CONSTANTS CONSTRAINED DEFAULT ENUM +%token EXCEPTION INTERFACE MAYBEAMBIGUOUS MAYBEDEFAULT MAYBEVOID MODULE +%token NEEDS OBSERVES OPTIONAL PROPERTY RAISES READONLY REMOVEABLE SERVICE +%token SEQUENCE SINGLETON STRUCT SWITCH TRANSIENT TYPEDEF UNION ANY BOOLEAN +%token BYTE CHAR DOUBLE HYPER LONG SHORT STRING TYPE UNSIGNED VOID IN +%token OUT INOUT ONEWAY GET SET PUBLISHED ELLIPSIS FLOATING_PT_LITERAL +%token REMOVABLE %% -/* idl_specification: nil | declaration; */ -/* nil: {$$ = nil;}; */ -/* declaration: defenum | defstruct | deftemplate | defexception */ -/* | interface_forward_decl | definterface | deftype | constant_decl */ -/* | constants_decl | defmodule | interface_service_decl */ -/* | accumulated_service_decl | interface_singleton_decl */ -/* | service_singleton_decl; */ -/* published: nil | PUBLISHED {$$ = T;}; */ -/* defenum: published ENUM identifier LCURLY enum_members RCURLY SEMICOLON; */ -/* enum_members: enum_member {$$ = cons($1, NIL);} */ -/* | enum_member COMMA enum_members {$$ = cons($1, $2);}; */ -/* enum_member: identifier | identifier EQ exp {$$ = list3($2, $1, $3);}; */ -/* defstruct: published STRUCT identifier single_inheritance */ -/* LCURLY struct_members RCURLY SEMICOLON; */ -/* single_inheritance: nil | COLON name; */ -/* struct_members: struct_member | struct_member struct_members; */ -/* struct_member: type identifier SEMICOLON; */ -/* deftemplate: published STRUCT identifier struct_params */ -/* LCURLY template_members RCURLY SEMICOLON; */ -/* struct_params: LT identifiers GT; */ -/* identifiers: identifier {$$ = cons($1, NIL);} */ -/* | identifier COMMA identifiers {$$ = cons($1, $3)}; */ -/* template_members: template_member | template_member template_members; */ -/* template_member: struct_member_decl | parametric_member_decl; */ -/* parametric_member: identifier identifier SEMICOLON; */ -/* defexception: published EXCEPTION identifier single_inheritance LCURLY struct_members_opt RCURLY SEMICOLON; */ -/* struct_members_opt: nil | struct_members; */ -/* interface_forward_decl: published INTERFACE identifier SEMICOLON; */ -/* definterface: published INTERFACE identifier single_inheritance LCURLY interface_members_opt RCURLY SEMICOLON; */ -/* interface_member: interface_inheritance | attribute | defmethod; */ -/* interface_inheritance: optional INTERFACE name SEMICOLON {$$ = list2($3, $1);}; */ -/* optional: nil | LSQUARE OPTIONAL RSQUARE {$$ = $2;}; */ - -/* attribute_decl: attribute_flags type identifier attribute_accesses_opt SEMICOLON; */ -/* attribute_accesses_opt: nil | LCURLY attribute_accesses RCURLY; */ - -/* attribute_flags: LSQUARE (attribute_flag COMMA)* ATTRIBUTE (COMMA attribute_flag)* RSQUARE */ - -/* attribute_flag: BOUNG | READONLY; */ -/* attribute_access_decl: attribute_get | attribute_set; */ -/* attribute_get: GET exception_spec SEMICOLON; */ -/* attribute_set: SET exception_spec SEMICOLON; */ - -/* exception_spec: RAISES LPAR name (COMMA name)* RPAR */ - -/* method_decl: [LSQUARE ONEWAY RSQUARE] [type] identifier LPAR [method_param (COMMA method_param)*] RPAR [exception_spec] SEMICOLON */ - -/* method_param: LSQUARE direction RSQUARE type identifier; */ - -/* direction: IN | OUT | INOUT; */ - -/* deftype: published TYPEDEF type identifier SEMICOLON; */ - -/* constant_decl: published const_decl; */ - -/* const_decl: CONST type identifier EQ exp SEMICOLON; */ - -/* constants_decl: published CONSTANTS identifier LCURLY const_decl* RCURLY SEMICOLON; */ - -/* defmodule: MODULE identifier LCURLY declaration* RCURLY SEMICOLON */ - -/* interface_service_decl: published SERVICE identifier [COLON name] [LCURLY constructor_decl* RCURLY] SEMICOLON */ - -/* constructor_decl: identifier LPAR [constructor_params] RPAR [exception_spec] SEMICOLON */ - -/* constructor_params: rest_param | ctor_param (COMMA ctor_param)* */ - -/* rest_param: LSQUARE IN RSQUARE ANY "..." identifier */ - -/* ctor_param: LSQUARE IN RSQUARE type identifier */ - -/* accumulated_service_decl: published SERVICE identifier [COLON name"]{" service_member_decl+ RCURLY SEMICOLON */ - -/* service_member_decl: service_inheritance_decl | interface_inheritance_decl | property_decl */ - -/* service_inheritance_decl: [LSQUARE OPTIONAL RSQUARE] SERVICE name SEMICOLON */ - -/* property_decl: property_flags type identifier SEMICOLON; */ - -/* property_flags: LSQUARE (property_flag COMMA)* PROPERTY (COMMA property_flag)* RSQUARE */ - -/* property_flag: BOUND | CONSTRAINED | MAYBEAMBIGUOUS | MAYBEDEFAULT | MAYBEVOID | OPTIONAL | READONLY | REMOVABLE | TRANSIENT */ - -/* interface_singleton_decl: published SINGLETON identifier COLON name SEMICOLON */ - -/* service_singleton_decl: published SINGLETON identifier LCURLY SERVICE name SEMICOLON RCURLY SEMICOLON */ - - -/* type: simple_type | sequence_type | template_type | name; */ -/* simple_type: VOID | BOOLEAN | BYTE | SHORT | UNSIGNED SHORT | LONG */ -/* | UNSIGNED LONG | HYPER | UNSIGNED HYPER | FLOAT | DOUBLE | CHAR */ -/* | STRING | TYPE | ANY; */ -/* sequence_type: SEQUENCE LT type GT; */ - -/* template_type: name LT type GT | (COMMA type)* ">" */ - - - -ast: exp {ast = $1}; +ast: idl_specification {ast = $1}; +idl_specification: nil | declaration; +nil: {$$ = NIL;}; +declaration: defenum | defstruct | deftemplate | defexception + | interface_forward | definterface | deftype | constant + | constants | defmodule | interface_service + | accumulated_service | interface_singleton + | service_singleton; +published: nil | PUBLISHED {$$ = T;}; +defenum: published ENUM identifier LCURLY enum_members RCURLY SEMICOLON; +enum_members: enum_member {$$ = list1($1);} + | enum_member COMMA enum_members {$$ = cons($1, $2);}; +enum_member: identifier | identifier EQ exp {$$ = list3($2, $1, $3);}; +defstruct: published STRUCT identifier single_inheritance + LCURLY struct_members RCURLY SEMICOLON; +single_inheritance: nil | COLON name; +struct_members: struct_member | struct_member struct_members; +struct_member: type identifier SEMICOLON; +deftemplate: published STRUCT identifier struct_params + LCURLY template_members RCURLY SEMICOLON; +struct_params: LT identifiers GT; +identifiers: identifier {$$ = list1($1);} + | identifier COMMA identifiers {$$ = cons($1, $3)}; +template_members: template_member | template_member template_members; +template_member: struct_member | parametric_member; +parametric_member: identifier identifier SEMICOLON; +defexception: published EXCEPTION identifier single_inheritance LCURLY struct_members_opt RCURLY SEMICOLON; +struct_members_opt: nil | struct_members; +interface_forward: published INTERFACE identifier SEMICOLON; +definterface: published INTERFACE identifier single_inheritance + LCURLY interface_members RCURLY SEMICOLON; +interface_members: nil | interface_member interface_members; +interface_member: interface_inheritance | attribute | defmethod; +interface_inheritance: optional INTERFACE name SEMICOLON {$$ = list2($3, $1);}; +optional: nil | LSQUARE OPTIONAL RSQUARE {$$ = $2;}; +attribute: attribute_flags type identifier attribute_accesses_opt SEMICOLON; +attribute_accesses_opt: nil | LCURLY attribute_accesses2 RCURLY {$$ = $2}; +attribute_accesses2: attribute_access {$$ = list1($1);} + | attribute_access attribute_accesses2 {$$ = cons($1, $2);}; +attribute_flags: LSQUARE attribute_flags ATTRIBUTE attribute_flags_cdr RSQUARE; +attribute_flags: nil | attribute_flag | attribute_flag attribute_flags_cdr; +attribute_flags_cdr: COMMA attribute_flag | COMMA attribute_flag attribute_flags_cdr; +attribute_flag: BOUND | READONLY; +attribute_access: attribute_get | attribute_set; +attribute_get: GET exception_spec SEMICOLON; +attribute_set: SET exception_spec SEMICOLON; +exception_spec: RAISES LPAR names RPAR; +names: name | name COMMA names; +defmethod: oneway type_opt identifier LPAR method_params RPAR exception_spec SEMICOLON; +oneway: nil | LSQUARE ONEWAY RSQUARE {$$ = T;}; +type_opt: nil | type; +method_params: method_param method_params_cdr; +method_params_cdr: nil | COMMA method_param; +method_param: LSQUARE direction RSQUARE type identifier; +exception_spec_opt: nil | exception_spec; +direction: IN | OUT | INOUT; +deftype: published TYPEDEF type identifier SEMICOLON; +constant: published const_decl; +const_decl: CONST type identifier EQ exp SEMICOLON; +constants: published CONSTANTS identifier LCURLY const_decls RCURLY SEMICOLON; +const_decls: nil | const_decl const_decls; +defmodule: MODULE identifier LCURLY declarations RCURLY SEMICOLON; +declarations: nil | declaration declarations; +interface_service: published SERVICE identifier colon_name_opt + constructors_block SEMICOLON; +colon_name_opt: nil | COLON name; +constructors: nil | constructor constructors; +constructor: identifier LPAR constructor_params_opt RPAR + exception_spec_opt SEMICOLON; +constructors_block: nil | LCURLY constructors RCURLY; +constructor_params_opt: nil | constructor_params; +constructor_params: rest_param | ctor_params; +ctor_params: ctor_param | ctor_param COMMA ctor_params; +rest_param: LSQUARE IN RSQUARE ANY ELLIPSIS identifier; +ctor_param: LSQUARE IN RSQUARE type identifier; +accumulated_service: published SERVICE identifier colon_name_opt + LCURLY service_members RCURLY SEMICOLON; +service_members: service_member | service_member service_members; +service_member: service_inheritance | interface_inheritance | property; +service_inheritance: optional SERVICE name SEMICOLON; +property: property_flags type identifier SEMICOLON; +property_flags: LSQUARE property_flag property_flags_cdr + PROPERTY property_flags_cdr RSQUARE; +property_flags_cdr: nil | COMMA property_flag property_flags_cdr; +property_flag: BOUND | CONSTRAINED | MAYBEAMBIGUOUS | MAYBEDEFAULT + | MAYBEVOID | OPTIONAL | READONLY | REMOVABLE | TRANSIENT; +interface_singleton: published SINGLETON identifier COLON name SEMICOLON; +service_singleton: published SINGLETON identifier + LCURLY SERVICE name SEMICOLON RCURLY SEMICOLON; +type: simple_type | sequence_type | template_type | name; +simple_type: VOID | BOOLEAN | BYTE | SHORT | UNSIGNED SHORT | LONG + | UNSIGNED LONG | HYPER | UNSIGNED HYPER | FLOAT | DOUBLE | CHAR + | STRING | TYPE | ANY; +sequence_type: SEQUENCE LT type GT; +template_type: name LT types GT; +types: nil | type COMMA types; exp: xor_exp | exp OR xor_exp {$$ = list3($2, $1, $3);}; xor_exp: and_exp | xor_exp XOR and_exp {$$ = list3($2, $1, $3);}; and_exp: shift_exp | and_exp AND shift_exp {$$ = list3($2, $1, $3);}; diff --git a/scan.ll b/scan.ll @@ -1,16 +1,18 @@ %{ #include "unoidl2.h" + +#define YYSTYPE Any + #include "parse.c.h" #include <stdio.h> -//#include <string.h> char *strdup(char *); int yycolumn = 1; -enum yytokentype tok(enum yytokentype kind, char *token) { +Kind tok(Kind kind, char *token) { printf("{%s}\n", token); - yylval.a = mk(kind, token); + yylval = mk(kind, token); return kind; } %} @@ -116,11 +118,7 @@ published return tok(PUBLISHED, "published"); "..." return tok(ELLIPSIS, "ellipsis"); -"//"[^/]{1}.*"\n" {yylineno++;} - -"///".*"\n" {yylineno++;} - -{DIGIT}+ return tok(INT, strdup(yytext)); +{DIGIT}+ return tok(INT, strdup(yytext)); . return yytext[0]; diff --git a/unoidl2.c b/unoidl2.c @@ -18,9 +18,9 @@ struct any { } u; }; -static const Any NIL = NULL; +const Any NIL = NULL; static struct any _T = {.tag = CONS, .u = {.t = {.kind = 0, .token = "T"}}}; -static const Any T = &_T; +const Any T = &_T; Any cons(Any car, Any cdr) { Any x = malloc(sizeof(struct any));