home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume10
/
contool
/
part02
/
parse.y
< prev
next >
Wrap
Text File
|
1990-10-30
|
7KB
|
319 lines
/************************************************************************/
/* Copyright 1988-1990 by Chuck Musciano and Harris Corporation */
/* */
/* Permission to use, copy, modify, and distribute this software */
/* and its documentation for any purpose and without fee is */
/* hereby granted, provided that the above copyright notice */
/* appear in all copies and that both that copyright notice and */
/* this permission notice appear in supporting documentation, and */
/* that the name of Chuck Musciano and Harris Corporation not be */
/* used in advertising or publicity pertaining to distribution */
/* of the software without specific, written prior permission. */
/* Chuck Musciano and Harris Corporation make no representations */
/* about the suitability of this software for any purpose. It is */
/* provided "as is" without express or implied warranty. This */
/* software may not be sold without the prior explicit permission */
/* of Harris Corporation. */
/************************************************************************/
%{
#include <stdio.h>
#include <ctype.h>
#include "manifest.h"
#include "contool.h"
EXPORT Props *parsed_defaults;
EXPORT Filter *parsed_filters;
EXPORT int parse_errors_occured;
PRIVATE char *get_last_token();
PRIVATE Filter *curr;
PRIVATE char *curr_file;
PRIVATE int line_count = 1;
PRIVATE char ungetc = -1;
%}
%start configuration
%union {char *cpval;
int ival;
Filter *fval;
Props *pval;
}
%token <cpval> STRING
%token <ival> INTEGER
%token LBRACE RBRACE
%token BEEP CHECK_ICON COMMAND COMMENT DEFAULTS DELETE DISPLAY FILTERS
FLASH FLASH_ICON GOOD_ICON IGNORE LOG_BEFORE_FILTERING LOG_FILE
MATCH NO NOFLASH NOOPEN NOSTAMP OPEN PRINT SAVE STAMP TIMESTAMP TO YES
%type <ival> beep flash old_flash old_open old_stamp open stamp yes_no
%type <cpval> command old_end_string string
%type <fval> filter filter_list old_filter old_filter_list old_ignore old_save
%%
configuration : empty
| old_style
| new_style
;
old_style : old_filter_list
{ parsed_defaults = NULL;
parsed_filters = $1;
}
;
old_filter_list : old_filter
{ $$ = $1; }
| old_filter_list old_filter
{ Filter *f;
for (f = $1; f->next; f = f->next)
;
f->next = $2;
$$ = $1;
}
;
old_filter : old_save
| old_ignore
;
old_save : SAVE beep old_flash old_open old_stamp STRING old_end_string
{ Filter *f;
char *msg;
f = (Filter *) malloc(sizeof(Filter));
f->save = TRUE;
f->beep = $2;
f->flash = $3;
f->open = $4;
f->stamp = $5;
f->start = $6;
f->stop = $7;
f->start_re = NULL;
f->stop_re = NULL;
f->command = NULL;
f->comment = NULL;
f->next = NULL;
if (msg = compile_exp(f, f->start, f->stop))
yyerror(msg);
$$ = f;
}
;
old_ignore : IGNORE STRING old_end_string
{ Filter *f;
char *msg;
f = (Filter *) malloc(sizeof(Filter));
f->save = FALSE;
f->beep = 0;
f->flash = FALSE;
f->open = FALSE;
f->stamp = FALSE;
f->start = $2;
f->stop = $3;
f->start_re = NULL;
f->stop_re = NULL;
f->command = NULL;
f->comment = NULL;
f->next = NULL;
if (msg = compile_exp(f, f->start, f->stop))
yyerror(msg);
$$ = f;
}
;
old_flash : FLASH
{ $$ = TRUE; }
| NOFLASH
{ $$ = FALSE; }
;
old_open : OPEN
{ $$ = TRUE; }
| NOOPEN
{ $$ = FALSE; }
;
old_stamp : STAMP
{ $$ = TRUE; }
| NOSTAMP
{ $$ = FALSE; }
;
old_end_string : empty
{ $$ = NULL; }
| TO STRING
{ $$ = $2; }
;
new_style : defaults
| filters
| defaults filters
;
defaults : DEFAULTS
{ parsed_defaults = (Props *) malloc(sizeof(Props));
*parsed_defaults = defaults;
}
LBRACE default_list RBRACE
;
filters : FILTERS LBRACE filter_list RBRACE
{ parsed_filters = $3; }
;
default_list : empty
| default_list default
;
default : beep
{ parsed_defaults->beep = $1; }
| command
{ parsed_defaults->command = $1; }
| flash
{ parsed_defaults->flash = $1; }
| open
{ parsed_defaults->open = $1; }
| stamp
{ parsed_defaults->stamp = $1; }
| CHECK_ICON string
{ parsed_defaults->bad_icon = $2; }
| DELETE INTEGER
{ parsed_defaults->delete_amount = $2; }
| DISPLAY INTEGER
{ parsed_defaults->max_size = $2; }
| FLASH_ICON string
{ parsed_defaults->flash_icon = $2; }
| GOOD_ICON string
{ parsed_defaults->good_icon = $2; }
| LOG_BEFORE_FILTERING yes_no
{ parsed_defaults->log_after = !$2; }
| LOG_FILE string
{ parsed_defaults->log_file = $2; }
| PRINT STRING
{ parsed_defaults->print_filter = $2; }
| TIMESTAMP INTEGER
{ parsed_defaults->stamp_resolution = $2; }
;
filter_list : empty
{ $$ = NULL; }
| filter_list filter
{ Filter *f;
if ($1 == NULL)
$$ = $2;
else {
for (f = $1; f->next; f = f->next)
;
f->next = $2;
$$ = $1;
}
}
;
filter : LBRACE
{ curr = (Filter *) malloc(sizeof(Filter));
bzero(curr, sizeof(Filter));
}
filter_attr_list RBRACE
{ char *msg;
if (curr->start == NULL)
yyerror("no filter pattern specified");
if (msg = compile_exp(curr, curr->start, curr->stop))
yyerror(msg);
$$ = curr;
}
;
filter_attr_list: empty
| filter_attr_list filter_attr
;
filter_attr : beep
{ curr->beep = $1; }
| command
{ curr->command = $1; }
| flash
{ curr->flash = $1; }
| open
{ curr->open = $1; }
| stamp
{ curr->stamp = $1; }
| COMMENT string
{ curr->comment = $2; }
| IGNORE yes_no
{ curr->save = !$2; }
| MATCH string
{ curr->start = $2; }
| TO string
{ curr->stop = $2; }
;
beep : BEEP INTEGER
{ $$ = $2; }
;
command : COMMAND string
{ $$ = $2; }
;
flash : FLASH yes_no
{ $$ = $2; }
;
open : OPEN yes_no
{ $$ = $2; }
;
stamp : STAMP yes_no
{ $$ = $2; }
;
yes_no : YES
{ $$ = TRUE; }
| NO
{ $$ = FALSE; }
;
string : STRING
{ $$ = (*$1 == '\0')? NULL : $1; }
;
empty : ;
%%
/************************************************************************/
PRIVATE yyerror(s1, s2, s3, s4, s5, s6, s7)
char *s1, *s2, *s3, *s4, *s5, *s6, *s7;
{ char buf1[1024], buf2[1024];
sprintf(buf1, "%s: line %d: ", curr_file, line_count - ((ungetc == '\n')? 1 : 0));
sprintf(buf2, s1, s2, s3, s4, s5, s6, s7);
strcat(buf1, buf2);
if (strcmp(s1, "syntax error") == 0) {
strcat(buf1, " at or near ");
strcat(buf1, get_last_token());
}
error(buf1);
yyclearin;
parse_errors_occured++;
}
#include "lex.c"