commit 66acffa599b36cfd552ad5ccd2d8559e3ea1db2b
parent 34e1f1810997d18f60d80cfec089417b9343c978
Author: Tomas Hlavaty <tom@logand.com>
Date: Tue, 6 Dec 2011 03:48:51 +0100
parser fixes
Diffstat:
4 files changed, 96 insertions(+), 67 deletions(-)
diff --git a/parse.y b/parse.y
@@ -25,7 +25,8 @@ Any ast;
%}
-%token TRUE FALSE ID BOOL INT FLOAT EQ LT LE GT GE PLUS MINUS MUL DIV MOD
+%token TRUE FALSE ID BOOL INT OCT HEX REAL
+%token 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
@@ -33,11 +34,11 @@ Any ast;
%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 BYTE CHAR DOUBLE HYPER LONG SHORT FLOAT STRING TYPE UNSIGNED VOID IN
+%token OUT INOUT ONEWAY GET SET PUBLISHED ELLIPSIS
%token REMOVABLE
-%token METHOD CONSTRUCTOR
+%token METHOD CONSTRUCTOR RELATIVE ABSOLUTE TEMPLATE
%%
@@ -50,100 +51,110 @@ declaration: defenum | defstruct | deftemplate | defexception
| service_singleton;
published: nil | PUBLISHED {$$ = T;};
defenum: published ENUM identifier LCURLY enum_members RCURLY SEMICOLON
- {$$ = cons4($2, $3, $1, $4)};
+ {$$ = cons4($2, $3, $1, $5)};
enum_members: enum_member {$$ = list1($1);}
- | enum_member COMMA enum_members {$$ = cons($1, $2);};
-enum_member: identifier | identifier EQ exp {$$ = list3($2, $1, $3);};
+ | enum_member COMMA enum_members {$$ = cons($1, $3);};
+enum_member: identifier | identifier EQ exp {$$ = list2($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;
+ LCURLY struct_members RCURLY SEMICOLON {cons5($2, $3, $1, $4, $6);};
+single_inheritance: nil | COLON name {$$ = $2};
+struct_members: struct_member | struct_member struct_members {$$ = cons($1, $2);};
+struct_member: type identifier SEMICOLON {$$ = list2($2, $1);};
deftemplate: published STRUCT identifier struct_params
- LCURLY template_members RCURLY SEMICOLON;
-struct_params: LT identifiers GT;
+ LCURLY template_members RCURLY SEMICOLON {$$ = cons5($2, $3, $1, $4, $6);};
+struct_params: LT identifiers GT {$$ = $2;};
identifiers: identifier {$$ = list1($1);}
| identifier COMMA identifiers {$$ = cons($1, $3)};
-template_members: template_member | template_member template_members;
+template_members: template_member
+ | template_member template_members {$$ = cons($1, $2);};
template_member: struct_member | parametric_member;
-parametric_member: identifier identifier SEMICOLON;
+parametric_member: identifier identifier SEMICOLON {$$ = list2($1, $2);};
defexception: published EXCEPTION identifier single_inheritance
- LCURLY struct_members_opt RCURLY SEMICOLON;
+ LCURLY struct_members_opt RCURLY SEMICOLON {$$ = cons5($2, $3, $1, $4, $6);};
struct_members_opt: nil | struct_members;
-interface_forward: published INTERFACE identifier SEMICOLON {$$ = list3($2, $3, $1);};
+interface_forward: published INTERFACE name SEMICOLON {$$ = list3($2, $3, $1);};
definterface: published INTERFACE identifier single_inheritance
- LCURLY interface_members RCURLY SEMICOLON {$$ = cons5($2, $3, $1, $4, $5);};
+ LCURLY interface_members RCURLY SEMICOLON {$$ = cons5($2, $3, $1, $4, $6);};
interface_members: nil | interface_member interface_members {$$ = cons($1, $2);};
-interface_member: interface_inheritance | attribute | defmethod;
+interface_member: interface_inheritance | attribute | interface_forward | defmethod;
interface_inheritance: optional INTERFACE name SEMICOLON {$$ = list3($2, $3, $1);};
optional: nil | LSQUARE OPTIONAL RSQUARE {$$ = $2;};
-attribute: attribute_flags type identifier attribute_accesses_opt SEMICOLON;
+attribute: attribute_flags type identifier attribute_accesses_opt SEMICOLON
+ {$$ = cons5(mk(ATTRIBUTE, "attribute"), $2, $3, $1, $4);};
+attribute_flags: LSQUARE attribute_flags1 RSQUARE {$$ = $2;};
+attribute_flags1: attribute_flags2a ATTRIBUTE attribute_flags2b {$$ = nconc2($1, $3);};
+attribute_flags2a: nil | attribute_flag COMMA attribute_flags2a {$$ = cons($1, $3);};
+attribute_flags2b: nil | COMMA attribute_flag attribute_flags2b {$$ = cons($2, $3);};
+attribute_flag: BOUND | READONLY;
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_opt RPAR
- exception_spec SEMICOLON
- {$$ = list6(mk(METHOD, "method"), $3, $2, $1, $5, $7);};
-/* oneway: nil | LSQUARE ONEWAY RSQUARE {$$ = T;}; */
-/* type_opt: nil | type; */
-method_params_opt: nil | method_params {$$ = $1;};
+attribute_get: GET exception_spec SEMICOLON {$$ = list2($1, $2);};
+attribute_set: SET exception_spec SEMICOLON {$$ = list2($1, $2);};
+exception_spec: RAISES LPAR names RPAR {$$ = $3;};
+names: name {$$ = list1($1);} | name COMMA names {$$ = cons($1, $3);};
+defmethod: oneway type_opt identifier LPAR method_params_opt RPAR
+ exception_spec_opt SEMICOLON
+ {$$ = cons6(mk(METHOD, "method"), $3, $1, $2, $5, $7);};
+oneway: nil | LSQUARE ONEWAY RSQUARE {$$ = T;};
+type_opt: nil | type;
+method_params_opt: nil | method_params;
method_params: method_param {$$ = list1($1);}
| method_param COMMA method_params {$$ = cons($1, $3);};
-method_param: LSQUARE direction RSQUARE type identifier {$$ = list3($3, $5, $4);};
+method_param: LSQUARE direction RSQUARE type identifier {$$ = list3($2, $5, $4);};
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;
+deftype: published TYPEDEF type identifier SEMICOLON {$$ = list4($2, $3, $1, $4);};
+constant: published const_decl {$$ = list2($1, $2);};
+const_decl: CONST type identifier EQ exp SEMICOLON {$$ = list4($1, $2, $3, $5);};
+constants: published CONSTANTS identifier LCURLY const_decls RCURLY SEMICOLON
+ {$$ = cons4($2, $3, $1, $5);};
+const_decls: nil | const_decl const_decls {$$ = cons($1, $2);};
defmodule: MODULE identifier LCURLY declarations RCURLY SEMICOLON
{$$ = cons3($1, $2, $4)};
declarations: nil | declaration declarations {$$ = cons($1, $2);};
interface_service: published SERVICE identifier colon_name_opt
constructors_block SEMICOLON {$$ = cons5($2, $3, $1, $4, $5);};
colon_name_opt: nil | COLON name {$$ = $2;};
-constructors: nil | constructor constructors;
+constructors_block: nil | LCURLY constructors RCURLY {$$ = $2;};
+constructors: nil | constructor constructors {$$ = cons($1, $2);};
constructor: identifier LPAR constructor_params_opt RPAR
exception_spec_opt SEMICOLON
- {$$ = list4(mk(CONSTRUCTOR, "constructor"), $1, $3, $5);};
-constructors_block: nil | LCURLY constructors RCURLY {$$ = $2;};
+ {$$ = cons4(mk(CONSTRUCTOR, "constructor"), $1, $3, $5);};
constructor_params_opt: nil | constructor_params;
constructor_params: rest_param | ctor_params;
-ctor_params: ctor_param | ctor_param COMMA ctor_params {$$ = cons($1, $2);};
-rest_param: LSQUARE IN RSQUARE ANY ELLIPSIS identifier;
-ctor_param: LSQUARE IN RSQUARE type identifier;
+ctor_params: ctor_param {$$ = list1($1);}
+ | ctor_param COMMA ctor_params {$$ = cons($1, $3);};
+rest_param: LSQUARE IN RSQUARE ANY ELLIPSIS identifier {$$ = list4($2, $6, $4, $5);};
+ctor_param: LSQUARE IN RSQUARE type identifier {$$ = list3($2, $5, $4);};
accumulated_service: published SERVICE identifier colon_name_opt
- LCURLY service_members RCURLY SEMICOLON;
-service_members: service_member | service_member service_members;
+ LCURLY service_member service_members RCURLY SEMICOLON
+ {$$ = list5($2, $3, $1, $4, cons($6, $7));};
+service_members: nil | service_member service_members {$$ = cons($1, $2);};
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;
+service_inheritance: optional SERVICE name SEMICOLON {$$ = list3($2, $3, $1);};
+property: property_flags type identifier SEMICOLON
+ {$$ = list4(mk(PROPERTY, "property"), $3, $2, $1);};
+property_flags: LSQUARE property_flags1 RSQUARE {$$ = $2;};
+property_flags1: property_flags2a PROPERTY property_flags2b {$$ = nconc2($1, $3);};
+property_flags2a: nil | property_flag COMMA property_flags2a {$$ = cons($1, $3);};
+property_flags2b: nil | COMMA property_flag property_flags2b {$$ = cons($2, $3);};
property_flag: BOUND | CONSTRAINED | MAYBEAMBIGUOUS | MAYBEDEFAULT
| MAYBEVOID | OPTIONAL | READONLY | REMOVABLE | TRANSIENT;
-interface_singleton: published SINGLETON identifier COLON name SEMICOLON;
+interface_singleton: published SINGLETON identifier COLON name SEMICOLON
+ {$$ = list4($2, $3, $1, $5);};
service_singleton: published SINGLETON identifier
- LCURLY SERVICE name SEMICOLON RCURLY SEMICOLON;
+ LCURLY SERVICE name SEMICOLON RCURLY SEMICOLON
+ {$$ = list5($2, $3, $1, $6, T);};
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 {$$ = list2($1, $2);};
-template_type: name LT types GT;
-types: nil | type COMMA types;
+sequence_type: SEQUENCE LT type GT {$$ = list2($1, $3);};
+template_type: name LT type types GT
+ {$$ = list3(mk(TEMPLATE, "template"), $1, cons($3, $4));};
+types: nil | COMMA type types {$$ = cons($2, $3);};
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);};
@@ -155,10 +166,14 @@ mul_exp: unary_exp | mul_exp mul_op unary_exp {$$ = list3($2, $1, $3);};
mul_op: MUL | DIV | MOD;
unary_exp: primary_exp | unary_op primary_exp {$$ = list2($1, $2);};
unary_op: PLUS | MINUS | NOT;
-primary_exp: name | literal | '(' exp ')' {$$ = $2;};
-literal: BOOL | INT | FLOAT;
-name: relname | SCOPE relname {$$ = list2($1, $2);};
-relname: identifier | identifier SCOPE relname {$$ = list2($1, $3);};
+primary_exp: name | literal | LPAR exp RPAR {$$ = $2;};
+literal: BOOL | INT | OCT | HEX | REAL;
+name: relname {$$ = cons(mk(RELATIVE, "relative"), $1);}
+ | SCOPE relname {$$ = cons(mk(ABSOLUTE, "absolute"), $2);};
+relname: identifier {$$ = list1($1);} | identifier SCOPE relname {$$ = cons($1, $3);};
identifier: ID
+ | GET {$$ = mk(ID, "get");}
+ | SET {$$ = mk(ID, "set");}
+ | PUBLISHED {$$ = mk(ID, "published");};
%%
diff --git a/scan.ll b/scan.ll
@@ -11,7 +11,7 @@ char *strdup(char *);
int yycolumn = 1;
Kind tok(Kind kind, char *token) {
- printf("{%s}\n", token);
+ //printf("{%s}\n", token);
yylval = mk(kind, token);
return kind;
}
@@ -28,6 +28,7 @@ ALPHA [a-zA-Z]
INT [1-9][0-9]*
OCT 0{OCT_DIGIT}*
HEX (0x|0X){HEX_DIGIT}*
+REAL [+-]?{DIGIT}+[.]{DIGIT}+
IDENTIFIER_NEW ({ALPHA}({ALPHA}|{DIGIT})*)|({CAPITAL}("_"?({ALPHA}|{DIGIT})+)*)
IDENTIFIER ("_"?({ALPHA}|{DIGIT})+)*
@@ -128,7 +129,10 @@ published return tok(PUBLISHED, "published");
"..." return tok(ELLIPSIS, "ellipsis");
-{DIGIT}+ return tok(INT, strdup(yytext));
+{INT} return tok(INT, strdup(yytext));
+{OCT} return tok(OCT, strdup(yytext));
+{HEX} return tok(HEX, strdup(yytext));
+{REAL} return tok(REAL, strdup(yytext));
{IDENTIFIER} return tok(ID, strdup(yytext));
diff --git a/unoidl2.c b/unoidl2.c
@@ -110,6 +110,16 @@ Any list6(Any a, Any b, Any c, Any d, Any e, Any f)
return cons7(a, b, c, d, e, f, NIL);
}
+Any nconc2(Any a, Any b)
+{
+ if(null(a))
+ return b;
+ Any x, d;
+ for(x = a, d = cdr(x); !null(d); x = d, d = cdr(x));
+ x->u.c.cdr = b;
+ return a;
+}
+
void print(Any x) {
if(null(x))
printf("NIL");
@@ -117,8 +127,7 @@ void print(Any x) {
if(consp(x)) {
printf("(");
print(car(x));
- Any d;
- for(d = cdr(x); !null(d); d = cdr(d)) {
+ for(Any d = cdr(x); !null(d); d = cdr(d)) {
printf(" ");
if(consp(d))
print(car(d));
diff --git a/unoidl2.h b/unoidl2.h
@@ -21,4 +21,5 @@ Any list3(Any a, Any b, Any c);
Any list4(Any a, Any b, Any c, Any d);
Any list5(Any a, Any b, Any c, Any d, Any e);
Any list6(Any a, Any b, Any c, Any d, Any e, Any f);
+Any nconc2(Any a, Any b);
void print(Any x);