diff options
author | 1994-08-30 21:35:47 +0000 | |
---|---|---|
committer | 1994-08-30 21:35:47 +0000 | |
commit | 56de557fa4ba2be8958d734c0e0a47d91e96d129 (patch) | |
tree | 67554155495ad5d4e3a34c8c98358d003010f9e8 /util | |
parent | 2ff92a4408331b087dc4637bb1b5ac87a8ed5e27 (diff) |
Initial revision
Diffstat (limited to 'util')
-rw-r--r-- | util/ss/cmd_tbl.lex.l | 82 | ||||
-rw-r--r-- | util/ss/ct.y | 82 |
2 files changed, 164 insertions, 0 deletions
diff --git a/util/ss/cmd_tbl.lex.l b/util/ss/cmd_tbl.lex.l new file mode 100644 index 0000000..166f76d --- /dev/null +++ b/util/ss/cmd_tbl.lex.l @@ -0,0 +1,82 @@ +N [0-9] +PC [^\"] +AN [A-Z_a-z0-9] +%% + +command_table return l_command_table(); +request return l_request(); +unimplemented return l_unimplemented(); +end return l_end(); + +[\t\n ] ; + +\"{PC}*\" return l_quoted_string(); + +{AN}* return l_string(); + +#.*\n ; + +. return (*yytext); +%% +/* + * User-subroutines section. + * + * Have to put all this stuff here so that the include file + * from YACC output can be included, since LEX doesn't allow + * an include file before the code it generates for the above + * rules. + * + * Copyright 1987 by MIT Student Information Processing Board. + * + * For copyright info, see mit-sipb-copyright.h. + */ +#include <string.h> +#include "ct.tab.h" +#include "mit-sipb-copyright.h" + +#ifndef HAS_STRDUP +extern char *strdup(); +#endif + +extern char *last_token; + +static l_command_table() +{ + last_token = "command_table"; + return COMMAND_TABLE; +} + +static l_request() +{ + last_token = "request"; + return REQUEST; +} + +static l_unimplemented() +{ + last_token = "unimplemented"; + return UNIMPLEMENTED; +} + +static l_end() +{ + last_token = "end"; + return END; +} + +static l_quoted_string() +{ + register char *p; + yylval.dynstr = strdup(yytext+1); + if (p=strrchr(yylval.dynstr, '"')) + *p='\0'; + last_token = strdup(yylval.dynstr); + return STRING; +} + +static l_string() +{ + yylval.dynstr = strdup(yytext); + last_token = strdup(yylval.dynstr); + return STRING; +} diff --git a/util/ss/ct.y b/util/ss/ct.y new file mode 100644 index 0000000..f1941fc --- /dev/null +++ b/util/ss/ct.y @@ -0,0 +1,82 @@ +%{ +/* + * Copyright 1987 by MIT Student Information Processing Board + * + * For copyright info, see mit-sipb-copyright.h. + */ +#include <stdio.h> +#include <string.h> +#include "mit-sipb-copyright.h" + +#ifndef HAS_STRDUP +extern char *strdup(); +#endif + +char *str_concat3(), *generate_rqte(), *quote(); +long flag_value(); +char *last_token = (char *)NULL; +FILE *output_file; +long gensym_n = 0; + +%} +%union { + char *dynstr; + long flags; +} + +%token COMMAND_TABLE REQUEST UNKNOWN UNIMPLEMENTED END +%token <dynstr> STRING +%token <dynstr> FLAGNAME +%type <dynstr> namelist header request_list +%type <dynstr> request_entry +%type <flags> flag_list options +%left OPTIONS +%{ +#include "ss.h" +%} +%start command_table +%% +command_table : header request_list END ';' + { write_ct($1, $2); } + ; + +header : COMMAND_TABLE STRING ';' + { $$ = $2; } + ; + +request_list : request_list request_entry + { $$ = str_concat3($1, $2, ""); } + | + { $$ = ""; } + ; + +request_entry : REQUEST STRING ',' STRING ',' namelist ',' options ';' + { $$ = generate_rqte($2, quote($4), $6, $8); } + | REQUEST STRING ',' STRING ',' namelist ';' + { $$ = generate_rqte($2, quote($4), $6, 0); } + | UNKNOWN namelist ';' + { $$ = generate_rqte("ss_unknown_request", + (char *)NULL, $2, 0); } + | UNIMPLEMENTED STRING ',' STRING ',' namelist ';' + { $$ = generate_rqte("ss_unimplemented", quote($4), $6, 3); } + ; + +options : '(' flag_list ')' + { $$ = $2; } + | '(' ')' + { $$ = 0; } + ; + +flag_list : flag_list ',' STRING + { $$ = $1 | flag_val($3); } + | STRING + { $$ = flag_val($1); } + ; + +namelist: STRING + { $$ = quote(strdup($1)); } + | namelist ',' STRING + { $$ = str_concat3($1, quote($3), ",\n "); } + ; + +%% |