/******************************************************************** ODL grammer analyzer (conformant to ODMG 2.0 ODL) The material is provided as-is, with no warrenty of any kind. Author: Daniel Grundmann, Fraunhofer ISST (corrected version) Contact:Deutsche Telekom, Technologiezentrum, D-64307 Darmstadt Fraunhofer ISST, Postfach 520 130, D-44207 Dortmund http://www.isst.fhg.de, mailto:Weissenberg@do.isst.fhg.de Date: 98/03/16 Decription: This file is based on the yacc file provided by the ODMG for ODMG-93 ODL and analyzes the grammer of an ODL source. The use of outdated ODMG-93 contructs generate warnings and some errors in ODMG-2.0 have been corrected, e.g. IDL-conformant attribute name lists are supported. Modified by Leonidas Fegaras, 9/28/98 *********************************************************************/ %{ #include #include #include int parser_line = 1; int parser_column = 0; int parser_state = 0; int yylex(); int yyerror ( char* text ); void warning_ODMG93 ( char* text ) { cout << "Warning: '" << text << "' is only supported in ODMG-93." << endl; cout << "Line: " << parser_line << ", Column: " << parser_column << endl; }; char* fix_string ( char* x ) { int n = strlen(x); char* s = new char[n-2]; int j = 0; for(int i = 0; iwrite(eout); eout.flush(); String s = new string(eout.str()); return s; }; void process_client_definitions ( list* r ) { for(; r->consp(); r=r->tl) process_definition(Expr_to_String(r->hd)->content()); }; Expr none = variable("none"); Expr L ( char* s, list* r ) { return function(variable(s),r); }; Expr L ( char* s, Expr x1, list* r ) { return function(variable(s),Cons(x1,r)); }; Expr L ( char* s, Expr x1, Expr x2, list* r ) { return function(variable(s),Cons(x1,Cons(x2,r))); }; Expr L ( char* s, Expr x1, Expr x2, Expr x3, list* r ) { return function(variable(s),Cons(x1,Cons(x2,Cons(x3,r)))); }; Expr L ( char* s, Expr x1, Expr x2, Expr x3, Expr x4, Expr x5, list* r ) { return function(variable(s),Cons(x1,Cons(x2,Cons(x3,Cons(x4,Cons(x5,r)))))); }; Expr F ( char* s, Expr x1 ) { return function(variable(s),Cons(x1,Nil)); }; Expr F ( char* s, Expr x1, Expr x2 ) { return function(variable(s),Cons(x1,Cons(x2,Nil))); }; Expr F ( char* s, Expr x1, Expr x2, Expr x3 ) { return function(variable(s),Cons(x1,Cons(x2,Cons(x3,Nil)))); }; Expr F ( char* s, Expr x1, Expr x2, Expr x3, Expr x4 ) { return function(variable(s),Cons(x1,Cons(x2,Cons(x3,Cons(x4,Nil))))); }; Expr F ( char* s, Expr x1, Expr x2, Expr x3, Expr x4, Expr x5 ) { return function(variable(s),Cons(x1,Cons(x2,Cons(x3,Cons(x4,Cons(x5,Nil)))))); }; Expr F ( char* s, Expr x1, Expr x2, Expr x3, Expr x4, Expr x5, Expr x6 ) { return function(variable(s),Cons(x1,Cons(x2,Cons(x3,Cons(x4,Cons(x5,Cons(x6,Nil))))))); }; %} %union { char* StringType; long Integer; double Float; char* Tstring; Expr Texp; list* Texps; } %token IntegerLiteral %token FloatingPtLiteral %token Identifier StringLiteral CharacterLiteral %token SEMI LPAR RPAR MODULE DOUBLE_COLON COLON PERSISTENT TRANSIENT INTERFACE LRPAR RRPAR EXTENT KEY KEYS COMMA _CONST EQUAL VERT HAT AMPER DOUBLE_RIGHT DOUBLE_LEFT PLUS MINUS TIMES SLASH PERCENT TILDE TRUE FALSE TYPEDEF FLOAT DOUBLE LONG SHORT UNSIGNED CHAR BOOLEAN ANY OCTET STRUCT UNION SWITCH CASE DEFAULT ENUM ARRAY LEFT RIGHT ODL_STRING LEPAR REPAR READONLY ATTRIBUTE SET LIST BAG INVERSE IMPORT RELATIONSHIP ORDER_BY EXCEPTION ONEWAY ODL_VOID IN OUT INOUT RAISES CONTEXT CLASS DATE TIME EXTENDS INTERVAL TIMESTAMP DICTIONARY SEQUENCE %type UnaryOperator RelCollectionType ParamAttribute %type Id Definition Class ClassHeader Module Interface InterfaceDcl ForwardDcl ExtentSpec OptKeySpec KeySpec Key PropertyName AttributeName Export ConstDcl ConstType ConstExp OrExpr XOrExpr AndExpr ShiftExpr AddExpr MultExpr UnaryExpr PrimaryExpr Literal BooleanLiteral PositiveIntConst TypeDcl TypeSpec SimpleTypeSpec BaseTypeSpec TemplateTypeSpec CollType ConstrTypeSpec Declarator SimpleDeclarator ComplexDeclarator FloatingPtType IntegerType SignedInt SignedLongInt SignedShortInt UnsignedInt UnsignedLongInt UnsignedShortInt StructType Member UnionType SwitchTypeSpec Case CaseLabel EnumType Enumerator ArrayType StringType ArrayDeclarator FixedArraySize AttrDcl DomainType RelDcl TraversalPathName1 TargetOfPath OptInverseTraversalPath TraversalPathName2 ExceptDcl OpDcl OpTypeSpec ParameterDcls ParamDcl RaisesExpr ContextExpr SL OptExtentSpec String %type KeyList PropertyList AttributeNameList InterfaceBody InheritanceSpec ScopedName Declarators MemberList SwitchBody CaseLabelList EnumeratorList ArraySizeList AttributeList ParamDclList ScopedNameList StringLiteralList Specification OptInterfaceBody OptMemberList TypePropertyList OptTypePropertyList TypeDeclarator ElementSpec %% start: Specification { process_client_definitions($1); } ; Id: Identifier { $$ = variable(yylval.StringType); } ; Specification: Definition { $$ = Cons($1,Nil); } | Definition Specification { $$ = Cons($1,$2); } ; String: StringLiteral { $$ = estring(fix_string(yylval.StringType)); } ; Definition: TypeDcl SEMI { $$ = $1; } | ConstDcl SEMI { $$ = $1; } | ExceptDcl SEMI { $$ = $1; } | Interface SEMI { $$ = $1; } | Module SEMI { $$ = $1; } | Class SEMI { $$ = $1; } | IMPORT Id COLON Id SEMI { $$ = F("import",$2,$4); } ; Class: ClassHeader LPAR InterfaceBody RPAR { $$ = L("class",$1->arguments()->append($3)); } ; ClassHeader: CLASS Id OptTypePropertyList { $$ = L("header",$2,L("scope",Nil),L("inherits",Nil),$3); } | CLASS Id EXTENDS ScopedName OptTypePropertyList { $$ = L("header",$2,L("scope",$4),L("inherits",Nil),$5); } | CLASS Id COLON InheritanceSpec OptTypePropertyList { $$ = L("header",$2,L("scope",Nil),L("inherits",$4),$5); } | CLASS Id COLON EXTENDS ScopedName COLON InheritanceSpec OptTypePropertyList { $$ = L("header",$2,L("scope",$5),L("inherits",$7),$8); } ; Module: MODULE Id LPAR Specification RPAR { $$ = L("module",$2,$4); } ; Interface: InterfaceDcl { $$ = $1; } | ForwardDcl { $$ = $1; } ; InterfaceDcl: INTERFACE Id COLON InheritanceSpec LPAR OptInterfaceBody RPAR { $$ = L("interface",$2,L("inherits",$4),$6); } | INTERFACE Id LPAR OptInterfaceBody RPAR { $$ = L("interface",$2,L("inherits",Nil),$4); } ; ForwardDcl: INTERFACE Id { $$ = F("forward",$2); } ; OptInterfaceBody: /* No interface body */ { $$ = Nil; } | InterfaceBody { $$ = $1; } ; OptTypePropertyList: /* No type property list */ { $$ = Cons(F("extent",variable(new string("EXT"+*new_name()))),Cons(L("keys",Nil),Nil)); } | TypePropertyList { $$ = $1; } ; TypePropertyList: LRPAR OptExtentSpec OptKeySpec RRPAR { $$ = Cons($2,Cons($3,Nil)); } ; OptExtentSpec: /* No extent specifier */ { $$ = F("extent",new_variable()); } | ExtentSpec { $$ = $1; } ; ExtentSpec: EXTENT Id { $$ = F("extent",$2); } ; OptKeySpec: /* No key specifier */ { $$ = L("keys",Nil); } | KeySpec { $$ = $1; } ; KeySpec: KEY KeyList { $$ = L("keys",$2); } | KEYS KeyList { $$ = L("keys",$2); } ; KeyList: Key { $$ = Cons($1,Nil); } | Key COMMA KeyList { $$ = Cons($1,$3); } ; Key: PropertyName { $$ = $1; } | LRPAR PropertyList RRPAR { $$ = L("combine",$2); } ; PropertyList: PropertyName { $$ = Cons($1,Nil); } | PropertyName COMMA PropertyList { $$ = Cons($1,$3); } ; PropertyName: Id { $$ = $1; } ; AttributeNameList: AttributeName { $$ = Cons($1,Nil); } | AttributeName COMMA AttributeNameList { $$ = Cons($1,$3); } ; AttributeName: Id { $$ = $1; } ; InterfaceBody: Export { $$ = Cons($1,Nil); } | Export InterfaceBody { $$ = Cons($1,$2); } ; Export: TypeDcl SEMI { $$ = $1; } | ConstDcl SEMI { $$ = $1; } | ExceptDcl SEMI { $$ = $1; } | AttrDcl SEMI { $$ = $1; } | RelDcl SEMI { $$ = $1; } | OpDcl SEMI { $$ = $1; } ; InheritanceSpec: ScopedName { $$ = Cons(L("scope",$1),Nil); } | ScopedName COMMA InheritanceSpec { $$ = Cons(L("scope",$1),$3); } ; ScopedName: Id { $$ = Cons($1,Nil); } | DOUBLE_COLON Id { $$ = Cons($2,Cons(variable("global"),Nil)); } | ScopedName DOUBLE_COLON Id { $$ = Cons($3,$1); } ; ConstDcl: _CONST ConstType Id EQUAL ConstExp { $$ = F("constant",$2,$3,$5); } ; ConstType: IntegerType { $$ = variable("long"); } | CharType { $$ = variable("char"); } | BooleanType { $$ = variable("boolean"); } | FloatingPtType { $$ = variable("float"); } | StringType { $$ = variable("string"); } | ScopedName { $$ = L("scope",$1); } ; ConstExp: OrExpr { $$ = $1; } ; OrExpr: XOrExpr { $$ = $1; } | OrExpr VERT XOrExpr { $$ = F("or",$1,$3); } ; XOrExpr: AndExpr { $$ = $1; } | XOrExpr HAT AndExpr { $$ = F("xor",$1,$3); } ; AndExpr: ShiftExpr { $$ = $1; } | AndExpr AMPER ShiftExpr { $$ = F("and",$1,$3); } ; ShiftExpr: AddExpr { $$ = $1; } | ShiftExpr DOUBLE_RIGHT AddExpr { $$ = F("shift_right",$1,$3); } | ShiftExpr DOUBLE_LEFT AddExpr { $$ = F("shift_left",$1,$3); } ; AddExpr: MultExpr { $$ = $1; } | AddExpr PLUS MultExpr { $$ = F("plus",$1,$3); } | AddExpr MINUS MultExpr { $$ = F("minus",$1,$3); } ; MultExpr: UnaryExpr { $$ = $1; } | MultExpr TIMES UnaryExpr { $$ = F("times",$1,$3); } | MultExpr SLASH UnaryExpr { $$ = F("div",$1,$3); } | MultExpr PERCENT UnaryExpr { $$ = F("mod",$1,$3); } ; UnaryExpr: UnaryOperator PrimaryExpr { $$ = F($1,$2); } | PrimaryExpr { $$ = $1; } ; UnaryOperator: MINUS { $$ = "minus"; } | PLUS { $$ = "plus"; } | TILDE { $$ = "not"; } ; PrimaryExpr: ScopedName { $$ = L("scope",$1); } | Literal { $$ = $1; } | LRPAR ConstExp RRPAR { $$ = $2; } ; Literal: IntegerLiteral { $$ = integer(yylval.Integer); } | StringLiteral { $$ = estring(fix_string(yylval.StringType)); } | CharacterLiteral { $$ = estring(yylval.StringType); } | FloatingPtLiteral { $$ = real(yylval.Float); } | BooleanLiteral { $$ = $1; } ; BooleanLiteral: TRUE { $$ = variable("true"); } | FALSE { $$ = variable("false"); } ; PositiveIntConst: ConstExp { $$ = $1; } ; TypeDcl: TYPEDEF TypeDeclarator { $$ = L("typedef",$2); } | StructType { $$ = $1; } | UnionType { $$ = $1; } | EnumType { $$ = $1; } ; TypeDeclarator: TypeSpec Declarators { $$ = Cons($1,$2); } ; TypeSpec: SimpleTypeSpec { $$ = $1; } | ConstrTypeSpec { $$ = $1; } ; SimpleTypeSpec: BaseTypeSpec { $$ = $1; } | TemplateTypeSpec { $$ = $1; } | ScopedName { $$ = L("scope",$1); } ; BaseTypeSpec: FloatingPtType { $$ = $1; } | IntegerType { $$ = $1; } | CharType { $$ = variable("char"); } | BooleanType { $$ = variable("boolean"); } | OctetType { $$ = variable("octet"); } | AnyType { $$ = variable("any"); } | DATE { $$ = variable("date"); } | TIME { $$ = variable("time"); } | INTERVAL { $$ = variable("interval"); } | TIMESTAMP { $$ = variable("timestamp"); } ; TemplateTypeSpec: ArrayType { $$ = $1; } | StringType { $$ = $1; } | CollType { $$ = $1; } ; CollType: SET LEFT SimpleTypeSpec RIGHT { $$ = F("set",$3); } | LIST LEFT SimpleTypeSpec RIGHT { $$ = F("list",$3); } | BAG LEFT SimpleTypeSpec RIGHT { $$ = F("bag",$3); } | DICTIONARY LEFT SimpleTypeSpec COMMA SimpleTypeSpec RIGHT { $$ = F("dictionary",$3,$5); } ; ConstrTypeSpec: StructType { $$ = $1; } | UnionType { $$ = $1; } | EnumType { $$ = $1; } ; Declarators: Declarator { $$ = Cons($1,Nil); } | Declarator COMMA Declarators { $$ = Cons($1,$3); } ; Declarator: SimpleDeclarator { $$ = $1; } | ComplexDeclarator { $$ = $1; } ; SimpleDeclarator: Id { $$ = $1; } ; ComplexDeclarator: ArrayDeclarator { $$ = $1; } ; FloatingPtType: FLOAT { $$ = variable("float"); } | DOUBLE { $$ = variable("float"); } ; IntegerType: SignedInt { $$ = $1; } | UnsignedInt { $$ = $1; } ; SignedInt: SignedLongInt { $$ = $1; } | SignedShortInt { $$ = $1; } ; SignedLongInt: LONG { $$ = variable("long"); } ; SignedShortInt: SHORT { $$ = variable("short"); } ; UnsignedInt: UnsignedLongInt { $$ = $1; } | UnsignedShortInt { $$ = $1; } ; UnsignedLongInt: UNSIGNED LONG { $$ = variable("unsigned_long"); } ; UnsignedShortInt: UNSIGNED SHORT { $$ = variable("unsigned_short"); } ; CharType: CHAR ; BooleanType: BOOLEAN ; OctetType: OCTET ; AnyType: ANY ; StructType: STRUCT Id LPAR MemberList RPAR { $$ = L("struct",$2,$4); } ; MemberList: Member { $$ = Cons($1,Nil); } | Member MemberList { $$ = Cons($1,$2); } ; Member: TypeSpec Declarators SEMI { $$ = L("attribute",$1,$2); } ; UnionType: UNION Id SWITCH LRPAR SwitchTypeSpec RRPAR LPAR SwitchBody RPAR { $$ = L("union",$2,$5,$8); } ; SwitchTypeSpec: IntegerType { $$ = $1; } | CharType { $$ = variable("char"); } | BooleanType { $$ = variable("boolean"); } | EnumType { $$ = $1; } | ScopedName { $$ = L("scope",$1); } ; SwitchBody: Case { $$ = Cons($1,Nil); } | Case SwitchBody { $$ = Cons($1,$2); } ; Case: CaseLabelList ElementSpec SEMI { $$ = L("case",$2->hd,$2->tl->hd,$1); } ; CaseLabelList: CaseLabel { $$ = Cons($1,Nil); } | CaseLabel CaseLabelList { $$ = Cons($1,$2); } ; CaseLabel: CASE ConstExp COLON { $$ = $2; } | DEFAULT COLON { $$ = variable("default"); } ; ElementSpec: TypeSpec Declarator { $$ = Cons($1,Cons($2,Nil)); } ; EnumType: ENUM Id LPAR EnumeratorList RPAR { $$ = L("enum",$2,$4); } ; EnumeratorList: Enumerator { $$ = Cons($1,Nil); } | Enumerator COMMA EnumeratorList { $$ = Cons($1,$3); } ; Enumerator: Id { $$ = $1; } ; ArrayType: ARRAY LEFT SimpleTypeSpec COMMA PositiveIntConst RIGHT { $$ = F("array",$3,$5); } | SEQUENCE LEFT SimpleTypeSpec COMMA PositiveIntConst RIGHT { $$ = F("sequence",$3,$5); } | ARRAY LEFT SimpleTypeSpec RIGHT { $$ = F("array",$3,none); } | SEQUENCE LEFT SimpleTypeSpec RIGHT { $$ = F("sequence",$3,none); } ; StringType: ODL_STRING LEFT PositiveIntConst RIGHT { $$ = F("string",$3); } | ODL_STRING { $$ = variable("string"); } ; ArrayDeclarator: Id ArraySizeList { $$ = L("array",$1,$2); } ; ArraySizeList: FixedArraySize { $$ = Cons($1,Nil); } | FixedArraySize ArraySizeList { $$ = Cons($1,$2); } ; FixedArraySize: LEPAR PositiveIntConst REPAR { $$ = $2; } ; /************************************************************************* IDL-conformant correction to ODMG 2.0: ATTRIBUTE Type Name1, Name2, ... *************************************************************************/ AttrDcl: READONLY ATTRIBUTE DomainType FixedArraySize AttributeNameList { $$ = L("attribute",$3,$4,$5); } | ATTRIBUTE DomainType FixedArraySize AttributeNameList { $$ = L("attribute",$2,$3,$4); } | READONLY ATTRIBUTE DomainType AttributeNameList { $$ = L("attribute",$3,none,$4); } | ATTRIBUTE DomainType AttributeNameList { $$ = L("attribute",$2,none,$3); } ; DomainType: SimpleTypeSpec { $$ = $1; } | StructType { $$ = $1; } | EnumType { $$ = $1; } | SET LEFT Literal RIGHT { $$ = F("set",$3); } | LIST LEFT Literal RIGHT { $$ = F("list",$3); } | BAG LEFT Literal RIGHT { $$ = F("bag",$3); } | ARRAY LEFT Literal RIGHT { warning_ODMG93("Array"); $$ = F("array",$3); } ; /**************************************************************** Modification for VHDBS in RelDcl: InverseTraversalPath made optional and INVERSE not in RelDcl but in Opt InverseTraversalPath *****************************************************************/ RelDcl: RELATIONSHIP TargetOfPath TraversalPathName1 OptInverseTraversalPath OptOrderBy { $$ = F("relationship",$2,$3,$4); } ; OptOrderBy: /* no order by */ | LPAR ORDER_BY AttributeList RPAR { warning_ODMG93("Order By"); } ; TraversalPathName1: Id { $$ = $1; } ; TargetOfPath: Id { $$ = $1; } | RelCollectionType LEFT Id RIGHT { $$ = F($1,$3); } ; OptInverseTraversalPath: /* nothing */ { $$ = none; } | INVERSE Id DOUBLE_COLON TraversalPathName2 { $$ = F("inverse",$2,$4); } ; TraversalPathName2: Id { $$ = $1; } ; AttributeList: ScopedName { $$ = Cons(L("scope",$1),Nil); } | ScopedName COMMA AttributeList { $$ = Cons(L("scope",$1),$3); } ; RelCollectionType: SET { $$ = "set"; } | LIST { $$ = "list"; } | BAG { $$ = "bag"; } | ARRAY { warning_ODMG93("Array"); $$ = "array"; } ; ExceptDcl: EXCEPTION Id LPAR OptMemberList RPAR { $$ = L("exception",$2,$4); } ; OptMemberList: /* No member list */ { $$ = Nil; } | MemberList { $$ = $1; } ; OpDcl: OpAttribute OpTypeSpec Id ParameterDcls RaisesExpr ContextExpr { $$ = F("method",$2,$3,$4,$5,$6); } | OpTypeSpec Id ParameterDcls RaisesExpr ContextExpr { $$ = F("method",$1,$2,$3,$4,$5); } | OpAttribute OpTypeSpec Id ParameterDcls ContextExpr { $$ = F("method",$2,$3,$4,none,$5); } | OpAttribute OpTypeSpec Id ParameterDcls RaisesExpr { $$ = F("method",$2,$3,$4,$5,none); } | OpTypeSpec Id ParameterDcls ContextExpr { $$ = F("method",$1,$2,$3,none,$4); } | OpAttribute OpTypeSpec Id ParameterDcls { $$ = F("method",$2,$3,$4,none,none); } | OpTypeSpec Id ParameterDcls RaisesExpr { $$ = F("method",$1,$2,$3,$4,none); } | OpTypeSpec Id ParameterDcls { $$ = F("method",$1,$2,$3,none,none); } ; OpAttribute: ONEWAY ; OpTypeSpec: SimpleTypeSpec { $$ = $1; } | ODL_VOID { $$ = variable("void"); } ; ParameterDcls: LRPAR ParamDclList RRPAR { $$ = L("params",$2); } | LRPAR RRPAR { $$ = L("params",Nil); } ; ParamDclList: ParamDcl { $$ = Cons($1,Nil); } | ParamDcl COMMA ParamDclList { $$ = Cons($1,$3); } ; ParamDcl: ParamAttribute SimpleTypeSpec Declarator { $$ = F($1,$2,$3); } ; ParamAttribute: IN { $$ = "in"; } | OUT { $$ = "out"; } | INOUT { $$ = "inout"; } ; RaisesExpr: RAISES LRPAR ScopedNameList RRPAR { $$ = L("raise",$3); } ; ScopedNameList: ScopedName { $$ = Cons(L("scope",$1),Nil); } | ScopedName COMMA ScopedNameList { $$ = Cons(L("scope",$1),$3); } ; ContextExpr: CONTEXT LRPAR StringLiteralList RRPAR { $$ = L("context",$3); } ; SL: StringLiteral { $$ = estring(fix_string(yylval.StringType)); } ; StringLiteralList: SL { $$ = Cons($1,Nil); } | SL COMMA StringLiteralList { $$ = Cons($1,$3); } ; %% #include "odl.yy.cc" int yyerror ( char* text ) { eout << "*** " << text << " near the token " << yytext << " (line: " << parser_line << ", column: " << parser_column << ")\n"; yyclearin; throw odmg_error_class(eout.str()); }; void parse_odl () { parser_line = 1; parser_column = 0; parser_state = 0; yyparse(); };