From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,ec53cda8d00593d7,start X-Google-Attributes: gidfc89c,public X-Google-Thread: 11035d,ec53cda8d00593d7,start X-Google-Attributes: gid11035d,public X-Google-Thread: fee84,ec53cda8d00593d7,start X-Google-Attributes: gidfee84,public From: magrasjc@texas.net Subject: Help with bison built interactive parser Date: 1997/06/17 Message-ID: <33A6CBBF.30ED@texas.net> X-Deja-AN: 249106320 Organization: Texas Networking, Inc. Newsgroups: comp.unix.programmer,comp.unix.solaris,comp.unix.osf.osf1 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 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 (512) 672-5778/magrasjc@texas.net. have Answering machine. --------------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_K %token PRINT_K SEQ_OF DIRPATH %token IDENTIFIER %token CHAR BYTE INTEGER16 INTEGER32 INTEGER64 UINT16 UINT32 UINT64 STRUCT %token INTEGER %start full %type 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 { printf ("DEBUG:command<-DELETE_K dpath\n"); }; verb: CREATE_K | MODIFY_K | ADD_K | PRINT_K ; type: CHAR { printf ("DEBUG:type<- CHAR\n"); } |BYTE { printf ("DEBUG:type<- BYTE\n"); } |INTEGER16 { printf ("DEBUG:type<- INTEGER16\n"); }|INTEGER32 { printf ("DEBUG:type<- INTEGER32\n"); }|INTEGER64 { printf ("DEBUG:type<- INTEGER64\n"); }|UINT16 { printf ("DEBUG:type<- UINT16\n"); }|UINT32 { printf ("DEBUG:type<- UINT32\n"); }|UINT64 { printf ("DEBUG:type<- UINT64\n"); }|STRUCT { printf ("DEBUG:type<- STRUCT\n"); } |SEQ_OF INTEGER type { printf ("DEBUG:type<- SEQ_OF INTEGER type\n"); }; dpath: DIRPATH { printf ("DEBUG:dpath <- DIRPATH\n"); }; instance: IDENTIFIER { printf ("DEBUG:instance <- IDENTIFIER\n"); strcpy($$, $1); } %% yyerror(char *errstring) { strerror(errstring); } --------------5C633B2F64B5 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 path pathcomp identifer keyword_ptn 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--