home *** CD-ROM | disk | FTP | other *** search
- /**********************************************/
- /* */
- /* YACC source file for the telecom compiler */
- /* */
- /**********************************************/
- /*
- Written by Tim Capps, 4/11/90
- Copyright 1990, QED Software, all rights reserved.
- */
-
- %{
- /* Make the generated module separately compilable */
-
- #ifdef BORLAND
- #pragma warn -sus /* No suspicious pointer messages */
- #endif
-
- #define YYDEBUG 1
- #define CUSTOM_SIZE 200 /* Initial allocation for custom resources */
-
- extern "C" {
- #include <String.H>
- #include <CType.H>
- #include <stdlib.h>
- #include <stdio.h>
- #include <io.h>
- }
-
- #include "pcodes.h" /* P-codes understood by the com engine */
-
- extern short yystate;
- extern FILE * comOut;
-
- char *p; /* General purpose pointer */
- char *pbase; /* Pointer to base of generic structure */
- long psize; /* Size of data pointed to by p */
- char *junk; /* Pointer to someting about to be trashed */
- int *pi; /* Integer pointer */
- short *ps; /* Short pointer */
- int x; /* Work variable */
-
- int yyerror(char *);
- int yylex();
-
- %}
-
- %start com
-
- %union
- {
- int ival; /* Integer value */
- long lval; /* Long value */
- char * ptr; /* General pointer */
- }
-
-
- /************/
- /* Tokens */
- /************/
-
- %token <ival> YDEBUG NOYDEBUG
- %token <ival> SHIFT_RIGHT SHIFT_LEFT LOGICAL_OR LOGICAL_AND
- %token <ival> NOT_EQ EQ GT_EQ LT_EQ BYTE_LITCONST
-
- %token <lval> CONSTANT LITCONST
-
- %token <ptr> STRING
-
- /* Commands */
- %token <ival> SEND WAIT FOR EOL ANYTHING ELSE END BELL NOTIFY ON OFF
- %token <ival> SLOW CLOSE WINDOW DISPLAYCOMMENT ERASECOMMENT
-
- /***********************/
- /* Nonterminal types */
- /***********************/
-
- %type <ival> byte_litconst
-
- %type <lval> long_constant expression literal_constant
-
- /*************************/
- /* Operator Precedence */
- /*************************/
-
- /* This is the same as 'C' operator precedence */
- %left LOGICAL_OR
- %left LOGICAL_AND
- %left '|'
- %left '^'
- %left '&'
- %left EQ NOT_EQ
- %left '<' LT_EQ '>' GT_EQ
- %left SHIFT_RIGHT SHIFT_LEFT
- %left '+' '-'
- %left '*' '/' '%'
- %right '!' '~'
- %left ','
-
- %%
-
- /*******************************************/
- /* */
- /* Communication Script Compiler Grammar */
- /* */
- /*******************************************/
-
- com: /* nothing */
- | com statement
- | com test
- | com error
- ;
-
- statement: end
- | send
- | waitfor
- | notify
- | bell
- | wait
- | closewindow
- | dispcom /* Display text in comment area */
- | erasecom /* Erase comment area */
- | toggle_debug
- ;
-
- test: '=' expression ';'
- {
- printf ("Result=%i\n", $2);
- }
-
- /* Display text in the comment area */
- dispcom: DISPLAYCOMMENT STRING
- {
- fputc(PC_DISPCOM, comOut); // Display comment text
- /* Length is +2 to include length byte + terminator */
- fputc(strlen($2)+2, comOut);// Write the length
- fputs($2, comOut); // Write string w/o null
- fputc(0, comOut); // Termnate it
- }
-
- /* Erase the comment area */
- erasecom: ERASECOMMENT
- {
- fputc(PC_ERASECOM, comOut);
- }
-
- /* Close the current window */
- closewindow: CLOSE WINDOW
- {
- fputc(PC_CLOSEWINDOW, comOut);
- }
-
- /* Wait a specified number of seconds */
- /* Wait P-code is followed by int count */
- wait: WAIT expression
- {
- fputc(PC_WAIT, comOut);
- x=$2; // Make it into an INT
- (void) fwrite(&x, sizeof(int), 1, comOut);
- }
-
- /* End of com program */
- end: END
- {
- fputc(PC_END, comOut); /* Write the end command */
- }
-
- /* Send a string to the remote host */
- send: SEND STRING
- {
- fputc(PC_SEND, comOut); // Start a send command
- /* Length is +1 to include the length byte */
- fputc(strlen($2)+1, comOut);// Write the length
- fputs($2, comOut); // Write string w/o null
- /* NOTE: WE DON'T TERMINATE THE STRING! */
- }
- | SEND SLOW STRING
- {
- fputc(PC_SENDSLOW, comOut); // Start a send command
- /* Length is +1 to include the length byte */
- fputc(strlen($3)+1, comOut);// Write the length
- fputs($3, comOut); // Write string w/o null
- /* NOTE: WE DON'T TERMINATE THE STRING! */
- }
-
-
- /* Wait for a string from the remote host */
- waitfor: WAIT FOR STRING
- {
- fputc(PC_WAITFOR, comOut); // Wait for a string
- /* Length is +2 to include length byte + terminator */
- fputc(strlen($3)+2, comOut);// Write the length
- fputs($3, comOut); // Write string w/o null
- fputc(0, comOut); // Termnate it
- }
-
- /* Turn BISON debugging on/off */
- toggle_debug: YDEBUG ON
- {
- yydebug=1;
- }
- | YDEBUG OFF
- {
- yydebug=0;
- }
- ;
-
- /* Beep the terminal */
- bell: BELL
- {
- fputc(PC_BELL, comOut); // Beep!
- }
-
- /* Put up a 'notify' box */
- notify: NOTIFY STRING
- {
- fputc(PC_NOTIFY, comOut);
- /* Length is +2 because we have a null terminator */
- /* and we include the length byte. */
- fputc(strlen($2)+2, comOut); // Write the length
- fputs($2, comOut); // Write string w/o null
- fputc(0, comOut); // Termnate it w/null
- }
- | NOTIFY OFF
- {
- fputc(PC_NOTIFYOFF, comOut); // Remove notify box
- }
-
- /* Expressions */
-
- expression: long_constant
- | byte_litconst
- {
- $$=$1; /* Avoid type mismatch warning */
- }
- | literal_constant
- | '-' expression
- {
- $$=(-$2);
- }
- | '~' expression
- {
- $$=(~$2);
- }
- | '!' expression
- {
- $$=(!$2);
- }
- | '(' expression ')'
- {
- $$=$2;
- }
- | expression SHIFT_RIGHT expression
- {
- $$=($1 >> $3);
- }
- | expression SHIFT_LEFT expression
- {
- $$=($1 << $3);
- }
- | expression '^' expression
- {
- $$=($1 ^ $3);
- }
- | expression LOGICAL_OR expression
- {
- $$=($1 || $3);
- }
- | expression LOGICAL_AND expression
- {
- $$=($1 && $3);
- }
- | expression '|' expression
- {
- $$=($1 | $3);
- }
- | expression '&' expression
- {
- $$=($1 & $3);
- }
- | expression NOT_EQ expression
- {
- $$=($1 != $3);
- }
- | expression EQ expression
- {
- $$=($1 == $3);
- }
- | expression GT_EQ expression
- {
- $$=($1 >= $3);
- }
- | expression LT_EQ expression
- {
- $$=($1 <= $3);
- }
- | expression '>' expression
- {
- $$=($1 > $3);
- }
- | expression '<' expression
- {
- $$=($1 < $3);
- }
- | expression '-' expression
- {
- $$=($1 - $3);
- }
- | expression '+' expression
- {
- $$=($1 + $3);
- }
- | expression '*' expression
- {
- $$=($1 * $3);
- }
- | expression '/' expression
- {
- if ($3!=0) {
- $$=($1 / $3);
- } else {
- /* This error should be handled properly! */
- /* At the moment, I don't know how - sorry. */
- yyerror("Attempt to divide by zero");
- break;
- }
- }
- | expression '%' expression
- {
- $$=($1 % $3);
- }
- ;
-
- /* Numbers */
-
- long_constant: CONSTANT
- ;
-
- literal_constant: LITCONST
- ;
-
- byte_litconst: BYTE_LITCONST
- ;
-