home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
gdead.berkeley.edu
/
gdead.berkeley.edu.tar
/
gdead.berkeley.edu
/
pub
/
cad-tools
/
ciftomann.tar
/
cmd_dir
/
parse.y
< prev
next >
Wrap
Text File
|
1988-01-28
|
3KB
|
178 lines
%{
/* This is the yacc file describing the input syntax for
* the ciftomann command file. It is an overkill to use
* yacc for this sort of thing, but it is easier than writing
* my own parser
*/
#include "pg_desc.h"
extern float scale;
char *strcpy();
%}
%union {
char *strval;
int intval;
float floatval;
struct {
int invert_flag;
int mod_factor;
} optlistval;
struct {
enum { MOD, INV } type;
union {
int invert_flag;
int mod_factor;
} value;
} optval;
}
%token LAYER NUMBER FLOAT MINUS INVERT GROW SHRINK EOL SCALE
%token APERTURE_MAX APERTURE_MIN STAGE_MAX STAGE_MIN GRID_SIZE
%token CONVERT_FACTOR
%type <intval> NUMBER SNUMBER
%type <floatval> FLOAT
%type <strval> layer_name LAYER
%type <optval> option
%type <optlistval> option_list options
%start file
%%
file : scale cmds
| cmds
;
scale : SCALE NUMBER EOL
{
scale = (float) $2;
}
| SCALE FLOAT EOL
{
scale = $2;
}
;
cmds : cmd
| cmds cmd
;
cmd : layer
| pg_param
;
pg_param : APERTURE_MAX NUMBER EOL
{
pg_desc.aperture_max = $2;
pg_modified++;
}
| APERTURE_MIN NUMBER EOL
{
pg_desc.aperture_min = $2;
pg_modified++;
}
| STAGE_MAX NUMBER EOL
{
pg_desc.stage_max = $2;
pg_modified++;
}
| STAGE_MIN NUMBER EOL
{
pg_desc.stage_min = $2;
pg_modified++;
}
| GRID_SIZE NUMBER EOL
{
pg_desc.grid_size = $2;
pg_modified++;
}
| CONVERT_FACTOR NUMBER EOL
{
pg_desc.convert_factor = $2;
pg_modified++;
}
| CONVERT_FACTOR FLOAT EOL
{
pg_desc.convert_factor = $2;
pg_modified++;
}
;
layer : layer_name option_list EOL
{
make_cmd($1,$2.mod_factor,
$2.invert_flag,$1);
}
| layer_name option_list layer_name EOL
{
make_cmd($1,$2.mod_factor,
$2.invert_flag,$3);
}
;
option_list : options
|
{
$$.mod_factor = 0;
$$.invert_flag = 0;
}
;
options : option
{
if ($1.type == MOD) {
$$.mod_factor =
$1.value.mod_factor;
$$.invert_flag = 0;
} else {
$$.invert_flag =
$1.value.invert_flag;
$$.mod_factor = 0;
}
}
| options option
{
if ($2.type == MOD)
$$.mod_factor =
$2.value.mod_factor;
else
$$.invert_flag =
$2.value.invert_flag;
}
;
option : SNUMBER
{
$$.type = MOD;
$$.value.mod_factor = $1;
}
| SHRINK NUMBER
{
$$.type = MOD;
$$.value.mod_factor = -$2;
}
| GROW NUMBER
{
$$.type = MOD;
$$.value.mod_factor = $2;
}
| INVERT
{
$$.type = INV;
$$.value.invert_flag = 1;
}
;
SNUMBER : NUMBER
| MINUS NUMBER
{
$$ = -$2;
}
;
layer_name : LAYER
{
$$ = strcpy(malloc(strlen($1)+1),$1);
}
;