📄 soapcpp2_yacc.y
字号:
/*soapcpp2_yacc.yYacc/Bison grammar.Notes:Bison 1.6 can crash on Win32 systems if YYINITDEPTH is too small Compile with-DYYINITDEPTH=5000This grammar has one shift/reduce conflict related to the use of a classdeclaration with a base class (e.g. class Y : public X) and the use of amaxOccurs (class Y :10). Internally the conflict is resolved in favor of ashift by Bison/Yacc, which leads to the correct parsing behavior. Therefore,the warning can be ignored.gSOAP XML Web services toolsCopyright (C) 2000-2007, Robert van Engelen, Genivia Inc. All Rights Reserved.This part of the software is released under one of the following licenses:GPL, the gSOAP public license, or Genivia's license for commercial use.--------------------------------------------------------------------------------gSOAP public license.The contents of this file are subject to the gSOAP Public License Version 1.3(the "License"); you may not use this file except in compliance with theLicense. You may obtain a copy of the License athttp://www.cs.fsu.edu/~engelen/soaplicense.htmlSoftware distributed under the License is distributed on an "AS IS" basis,WITHOUT WARRANTY OF ANY KIND, either express or implied. See the Licensefor the specific language governing rights and limitations under the License.The Initial Developer of the Original Code is Robert A. van Engelen.Copyright (C) 2000-2007 Robert A. van Engelen, Genivia inc. All Rights Reserved.--------------------------------------------------------------------------------GPL license.This program is free software; you can redistribute it and/or modify it underthe terms of the GNU General Public License as published by the Free SoftwareFoundation; either version 2 of the License, or (at your option) any laterversion.This program is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along withthis program; if not, write to the Free Software Foundation, Inc., 59 TemplePlace, Suite 330, Boston, MA 02111-1307 USAAuthor contact information:engelen@genivia.com / engelen@acm.org--------------------------------------------------------------------------------A commercial use license is available from Genivia, Inc., contact@genivia.com--------------------------------------------------------------------------------*/%{#include "soapcpp2.h"#ifdef WIN32#ifndef __STDC__#define __STDC__#endif#define YYINCLUDED_STDLIB_H#ifdef WIN32_WITHOUT_SOLARIS_FLEXextern int soapcpp2lex();#elseextern int yylex();#endif#elseextern int yylex();#endifextern int is_XML(Tnode*);#define MAXNEST 16 /* max. nesting depth of scopes */struct Scope{ Table *table; Entry *entry; Node node; LONG64 val; int offset; Bool grow; /* true if offset grows with declarations */ Bool mask; /* true if enum is mask */} stack[MAXNEST], /* stack of tables and offsets */ *sp; /* current scope stack pointer */Table *classtable = (Table*)0, *enumtable = (Table*)0, *typetable = (Table*)0, *booltable = (Table*)0, *templatetable = (Table*)0;char *namespaceid = NULL;int transient = 0;int permission = 0;int custom_header = 1;int custom_fault = 1;Pragma *pragmas = NULL;Tnode *qname = NULL;Tnode *xml = NULL;/* function prototypes for support routine section */static Entry *undefined(Symbol*);static Tnode *mgtype(Tnode*, Tnode*);static Node op(const char*, Node, Node), iop(const char*, Node, Node), relop(const char*, Node, Node);static void mkscope(Table*, int), enterscope(Table*, int), exitscope();static int integer(Tnode*), real(Tnode*), numeric(Tnode*);static void add_XML(), add_qname(), add_header(Table*), add_fault(Table*), add_response(Entry*, Entry*), add_result(Tnode*);extern char *c_storage(Storage), *c_type(Tnode*), *c_ident(Tnode*);extern int is_primitive_or_string(Tnode*), is_stdstr(Tnode*), is_binary(Tnode*), is_external(Tnode*);/* temporaries used in semantic rules */int i;char *s, *s1, *s2;Symbol *sym;Entry *p, *q;Tnode *t;Node tmp, c;Pragma **pp;%}/* we expect one shift-reduce conflict */%expect 1/* remove this line if necessary to allow Yacc to proceed */%union{ Symbol *sym; LONG64 i; double r; char c; char *s; Tnode *typ; Storage sto; Node rec; Entry *e;}/* pragmas */%token <s> PRAGMA/* keywords */%token <sym> AUTO DOUBLE INT STRUCT%token <sym> BREAK ELSE LONG SWITCH%token <sym> CASE ENUM REGISTER TYPEDEF%token <sym> CHAR EXTERN RETURN UNION%token <sym> CONST FLOAT SHORT UNSIGNED%token <sym> CONTINUE FOR SIGNED VOID%token <sym> DEFAULT GOTO SIZEOF VOLATILE%token <sym> DO IF STATIC WHILE%token <sym> CLASS PRIVATE PROTECTED PUBLIC%token <sym> VIRTUAL INLINE OPERATOR LLONG%token <sym> BOOL CFALSE CTRUE WCHAR%token <sym> TIME USING NAMESPACE ULLONG%token <sym> MUSTUNDERSTAND SIZE FRIEND%token <sym> TEMPLATE EXPLICIT TYPENAME%token <sym> RESTRICT null/* */%token NONE/* identifiers (TYPE = typedef identifier) */%token <sym> ID LAB TYPE/* constants */%token <i> LNG%token <r> DBL%token <c> CHR%token <s> STR/* types and related */%type <typ> type%type <sto> store virtual constobj abstract%type <e> fname struct class base enum%type <sym> id arg name%type <s> patt%type <i> cint/* expressions and statements */%type <rec> expr cexp oexp obex aexp abex rexp lexp pexp init spec tspec ptrs array arrayck texp qexp occurs/* terminals */%left ','%right '=' PA NA TA DA MA AA XA OA LA RA /* += -= *= /= %= &= ^= |= <<= >>= */%right '?'%right ':'%left OR /* || */%left AN /* && */%left '|'%left '^'%left '&'%left EQ NE /* == != */%left '<' LE '>' GE /* <= >= */%left LS RS /* << >> */%left '+' '-'%left '*' '/' '%'%left AR /* -> */%token PP NN /* ++ -- */%%/******************************************************************************\ Program syntax\******************************************************************************/prog : s1 exts { if (lflag) { custom_header = 0; custom_fault = 0; } else { add_header(sp->table); add_fault(sp->table); } compile(sp->table); freetable(classtable); freetable(enumtable); freetable(typetable); freetable(booltable); freetable(templatetable); } ;s1 : /* empty */ { classtable = mktable((Table*)0); enumtable = mktable((Table*)0); typetable = mktable((Table*)0); booltable = mktable((Table*)0); templatetable = mktable((Table*)0); p = enter(booltable, lookup("false")); p->info.typ = mkint(); p->info.val.i = 0; p = enter(booltable, lookup("true")); p->info.typ = mkint(); p->info.val.i = 1; mkscope(mktable(mktable((Table*)0)), 0); } ;exts : NAMESPACE ID '{' exts1 '}' { namespaceid = $2->name; } | exts1 { namespaceid = NULL; } ;exts1 : /* empty */ { add_XML(); add_qname(); } | exts1 ext { } ;ext : dclrs ';' { } | pragma { } | error ';' { synerror("input before ; skipped"); while (sp > stack) { freetable(sp->table); exitscope(); } yyerrok; } | t1 { } | t2 { } ;pragma : PRAGMA { if ($1[1] >= 'a' && $1[1] <= 'z') { for (pp = &pragmas; *pp; pp = &(*pp)->next) ; *pp = (Pragma*)emalloc(sizeof(Pragma)); (*pp)->pragma = (char*)emalloc(strlen($1)+1); strcpy((*pp)->pragma, $1); (*pp)->next = NULL; } else if ((i = atoi($1+2)) > 0) yylineno = i; else { sprintf(errbuf, "directive '%s' ignored (use #import to import files and/or use option -i)", $1); semwarn(errbuf); } } ;/******************************************************************************\ Declarations\******************************************************************************/decls : /* empty */ { transient &= ~6; permission = 0; } | dclrs ';' decls { } | PRIVATE ':' t3 decls { } | PROTECTED ':' t4 decls { } | PUBLIC ':' t5 decls { } | t1 decls t2 decls { } ;t1 : '[' { transient |= 1; } ;t2 : ']' { transient &= ~1; } ;t3 : { permission = Sprivate; } ;t4 : { permission = Sprotected; } ;t5 : { permission = 0; } ;dclrs : spec { } | spec dclr { } | spec fdclr func { } | constr func { } | destr func { } | dclrs ',' dclr{ } | dclrs ',' fdclr func { } ;dclr : ptrs ID arrayck occurs init { if (($3.sto & Stypedef) && sp->table->level == GLOBAL) { if (($3.typ->type != Tstruct && $3.typ->type != Tunion && $3.typ->type != Tenum) || strcmp($2->name, $3.typ->id->name)) { p = enter(typetable, $2); p->info.typ = mksymtype($3.typ, $2); if ($3.sto & Sextern) p->info.typ->transient = -1; else p->info.typ->transient = $3.typ->transient; p->info.sto = $3.sto; p->info.typ->pattern = $4.pattern; if ($4.minOccurs != -1) { p->info.typ->minLength = $4.minOccurs; } if ($4.maxOccurs > 1) p->info.typ->maxLength = $4.maxOccurs; } $2->token = TYPE; } else { p = enter(sp->table, $2); p->info.typ = $3.typ; p->info.sto = ($3.sto | permission); if ($5.hasval) { p->info.hasval = True; switch ($3.typ->type) { case Tchar: case Tuchar: case Tshort: case Tushort: case Tint: case Tuint: case Tlong: case Tulong: case Tllong: case Tullong: case Tenum: case Ttime: if ($5.typ->type == Tint || $5.typ->type == Tchar || $5.typ->type == Tenum) sp->val = p->info.val.i = $5.val.i; else { semerror("type error in initialization constant"); p->info.hasval = False; } break; case Tfloat: case Tdouble: case Tldouble: if ($5.typ->type == Tfloat || $5.typ->type == Tdouble || $5.typ->type == Tldouble) p->info.val.r = $5.val.r; else if ($5.typ->type == Tint) p->info.val.r = (double)$5.val.i; else { semerror("type error in initialization constant"); p->info.hasval = False; } break; default: if ($3.typ->type == Tpointer && ((Tnode*)$3.typ->ref)->type == Tchar && $5.typ->type == Tpointer && ((Tnode*)$5.typ->ref)->type == Tchar) p->info.val.s = $5.val.s; else if ($3.typ->type == Tpointer && ((Tnode*)$3.typ->ref)->id == lookup("std::string")) p->info.val.s = $5.val.s; else if ($3.typ->id == lookup("std::string")) p->info.val.s = $5.val.s; else if ($3.typ->type == Tpointer && $5.typ->type == Tint && $5.val.i == 0) p->info.val.i = 0; else { semerror("type error in initialization constant"); p->info.hasval = False; } break; } } else p->info.val.i = sp->val; if ($4.minOccurs < 0) { if (($3.sto & Sattribute) || $3.typ->type == Tpointer || $3.typ->type == Ttemplate || !strncmp($2->name, "__size", 6)) p->info.minOccurs = 0; else p->info.minOccurs = 1; } else p->info.minOccurs = $4.minOccurs; p->info.maxOccurs = $4.maxOccurs; if (sp->mask) sp->val <<= 1; else sp->val++; p->info.offset = sp->offset; if ($3.sto & Sextern) p->level = GLOBAL; else if ($3.sto & Stypedef) ; else if (sp->grow) sp->offset += p->info.typ->width; else if (p->info.typ->width > sp->offset) sp->offset = p->info.typ->width; } sp->entry = p; } ;fdclr : ptrs name { if ($1.sto & Stypedef) { sprintf(errbuf, "invalid typedef qualifier for '%s'", $2->name); semwarn(errbuf); } p = enter(sp->table, $2); p->info.typ = $1.typ; p->info.sto = $1.sto; p->info.hasval = False; p->info.offset = sp->offset; if (sp->grow) sp->offset += p->info.typ->width; else if (p->info.typ->width > sp->offset) sp->offset = p->info.typ->width; sp->entry = p; } ;id : ID { $$ = $1; } | TYPE { $$ = $1; } ;name : ID { $$ = $1; } | OPERATOR '!' { $$ = lookup("operator!"); } | OPERATOR '~' { $$ = lookup("operator~"); } | OPERATOR '=' { $$ = lookup("operator="); } | OPERATOR PA { $$ = lookup("operator+="); } | OPERATOR NA { $$ = lookup("operator-="); } | OPERATOR TA { $$ = lookup("operator*="); } | OPERATOR DA { $$ = lookup("operator/="); } | OPERATOR MA { $$ = lookup("operator%="); } | OPERATOR AA { $$ = lookup("operator&="); } | OPERATOR XA { $$ = lookup("operator^="); } | OPERATOR OA { $$ = lookup("operator|="); } | OPERATOR LA { $$ = lookup("operator<<="); } | OPERATOR RA { $$ = lookup("operator>>="); } | OPERATOR OR { $$ = lookup("operator||"); } | OPERATOR AN { $$ = lookup("operator&&"); } | OPERATOR '|' { $$ = lookup("operator|"); } | OPERATOR '^' { $$ = lookup("operator^"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -