Removed depend. in lstLib.a & added "option" statement to SNL.
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
$Id$
|
||||
DESCRIPTION: gen_ss_code.c -- routines to generate state set code
|
||||
ENVIRONMENT: UNIX
|
||||
HISTORY:
|
||||
19nov91,ajk Changed find_var() to findVar().
|
||||
***************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include "parse.h"
|
||||
@@ -400,7 +402,7 @@ Expr *sp; /* current State struct */
|
||||
ep1 = ep->left; /* ptr to 1-st parameters */
|
||||
if ( (ep1 != 0) && (ep1->type == E_VAR) )
|
||||
{
|
||||
vp = (Var *)find_var(ep1->value);
|
||||
vp = (Var *)findVar(ep1->value);
|
||||
cp = vp->chan;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -31,7 +31,6 @@ int nstates; /* total # states in all state sets */
|
||||
|
||||
gen_tables()
|
||||
{
|
||||
extern LIST var_list; /* variables (from parse) */
|
||||
extern Expr *ss_list; /* state sets (from parse) */
|
||||
extern char *global_c_code; /* global C code */
|
||||
|
||||
@@ -54,14 +53,15 @@ gen_tables()
|
||||
/* Generate database blocks with structure and data for each defined channel */
|
||||
gen_db_blocks()
|
||||
{
|
||||
extern LIST chan_list;
|
||||
Chan *cp;
|
||||
int nchan;
|
||||
extern Chan *chan_list;
|
||||
Chan *cp;
|
||||
int nchan;
|
||||
|
||||
printf("\n/* Database Blocks */\n");
|
||||
printf("static CHAN db_channels[NUM_CHANNELS] = {\n");
|
||||
nchan = 0;
|
||||
for (cp = firstChan(&chan_list); cp != NULL; cp = nextChan(cp))
|
||||
|
||||
for (cp = chan_list; cp != NULL; cp = cp->next)
|
||||
{
|
||||
/* Only process db variables */
|
||||
if (cp->db_name != NULL)
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
and linked lists, which are then passed on to the phase 2 routines.
|
||||
|
||||
ENVIRONMENT: UNIX
|
||||
HISTORY:
|
||||
19nov91,ajk Replaced lstLib calls with built-in links.
|
||||
20nov91,ajk Removed snc_init() - no longer did anything useful.
|
||||
20nov91,ajk Added option_stmt() routine.
|
||||
***************************************************************************/
|
||||
|
||||
/*====================== Includes, globals, & defines ====================*/
|
||||
@@ -34,33 +38,16 @@ Expr *defn_c_list; /* definition C code list */
|
||||
|
||||
Expr *ss_list; /* Start of state set list */
|
||||
|
||||
Expr *exit_code_list; /* Start of exit code list */
|
||||
Expr *exit_code_list; /* Start of exit code list */
|
||||
|
||||
LIST var_list; /* start of variable list */
|
||||
Var *var_list = NULL; /* start of variable list */
|
||||
Var *var_tail = NULL; /* tail of variable list */
|
||||
|
||||
LIST chan_list; /* start of DB channel list */
|
||||
Chan *chan_list = NULL; /* start of DB channel list */
|
||||
Chan *chan_tail = NULL; /* tail of DB channel list */
|
||||
|
||||
Expr *global_c_list; /* global C code following state program */
|
||||
/*+************************************************************************
|
||||
* NAME: snc_init
|
||||
*
|
||||
* CALLING SEQUENCE: none
|
||||
*
|
||||
* RETURNS:
|
||||
*
|
||||
* FUNCTION: Initialize state program tables & linked lists
|
||||
*
|
||||
* NOTES:
|
||||
*-*************************************************************************/
|
||||
init_snc()
|
||||
{
|
||||
extern char in_file[], *src_file;
|
||||
|
||||
lstInit(&var_list);
|
||||
lstInit(&chan_list);
|
||||
src_file = &in_file[0];
|
||||
return;
|
||||
}
|
||||
/*+************************************************************************
|
||||
* NAME: program_name
|
||||
*
|
||||
@@ -109,10 +96,11 @@ char *value; /* initial value or NULL */
|
||||
length = 0;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "variable decl: type=%d, name=%s, length=%d\n", type, name, length);
|
||||
fprintf(stderr, "variable decl: type=%d, name=%s, length=%d\n",
|
||||
type, name, length);
|
||||
#endif
|
||||
/* See if variable already declared */
|
||||
vp = (Var *)find_var(name);
|
||||
vp = (Var *)findVar(name);
|
||||
if (vp != 0)
|
||||
{
|
||||
fprintf(stderr, "variable %s already declared, line %d\n",
|
||||
@@ -121,7 +109,7 @@ char *value; /* initial value or NULL */
|
||||
}
|
||||
/* Build a struct for this variable */
|
||||
vp = allocVar();
|
||||
lstAdd(&var_list, (NODE *)vp);
|
||||
addVar(vp); /* add to var list */
|
||||
vp->name = name;
|
||||
vp->type = type;
|
||||
vp->length = length;
|
||||
@@ -129,6 +117,38 @@ char *value; /* initial value or NULL */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Option statement */
|
||||
option_stmt(option, value)
|
||||
char *option; /* "a", "r", ... */
|
||||
int value; /* TRUE means +, FALSE means - */
|
||||
{
|
||||
extern int async_flag, conn_flag, debug_flag,
|
||||
line_flag, reent_flag, warn_flag;
|
||||
|
||||
switch(*option)
|
||||
{
|
||||
case 'a':
|
||||
async_flag = value;
|
||||
break;
|
||||
case 'c':
|
||||
conn_flag = value;
|
||||
break;
|
||||
case 'd':
|
||||
debug_flag = value;
|
||||
break;
|
||||
case 'l':
|
||||
line_flag = value;
|
||||
break;
|
||||
case 'r':
|
||||
reent_flag = value;
|
||||
break;
|
||||
case 'w':
|
||||
warn_flag = value;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* "Assign" statement: assign a variable to a DB channel.
|
||||
elem_num is ignored in this version) */
|
||||
assign_stmt(name, db_name)
|
||||
@@ -139,8 +159,11 @@ char *db_name; /* ptr to db name */
|
||||
Var *vp;
|
||||
extern int line_num;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "assign_stmt: name=%s, db_name=%s\n", name, db_name);
|
||||
#endif DEBUG
|
||||
/* Find the variable */
|
||||
vp = (Var *)find_var(name);
|
||||
vp = (Var *)findVar(name);
|
||||
if (vp == 0)
|
||||
{
|
||||
fprintf(stderr, "assign: variable %s not declared, line %d\n",
|
||||
@@ -150,7 +173,7 @@ char *db_name; /* ptr to db name */
|
||||
|
||||
/* Build structure for this channel */
|
||||
cp = allocChan();
|
||||
lstAdd(&chan_list, (NODE *)cp);
|
||||
addChan(cp); /* add to Chan list */
|
||||
cp->var = vp; /* make connection to variable */
|
||||
vp->chan = cp; /* reverse ptr */
|
||||
cp->db_name = db_name; /* DB name */
|
||||
@@ -170,7 +193,7 @@ char *delta; /* monitor delta */
|
||||
extern int line_num;
|
||||
|
||||
/* Find a channel assigned to this variable */
|
||||
cp = (Chan *)find_chan(name);
|
||||
cp = (Chan *)findChan(name);
|
||||
if (cp == 0)
|
||||
{
|
||||
fprintf(stderr, "monitor: variable %s not assigned, line %d\n",
|
||||
@@ -193,7 +216,7 @@ char *ef_name;
|
||||
Var *vp;
|
||||
extern int line_num;
|
||||
|
||||
cp = (Chan *)find_chan(name);
|
||||
cp = (Chan *)findChan(name);
|
||||
if (cp == 0)
|
||||
{
|
||||
fprintf(stderr, "sync: variable %s not assigned, line %d\n",
|
||||
@@ -202,7 +225,7 @@ char *ef_name;
|
||||
}
|
||||
|
||||
/* Find the event flag varible */
|
||||
vp = (Var *)find_var(ef_name);
|
||||
vp = (Var *)findVar(ef_name);
|
||||
if (vp == 0 || vp->type != V_EVFLAG)
|
||||
{
|
||||
fprintf(stderr, "sync: e-f variable %s not declared, line %d\n",
|
||||
@@ -244,27 +267,38 @@ char *c_str; /* ptr to C code */
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Add a variable to the variable linked list */
|
||||
addVar(vp)
|
||||
Var *vp;
|
||||
{
|
||||
if (var_list == NULL)
|
||||
var_list = vp;
|
||||
else
|
||||
var_tail->next = vp;
|
||||
var_tail = vp;
|
||||
vp->next = NULL;
|
||||
}
|
||||
|
||||
/* Find a variable by name; returns a pointer to the Var struct;
|
||||
returns 0 if the variable is not found. */
|
||||
find_var(name)
|
||||
char *name;
|
||||
Var *findVar(name)
|
||||
char *name;
|
||||
{
|
||||
Var *vp;
|
||||
Var *vp;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "find_var, name=%s: ", name);
|
||||
fprintf(stderr, "findVar, name=%s: ", name);
|
||||
#endif
|
||||
vp = firstVar(&var_list);
|
||||
while (vp != NULL)
|
||||
for (vp = var_list; vp != NULL; vp = vp->next)
|
||||
{
|
||||
if (strcmp(vp->name, name) == 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "found\n");
|
||||
#endif
|
||||
return (int)vp;
|
||||
return vp;
|
||||
}
|
||||
vp = nextVar(vp);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "not found\n");
|
||||
@@ -272,23 +306,44 @@ char *name;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find channel with same variable name and same offset */
|
||||
find_chan(name)
|
||||
char *name; /* variable name */
|
||||
/* Add a channel to the channel linked list */
|
||||
addChan(cp)
|
||||
Chan *cp;
|
||||
{
|
||||
Chan *cp;
|
||||
Var *vp;
|
||||
if (chan_list == NULL)
|
||||
chan_list = cp;
|
||||
else
|
||||
chan_tail->next = cp;
|
||||
chan_tail = cp;
|
||||
cp->next = NULL;
|
||||
}
|
||||
|
||||
/* Find a channel with a given associated variable name */
|
||||
Chan *findChan(name)
|
||||
char *name; /* variable name */
|
||||
{
|
||||
Chan *cp;
|
||||
Var *vp;
|
||||
|
||||
for (cp = firstChan(&chan_list); cp != NULL; cp = nextChan(cp))
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "findChan, var name=%s: ", name);
|
||||
#endif
|
||||
for (cp = chan_list; cp != NULL; cp = cp->next)
|
||||
{
|
||||
vp = cp->var;
|
||||
if (vp == 0)
|
||||
continue;
|
||||
if (strcmp(vp->name, name) == 0)
|
||||
{
|
||||
return (int)cp;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "found chan name=%s\n", cp->db_name);
|
||||
#endif
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "not found\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -305,8 +360,8 @@ Expr *prog_list;
|
||||
{
|
||||
ss_list = prog_list;
|
||||
#ifdef DEBUG
|
||||
print_struct(ss_list);
|
||||
#endif
|
||||
fprintf(stderr, "----Phase2---\n");
|
||||
#endif DEBUG
|
||||
phase2(ss_list);
|
||||
|
||||
exit(0);
|
||||
@@ -338,7 +393,8 @@ Expr *right; /* RH side */
|
||||
/* Allocate a structure for this item or expression */
|
||||
ep = allocExpr();
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "expression: ep=%d, type=%s, value=\"%s\", left=%d, right=%d\n",
|
||||
fprintf(stderr,
|
||||
"expression: ep=%d, type=%s, value=\"%s\", left=%d, right=%d\n",
|
||||
ep, stype[type], value, left, right);
|
||||
#endif
|
||||
/* Fill in the structure */
|
||||
@@ -396,18 +452,8 @@ char *fname;
|
||||
src_file = fname;
|
||||
}
|
||||
|
||||
/* The ordering of this list must correspond with the ordering in parse.h */
|
||||
char *stype[] = {
|
||||
"E_EMPTY", "E_CONST", "E_VAR", "E_FUNC", "E_STRING", "E_UNOP", "E_BINOP",
|
||||
"E_ASGNOP", "E_PAREN", "E_SUBSCR", "E_TEXT", "E_STMT", "E_CMPND",
|
||||
"E_IF", "E_ELSE", "E_WHILE", "E_SS", "E_STATE", "E_WHEN" };
|
||||
|
||||
/* #define PHASE2*/
|
||||
#ifdef PHASE2
|
||||
phase2(ss_list)
|
||||
Expr *ss_list;
|
||||
{
|
||||
fprintf(stderr, "phase2() - dummy\07\n");
|
||||
/* Print structures */
|
||||
print_struct(ss_list);
|
||||
}
|
||||
#endif PHASE2
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
$Id$
|
||||
DESCRIPTION: Structures for parsing the state notation language.
|
||||
ENVIRONMENT: UNIX
|
||||
HISTORY:
|
||||
18nov91,ajk Replaced lstLib stuff with in-line links.
|
||||
***************************************************************************/
|
||||
/* Data for these blocks are generated by the parsing routines for each
|
||||
** state set. The tables are then used to generate the run-time C code
|
||||
@@ -13,8 +15,6 @@
|
||||
** the run-time code implementation.
|
||||
*/
|
||||
|
||||
#include "lstLib.h" /* VxWorks "list" routines & definitions */
|
||||
|
||||
struct expression /* Expression block */
|
||||
{
|
||||
struct expression *next; /* link to next expression */
|
||||
@@ -30,7 +30,7 @@ typedef struct expression Expr;
|
||||
|
||||
struct var /* Variable or function definition */
|
||||
{
|
||||
NODE V_link; /* next variable in list */
|
||||
struct var *next; /* link to next item in list */
|
||||
char *name; /* variable name */
|
||||
char *value; /* initial value or NULL */
|
||||
int type; /* var type */
|
||||
@@ -40,9 +40,9 @@ struct var /* Variable or function definition */
|
||||
};
|
||||
typedef struct var Var;
|
||||
|
||||
struct db_chan /* DB channel */
|
||||
struct db_chan /* DB channel info */
|
||||
{
|
||||
NODE D_link; /* next db chan in list */
|
||||
struct db_chan *next; /* link to next item in list */
|
||||
char *db_name; /* database name */
|
||||
int index; /* channel array index */
|
||||
Var *var; /* ptr to variable definition */
|
||||
@@ -55,17 +55,14 @@ struct db_chan /* DB channel */
|
||||
typedef struct db_chan Chan;
|
||||
|
||||
Expr *expression(), *link_expr();
|
||||
Var *findVar();
|
||||
Chan *findChan();
|
||||
|
||||
/* Linked list definitions to get rid of yucky in-line code */
|
||||
|
||||
/* Linked list allocation definitions */
|
||||
#define allocExpr() (Expr *)malloc(sizeof(Expr));
|
||||
|
||||
#define allocVar() (Var *)malloc(sizeof(Var));
|
||||
#define nextVar(node) (Var *)lstNext( (NODE *)node )
|
||||
#define firstVar(head) (Var *)lstFirst( (LIST *)head )
|
||||
|
||||
#define allocChan() (Chan *)malloc(sizeof(Chan));
|
||||
#define nextChan(node) (Chan *)lstNext( (NODE *)node )
|
||||
#define firstChan(head) (Chan *)lstFirst( (LIST *)head )
|
||||
|
||||
/* Variable types */
|
||||
#define V_NONE 0 /* not defined */
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
Produces code and tables in C output file.
|
||||
See also: gen_ss_code.c
|
||||
ENVIRONMENT: UNIX
|
||||
HISTORY:
|
||||
19nov91,ajk Replaced lstLib calls with built-in linked list.
|
||||
19nov91,ajk Removed extraneous "static" from "UserVar" declaration.
|
||||
***************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -33,7 +36,7 @@ int num_errors = 0; /* number of errors detected in phase 2 processing */
|
||||
*-*************************************************************************/
|
||||
phase2()
|
||||
{
|
||||
extern LIST var_list; /* variables (from parse) */
|
||||
extern Var *var_list; /* variables (from parse) */
|
||||
extern Expr *ss_list; /* state sets (from parse) */
|
||||
extern Expr *global_c_list; /* global C code */
|
||||
|
||||
@@ -147,15 +150,15 @@ Expr *ep;
|
||||
extern char *stype[];
|
||||
extern int warn_flag;
|
||||
|
||||
vp = (Var *)find_var(ep->value);
|
||||
vp = (Var *)findVar(ep->value);
|
||||
if (vp == 0)
|
||||
{ /* variable not declared; enter into variable list */
|
||||
{ /* variable not declared; add it to the variable list */
|
||||
if (warn_flag)
|
||||
fprintf(stderr,
|
||||
"Warning: variable \"%s\" is used but not declared.\n",
|
||||
ep->value);
|
||||
vp = allocVar();
|
||||
lstAdd(&var_list, (NODE *)vp);
|
||||
addVar(vp);
|
||||
vp->name = ep->value;
|
||||
vp->type = V_NONE; /* undeclared type */
|
||||
vp->length = 0;
|
||||
@@ -171,7 +174,6 @@ Expr *ep;
|
||||
/* Reconcile state names */
|
||||
reconcile_states()
|
||||
{
|
||||
extern LIST var_list;
|
||||
extern int num_errors;
|
||||
Expr *ssp, *sp, *sp1, tr;
|
||||
|
||||
@@ -212,7 +214,7 @@ Expr *sp; /* beginning of state list */
|
||||
/* Generate a C variable declaration for each variable declared in SNL */
|
||||
gen_var_decl()
|
||||
{
|
||||
extern LIST var_list;
|
||||
extern Var *var_list;
|
||||
Var *vp;
|
||||
char *vstr;
|
||||
int nv;
|
||||
@@ -222,8 +224,8 @@ gen_var_decl()
|
||||
|
||||
/* Convert internal type to `C' type */
|
||||
if (reent_flag)
|
||||
printf("static struct UserVar {\n");
|
||||
for (nv=0, vp = firstVar(&var_list); vp != NULL; nv++, vp = nextVar(vp))
|
||||
printf("struct UserVar {\n");
|
||||
for (nv=0, vp = var_list; vp != NULL; nv++, vp = vp->next)
|
||||
{
|
||||
switch (vp->type)
|
||||
{
|
||||
@@ -314,12 +316,12 @@ gen_global_c_code()
|
||||
/* Returns number of db channels defined & inserts index into each channel struct */
|
||||
db_chan_count()
|
||||
{
|
||||
extern LIST chan_list;
|
||||
extern Chan *chan_list;
|
||||
int nchan;
|
||||
Chan *cp;
|
||||
|
||||
nchan = 0;
|
||||
for (cp = firstChan(&chan_list); cp != NULL; cp = nextChan(cp))
|
||||
for (cp = chan_list; cp != NULL; cp = cp->next)
|
||||
{
|
||||
if (cp->db_name != NULL)
|
||||
{
|
||||
@@ -338,7 +340,7 @@ db_chan_count()
|
||||
/* Assign bits to event flags and database variables */
|
||||
assign_ef_bits()
|
||||
{
|
||||
extern LIST var_list;
|
||||
extern Var *var_list;
|
||||
Var *vp;
|
||||
Chan *cp;
|
||||
int ef_num;
|
||||
@@ -349,7 +351,7 @@ assign_ef_bits()
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "\nAssign values to event flags\n");
|
||||
#endif
|
||||
for (vp = firstVar(&var_list); vp != NULL; vp = nextVar(vp))
|
||||
for (vp = var_list; vp != NULL; vp = vp->next)
|
||||
{
|
||||
cp = vp->chan;
|
||||
/* First see if this is an event flag */
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
$Id$
|
||||
ENVIRONMENT: UNIX
|
||||
HISTORY:
|
||||
20nov91,ajk Added new "option" statement.
|
||||
***************************************************************************/
|
||||
/* SNC - State Notation Compiler.
|
||||
* The general structure of a state program is:
|
||||
@@ -31,6 +33,11 @@
|
||||
#include <ctype.h>
|
||||
#include "parse.h"
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#endif TRUE
|
||||
|
||||
extern int line_num; /* input file line no. */
|
||||
%}
|
||||
|
||||
@@ -46,7 +53,7 @@ extern int line_num; /* input file line no. */
|
||||
%token <pchar> STATE STATE_SET
|
||||
%token <pchar> NUMBER NAME
|
||||
%token <pchar> DEBUG_PRINT
|
||||
%token PROGRAM EXIT
|
||||
%token PROGRAM EXIT OPTION
|
||||
%token R_SQ_BRACKET L_SQ_BRACKET
|
||||
%token BAD_CHAR L_BRACKET R_BRACKET
|
||||
%token COLON SEMI_COLON EQUAL
|
||||
@@ -103,6 +110,7 @@ defn_stmt /* individual definitions for SNL (preceeds state sets) */
|
||||
| decl_stmt
|
||||
| debug_stmt
|
||||
| sync_stmt
|
||||
| option_stmt
|
||||
| C_STMT { defn_c_stmt($1); }
|
||||
| pp_code
|
||||
| error { snc_err("definitions/declarations"); }
|
||||
@@ -148,6 +156,11 @@ sync_stmt /* sync <variable> <event flag> */
|
||||
| SYNC NAME NAME SEMI_COLON { sync_stmt($2, $3); /* archaic syntax */ }
|
||||
;
|
||||
|
||||
option_stmt /* option +/-<option>; e.g. option +a; */
|
||||
: OPTION PLUS NAME SEMI_COLON { option_stmt($3, TRUE); }
|
||||
| OPTION MINUS NAME SEMI_COLON { option_stmt($3, FALSE); }
|
||||
;
|
||||
|
||||
state_set_list /* a program body is one or more state sets */
|
||||
: state_set { $$ = $1; }
|
||||
| state_set_list state_set { $$ = link_expr($1, $2); }
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
$Id$
|
||||
ENVIRONMENT: UNIX
|
||||
HISTORY:
|
||||
20nov91,ajk Added OPTION token.
|
||||
***************************************************************************/
|
||||
/* Lexical analyzer for State Notation Compiler (snc).
|
||||
*
|
||||
@@ -142,6 +144,7 @@ FPNUM (\-?(([0-9]+)(\.[0-9]*)?)|(\.[0-9]+))
|
||||
<SNL>"string" RETURN(STRING_DECL);
|
||||
<SNL>"to" RETURN(TO);
|
||||
<SNL>"program" RETURN(PROGRAM);
|
||||
<SNL>"option" RETURN(OPTION);
|
||||
<SNL>"debug" RETURN(DEBUG_PRINT);
|
||||
<SNL>"evflag" RETURN(EVFLAG);
|
||||
<SNL>"sync" RETURN(SYNC);
|
||||
|
||||
Reference in New Issue
Block a user