summaryrefslogtreecommitdiff
path: root/comm/OLD/ReqMgr.y
diff options
context:
space:
mode:
authorchatty1993-04-07 11:50:31 +0000
committerchatty1993-04-07 11:50:31 +0000
commitba066c34dde204aa192d03a23a81356374d93731 (patch)
tree39391f6235d2cf8a59a0634ac5ea430cdd21f5d4 /comm/OLD/ReqMgr.y
parent05ab076e1c2a9ca16472f9a6b47b8d22914b3783 (diff)
downloadivy-league-ba066c34dde204aa192d03a23a81356374d93731.zip
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.gz
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.bz2
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.xz
Initial revision
Diffstat (limited to 'comm/OLD/ReqMgr.y')
-rw-r--r--comm/OLD/ReqMgr.y285
1 files changed, 285 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include "ReqMgr.h"
+
+static UchReqMgr* CurMgr;
+static RequestType* CurRequest;
+static CcuListOf <RequestField>* CurFieldList;
+static CcuDictionnaryOf <RequestField> 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 <integer> Y_CLIENT Y_REQUEST Y_YIELDS Y_GETTERS Y_SETTERS Y_CONST
+%token <string> Y_ID
+%type <string> 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 <stdio.h>
+
+static void
+AddFieldToReq (const char* c, const char* t, const char* s, const char* id, const char* impl)
+{
+ int found;
+ CcuHashCellOf <RequestField>* 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);
+}