This is a multi-part message in MIME format.
--------------5C633B2F64B5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Greetings fellow Unixheads,
I am writing an *interactive* command line parser. I would like it
to be in the DEC style (ala Kermit) but the yacc code will only
parse 1 lexeme(token) before abruptly quitting and declaring the
parse a failure. You can refer to ORA's "lex & yacc" by Levine, Mason
and Brown. The stuff I have written with flex in the past has been
with the -B <noninteractive> mode.This is being done (currently)
on DEC UNIX 3.2d and Solaris 2.5.1.
Thanks in advance,
J.C. Magras
--
Unix Software Engineer looking for C++/UNIX/Motif/Perl/Tk/Flex
Software Engineering position **NOW**. Currently in Austin at
--------------5C633B2F64B5
Content-Type: image/x-xbitmap; name="y.tab.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="y.tab.h"
#define STRING 1
#define DIRPATH 2
#define IDENTIFIER 3
#define INTEGER 4
#define KEYWORD 32
#define CREATE_K 32
#define MODIFY_K 33
#define ADD_K 34
#define DELETE_K 35
#define QUIT_K 36
#define PRINT_K 37
#define AT_K 38
#define TO_K 39
#define TYPES 64
#define CHAR 64
#define BYTE 65
#define INTEGER16 66
#define INTEGER32 67
#define INTEGER64 68
#define UINT16 69
#define UINT32 70
#define UINT64 71
#define STRUCT 72
#define SEQ_OF 73
--------------5C633B2F64B5
Content-Type: text/plain; charset=us-ascii; name="jDirAdmin.y"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="jDirAdmin.y"
%{
#ifndef __cplusplus
#define C_NEWLINE "\n"
#define PRINTF printf(
#else
#define cout <<
#define C_NEWLINE << endl
#endif
%}
%union {
long intValue;
char string[64];
%token DELETE_K QUIT_K AT_K CREATE_K MODIFY_K ADD_KQuote:}
%token PRINT_K SEQ_OF DIRPATH
%token <string> IDENTIFIER
%token CHAR BYTE INTEGER16 INTEGER32 INTEGER64 UINT16 UINT32 UINT64 STRUCT
%token <intValue> INTEGER
%start full
%type <string>instance
%%
full: command | |
QUIT_K { PRINTF "exiting" C_NEWLINE);YYACCEPT;};
command: verb type instance AT_K dpath {
printf ("DEBUG:command<-verb type instance AT_K dpath\n");
| DELETE_K dpath {Quote:}
printf ("DEBUG:command<-DELETE_K dpath\n");
verb: CREATE_K | MODIFY_K | ADD_K | PRINT_K ;Quote:};
type:
CHAR {
printf ("DEBUG:type<- CHAR\n");
printf ("DEBUG:type<- BYTE\n");Quote:} |BYTE {
printf ("DEBUG:type<- INTEGER16\n");Quote:} |INTEGER16 {
printf ("DEBUG:type<- INTEGER32\n");Quote:}|INTEGER32 {
printf ("DEBUG:type<- INTEGER64\n");Quote:}|INTEGER64 {
printf ("DEBUG:type<- UINT16\n");Quote:}|UINT16 {
printf ("DEBUG:type<- UINT32\n");Quote:}|UINT32 {
printf ("DEBUG:type<- UINT64\n");Quote:}|UINT64 {
printf ("DEBUG:type<- STRUCT\n");Quote:}|STRUCT {
|SEQ_OF INTEGER type {Quote:}
printf ("DEBUG:type<- SEQ_OF INTEGER type\n");
dpath: DIRPATH {Quote:};
printf ("DEBUG:dpath <- DIRPATH\n");
instance: IDENTIFIER {Quote:};
printf ("DEBUG:instance <- IDENTIFIER\n");
strcpy($<string>$, $<string>1);
%%Quote:}
yyerror(char *errstring) {
strerror(errstring);
--------------5C633B2F64B5Quote:}
Content-Type: text/plain; charset=us-ascii; name="jDirAdmin.l"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="jDirAdmin.l"
%{
#include "y.tab.h"
int lookup(char*);
typedef union { long intValue; char string [64]; } YYSTYPE;
extern YYSTYPE yylval;
%}
/*
whitespace
<string> path pathcomp identifer keyword_ptn
<intValue> integer
newline
*/
identifier [_a-zA-Z][_a-zA-Z0-9]+
keyword_ptn [a-z]+
integer [0-9]+
pathcomp ([1](\.[0-9][0-9]*)* | / | (/[a-bA-Z][0-9A-Za-z_]+)+)
whitespace [ \t]+
newline \n
%s keyword_ptn
%%
{keyword_ptn} { printf ("keyword\n");strcpy(yylval.string,yytext);
return lookup(yytext); }
{identifier} { printf ("identifier\n");strcpy(yylval.string,yytext);
return IDENTIFIER ; }
{integer} { printf ("integer\n");yylval.intValue
= atol(yytext);
return INTEGER ; }
[1](\.[0-9][0-9]*)* | / | (/[a-bA-Z][0-9A-Za-z_]+)+ { printf ("pathname\n"); strcpy(yylval.string,yytext) ; return DIRPATH; }
[ \t]+ ;
\n { return 0 ; }
. ECHO;
%%
int lookup (char *yytext){
int index;
char *keywords[]= {
"create","modify","add",
"delete","quit","print","to","add","of"
};
char *types[]= {
"char","byte","int16","int32","int64",
"uint16","uint32","uint64","struct",
"sequenceof","message","response","request"
};
for (index=0;index<(sizeof(keywords)/sizeof(char*));index++) {
printf ("index=%d\n",index);
if ( strcmp(yytext,keywords[index])==0)
return KEYWORD+index;
}
for (index=0;index<(sizeof(types)/sizeof(char*));index++) {
printf ("index=%d\n",index);
if ( strcmp(yytext,types[index])==0)
return TYPES+index;
}
return (STRING);
--------------5C633B2F64B5--Quote:}