Commit eb303477 authored by dcw's avatar dcw
Browse files

minor changes;

put casts on all uses of NULL to shut lint up;
expected->error, removed "expected" word from default message,
so all calls to expected (and the macro MUSTBE) have expected
added
parent 65a36dd3
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
* *
******* Grammar for Declarations ******* Grammar for Declarations
* *
* declns = ne-list( decln ) tEOF * declns = list+( decln ) tEOF
* decln = tID tEQ shapes tSEMI * decln = tID tEQ shapes tSEMI
* shapes = ne-sep-list( shape, tOR ) * shapes = sep-list+( shape, tOR )
* shape = tID [ tOPENBR params tCLOSEBR ] printlist * shape = tID [ tOPENBR params tCLOSEBR ] printlist
* params = ne-sep-list( param, tCOMMA ) * params = sep-list+( param, tCOMMA )
* param = tID tID * param = tID tID
* printlist = list( tSTR | tNUM ) * printlist = list( tSTR | tNUM )
*/ */
...@@ -26,35 +26,43 @@ ...@@ -26,35 +26,43 @@
#include "parser.h" #include "parser.h"
/*
/^#ifdef HASPROTOS
!/endif$
stat %
*/
#ifdef HASPROTOS #ifdef HASPROTOS
static void error( char * );
static BOOL parse_decln( char ** , shapelist * ); static BOOL parse_decln( char ** , shapelist * );
static BOOL parse_shapes( shapelist * ); static BOOL parse_shapes( shapelist * );
static BOOL parse_shape( char ** , paramlist *, printlist * ); static BOOL parse_shape( char ** , paramlist * , printlist * );
static BOOL parse_params( paramlist * ); static BOOL parse_params( paramlist * );
static BOOL parse_param( char ** , char ** );
static BOOL parse_printlist( printlist * ); static BOOL parse_printlist( printlist * );
static BOOL parse_printitem( printitem * ); static BOOL parse_printitem( printitem * );
static BOOL parse_param( char ** , char ** );
#else #else
static void error();
static BOOL parse_decln(); static BOOL parse_decln();
static BOOL parse_shapes(); static BOOL parse_shapes();
static BOOL parse_shape(); static BOOL parse_shape();
static BOOL parse_params(); static BOOL parse_params();
static BOOL parse_param();
static BOOL parse_printlist(); static BOOL parse_printlist();
static BOOL parse_printitem(); static BOOL parse_printitem();
static BOOL parse_param();
#endif #endif
/* declns = ne-list( decln ) tEOF */ /* declns = list+( decln ) tEOF */
BOOL parse_declns( dp ) declnlist *dp; BOOL parse_declns( dp ) declnlist *dp;
{ {
char *name; char *name;
shapelist shapes; shapelist shapes;
for(;;) { for(;;) {
if( ! parse_decln( &name, &shapes ) ) return FALSE; if( ! parse_decln( &name, &shapes ) ) return FALSE;
*dp = build_declnlist( name, shapes, NULL ); *dp = build_declnlist( name, shapes, (declnlist) NULL );
if( nexttok() == tEOF ) break; if( nexttok() == tEOF ) break;
ungettok(); ungettok();
dp = &( (*dp)->next ); dp = &( (*dp)->next );
...@@ -63,33 +71,33 @@ BOOL parse_declns( dp ) declnlist *dp; ...@@ -63,33 +71,33 @@ BOOL parse_declns( dp ) declnlist *dp;
} }
static void expected( s ) char *s; static void error( s ) char *s;
{ {
fprintf( stderr, "%s expected at line %d\n", s, lineno ); fprintf( stderr, "%s at line %d\n", s, lineno );
} }
#define MUSTBE(t,mesg) if( nexttok() != (t) ) {expected(mesg); return FALSE;} #define MUSTBE(t,mesg) if( nexttok() != (t) ) {error(mesg); return FALSE;}
/* decln = tID tEQ shapes tSEMI */ /* decln = tID tEQ shapes tSEMI */
static BOOL parse_decln( name, shapes ) char **name; shapelist *shapes; static BOOL parse_decln( name, shapes ) char **name; shapelist *shapes;
{ {
MUSTBE( tID, "declaration" ); MUSTBE( tID, "declaration expected" );
COPYOF( *name, lexidval ); COPYOF( *name, lexidval );
MUSTBE( tEQ, "'='" ); MUSTBE( tEQ, "'=' expected" );
if( ! parse_shapes( shapes ) ) return FALSE; if( ! parse_shapes( shapes ) ) return FALSE;
MUSTBE( tSEMI, "';'" ); MUSTBE( tSEMI, "';' expected" );
return TRUE; return TRUE;
} }
/* shapes = ne-sep-list( shape, tOR ) */ /* shapes = sep-list+( shape, tOR ) */
static BOOL parse_shapes( sp ) shapelist *sp; static BOOL parse_shapes( sp ) shapelist *sp;
{ {
...@@ -97,9 +105,10 @@ static BOOL parse_shapes( sp ) shapelist *sp; ...@@ -97,9 +105,10 @@ static BOOL parse_shapes( sp ) shapelist *sp;
paramlist paras; paramlist paras;
printlist print; printlist print;
for(;;) { for(;;) {
if( ! parse_shape( &tagname, &paras, &print ) ) return FALSE; if( ! parse_shape( &tagname, &paras, &print ) ) return FALSE;
*sp = build_shapelist( tagname, paras, print, NULL ); *sp = build_shapelist( tagname, paras,
print, (shapelist) NULL );
if( nexttok() != tOR ) break; if( nexttok() != tOR ) break;
sp = &( (*sp)->next ); sp = &( (*sp)->next );
} }
...@@ -112,17 +121,17 @@ static BOOL parse_shapes( sp ) shapelist *sp; ...@@ -112,17 +121,17 @@ static BOOL parse_shapes( sp ) shapelist *sp;
static BOOL parse_shape( tagname, pl, print ) char **tagname; paramlist *pl; printlist *print; static BOOL parse_shape( tagname, pl, print ) char **tagname; paramlist *pl; printlist *print;
{ {
*pl = NULL; *pl = (paramlist) NULL;
*print = NULL; *print = (printlist) NULL;
MUSTBE( tID, "shape name" ); MUSTBE( tID, "shape name expected" );
COPYOF( *tagname, lexidval ); COPYOF( *tagname, lexidval );
if( nexttok() == tOPENBR ) if( nexttok() == tOPENBR )
{ {
if( ! parse_params( pl ) ) return FALSE; if( ! parse_params( pl ) ) return FALSE;
MUSTBE( tCLOSEBR, "')'" ); MUSTBE( tCLOSEBR, "')' expected" );
} else } else
{ {
ungettok(); ungettok();
...@@ -132,20 +141,20 @@ static BOOL parse_shape( tagname, pl, print ) char **tagname; paramlist *pl; pri ...@@ -132,20 +141,20 @@ static BOOL parse_shape( tagname, pl, print ) char **tagname; paramlist *pl; pri
} }
/* params = ne-sep-list( param, tCOMMA ) */ /* params = sep-list+( param, tCOMMA ) */
static BOOL parse_params( pp ) paramlist *pp; static BOOL parse_params( pp ) paramlist *pp;
{ {
char *type; char *type;
char *name; char *name;
for(;;) { for(;;) {
if( !parse_param( &type, &name ) ) return FALSE; if( !parse_param( &type, &name ) ) return FALSE;
*pp = build_paramlist( type, name, NULL ); *pp = build_paramlist( type, name, (paramlist) NULL );
if( nexttok() != tCOMMA ) break; if( nexttok() != tCOMMA ) break;
pp = &( (*pp)->next ); pp = &( (*pp)->next );
} }
ungettok(); ungettok();
return TRUE; return TRUE;
} }
...@@ -157,12 +166,12 @@ static BOOL parse_printlist( pp ) printlist *pp; ...@@ -157,12 +166,12 @@ static BOOL parse_printlist( pp ) printlist *pp;
{ {
printitem item; printitem item;
*pp = NULL; *pp = (printlist) NULL;
while( parse_printitem( &item ) ) while( parse_printitem( &item ) )
{ {
*pp = build_printlist( item, NULL ); *pp = build_printlist( item, (printlist) NULL );
pp = &( (*pp)->next ); pp = &( (*pp)->next );
} }
return TRUE; return TRUE;
} }
...@@ -193,10 +202,10 @@ static BOOL parse_printitem( item ) printitem *item; ...@@ -193,10 +202,10 @@ static BOOL parse_printitem( item ) printitem *item;
static BOOL parse_param( type, name ) char **type, **name; static BOOL parse_param( type, name ) char **type, **name;
{ {
MUSTBE( tID, "Field type" ); MUSTBE( tID, "Field type expected" );
COPYOF( *type, lexidval ); COPYOF( *type, lexidval );
MUSTBE( tID, "Field name" ); MUSTBE( tID, "Field name expected" );
COPYOF( *name, lexidval ); COPYOF( *name, lexidval );
return TRUE; return TRUE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment