From ba066c34dde204aa192d03a23a81356374d93731 Mon Sep 17 00:00:00 2001 From: chatty Date: Wed, 7 Apr 1993 11:50:31 +0000 Subject: Initial revision --- comm/OLD/ReqMgr.y | 285 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 comm/OLD/ReqMgr.y (limited to 'comm/OLD/ReqMgr.y') diff --git a/comm/OLD/ReqMgr.y b/comm/OLD/ReqMgr.y new file mode 100644 index 0000000..4c29f00 --- /dev/null +++ b/comm/OLD/ReqMgr.y @@ -0,0 +1,285 @@ +%{ + +/* + * The Unix Channel + * + * by Michel Beaudouin-Lafon + * + * Copyright 1993 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Request management, by Stephane Chatty + * + * $Id$ + * $CurLog$ + */ + +#include "ccu/HashTable.h" +extern "C" { + int yyerror (const char*); + int yyparse(); + int yywrap (); + int yylex(); +} + +/* This comes from the lexical analyzer */ +extern CcuDictionnary* ResWords; + +static void error (const char*, ...); + +#include +#include +#include +#include + +#include "ReqMgr.h" + +static UchReqMgr* CurMgr; +static RequestType* CurRequest; +static CcuListOf * CurFieldList; +static CcuDictionnaryOf Fields (16); + +static void AddFieldToReq (const char*, const char*, const char*, const char*, const char*); +static void AddFieldToList (const char*); + +%} + +%union { + int integer; + const char *string; +} + +%token Y_CLIENT Y_REQUEST Y_YIELDS Y_GETTERS Y_SETTERS Y_CONST +%token Y_ID +%type opt_star + +%% + +file: + /* empty */ + | file decl + ; + +decl: + client + | request + ; + +client: + Y_CLIENT Y_ID ';' + { + CurMgr->SetName ($2); + } + ; + +request: + Y_REQUEST Y_ID + { + CurRequest = new RequestType ($2); + CurMgr->Add (CurRequest); + Fields.Clear (); + } + '{' request_entries '}' ';' + ; + +request_entries: + /* empty */ + | request_entries request_entry + ; + +request_entry: + field + | getters + | setters + | constructor + ; + +field: + Y_CONST Y_ID opt_star Y_ID Y_YIELDS Y_ID ';' + { + AddFieldToReq ("const", $2, $3, $4, $6); + } + | Y_ID opt_star Y_ID Y_YIELDS Y_ID ';' + { + AddFieldToReq (0, $1, $2, $3, $5); + } + ; + +opt_star: + /* empty */ { $$ = 0; } + | '*' { $$ = "*"; } + ; + +getters: + Y_GETTERS + { + CurFieldList = &CurRequest->Getters; + } + '(' id_list ')' ';' + ; + +setters: + Y_SETTERS + { + CurFieldList = &CurRequest->Setters; + } + '(' id_list ')' ';' + ; + +constructor: + Y_ID + { + if (strcmp ($1, CurRequest->GetName ()) != 0) + fprintf (stderr, "unknown name %s in request type %s. Considering as constructor.\n", + $1, CurRequest->GetName ()); + RequestConstructor* c = new RequestConstructor; + CurRequest->AddConstructor (c); + CurFieldList = &c->Params; + } + '(' id_list ')' ';' + ; + +id_list: + /* empty */ + | Y_ID { AddFieldToList ($1); } + | id_list ',' Y_ID { AddFieldToList ($3); } + ; + +%% +#include + +static void +AddFieldToReq (const char* c, const char* t, const char* s, const char* id, const char* impl) +{ + int found; + CcuHashCellOf * hc = Fields.Add (id, &found); + if (found) { + fprintf (stderr, "warning: duplicate field %s in request %s. Ignoring. \n", + id, CurRequest->GetName ()); + } else { + char buf [128]; + if (c || s) { + sprintf (buf, "%s %s %s", (c ? c : ""), t, (s ? s : "")); + t = buf; + } + RequestField* f = new RequestField (id, t, impl); + hc->SetInfo (f); + CurRequest->AddField (f); + } +} + +static void +AddFieldToList (const char* name) +{ + RequestField* f = Fields [name]; + if (!f) { + fprintf (stderr, "warning: unknown field %s in request %s\n", + name, CurRequest->GetName ()); + } else { + CurFieldList->Append (f); + } +} + +int _DoTee = 0; + +int +tee (int x) +{ + if (_DoTee) { + char *s; + switch (x) { + case '(': + s = "("; + break; + case ')': + s = ")"; + break; + case '*': + s = "*"; + break; + case ';': + s = ";"; + break; + case ',': + s = ","; + break; + case '{': + s = "}"; + break; + case '\n': + s = "\n"; + break; + case Y_ID: + s = "ID"; + break; + case Y_CLIENT: + s = "CLIENT"; + break; + case Y_REQUEST: + s = "REQUEST"; + break; + case Y_YIELDS: + s = "->"; + break; + case Y_GETTERS: + s = "GETTERS"; + break; + case Y_SETTERS: + s = "SETTERS"; + break; +/* case Y_: + s = ""; + break; +*/ + default : + s = "???"; + break; + } + printf ("%s ", s); + } + return x; +} + +int +yyerror (const char *s) +{ + error ("%s\n",s); + return (0); +} + +int +yywrap () +{ + return 1; +} + +void +UchReqMgr :: Read (const char* file) +{ + extern void LexInit (); + extern FILE *yyin; + LexInit (); + if (!(yyin = fopen (file,"r"))) { + char err [1024]; + sprintf (err, "Cannot open %s", file); + yyerror (err); + return; + } + CurMgr = this; + if (yyparse ()) + fprintf (stderr, "\nParsing failed on %s\n", file); + fclose (yyin); +} + +extern int LineNo; + +static void +error (const char* s, ...) +{ + va_list ap; + va_start(ap, s); + + fprintf (stderr, "Error at line %d: ", LineNo); + vfprintf (stderr, s, ap); + exit (0); +} -- cgit v1.1