Commit 9eeb62bc authored by dcw's avatar dcw

major change;

grammar revised, EXPORT and GLOBAL sections added,
types surrounded by TYPE { .. } brackets
caused changes to upper parse procs
parent aabc48c5
......@@ -10,7 +10,11 @@
*
******* Grammar for Declarations
*
* declns = list+( decln ) tEOF
* data = [ tEXPORT chunk ]
* [ tGLOBAL chunk ]
* tTYPE tOPENCURLY declns tCLOSECURLY
* chunk = tOPENCURLY list_of_lines tCLOSECURLY
* declns = list*( decln ) tEOF
* decln = tID tEQ shapes tSEMI
* shapes = sep-list+( shape, tOR )
* shape = tID [ tOPENBR params tCLOSEBR ] printlist
......@@ -32,7 +36,10 @@
stat %
*/
#ifdef HASPROTOS
static BOOL parse_chunk( char * );
static BOOL parse_declns( declnlist * );
static void error( char * );
static BOOL parse_decln( char ** , shapelist * );
static BOOL parse_shapes( shapelist * );
......@@ -42,6 +49,8 @@ static BOOL parse_printlist( printlist * );
static BOOL parse_printitem( printitem * );
static BOOL parse_param( char ** , char ** );
#else
static BOOL parse_chunk();
static BOOL parse_declns();
static void error();
static BOOL parse_decln();
static BOOL parse_shapes();
......@@ -56,20 +65,86 @@ static BOOL parse_param();
#define MUSTBE(t,mesg) if( nexttok() != (t) ) {error(mesg); return FALSE;}
/* declns = list+( decln ) tEOF */
/*
* data = [ tEXPORT tOPENCURLY crap_to_} ]
* [ tGLOBAL tOPENCURLY crap_to_} ]
* tTYPE tOPENCURLY declns tCLOSECURLY
*/
BOOL parse_declns( dp ) declnlist *dp;
BOOL parse_data( exports, globals, dp ) char *exports, *globals; declnlist *dp;
{
if( nexttok() == tEXPORT )
{
if( ! parse_chunk( exports ) ) return FALSE;
} else
{
*exports = '\0';
ungettok();
}
if( nexttok() == tGLOBAL )
{
if( ! parse_chunk( globals ) ) return FALSE;
} else
{
*globals = '\0';
ungettok();
}
MUSTBE( tTYPE, "TYPE/EXPORT/GLOBAL expected" );
MUSTBE( tOPENCURLY, "{ expected" );
if( ! parse_declns( dp ) ) return FALSE;
MUSTBE( tCLOSECURLY, "{ expected" );
MUSTBE( tEOF, "Spurious characters found beyond EOF" );
return TRUE;
}
/* chunk = tOPENCURLY list_of_lines tCLOSECURLY */
static BOOL parse_chunk( s ) char *s;
{
char line[256];
int startlineno;
*s = '\0';
MUSTBE( tOPENCURLY, "'{' expected" );
startlineno = lineno;
for(;;)
{
if( ! readnextline( line ) )
{
fprintf( stderr,
"Premature EOF after { - started at line %d\n",
startlineno );
return FALSE;
}
if( streq( line, "}" ) ) break;
strcat( s, line );
strcat( s, "\n" );
}
return TRUE;
}
/* declns = list*( decln ) */
/* NB: a decln starts with a tID */
static BOOL parse_declns( dp ) declnlist *dp;
{
char *name;
shapelist shapes;
for(;;) {
while( nexttok() == tID )
{
ungettok();
if( ! parse_decln( &name, &shapes ) ) return FALSE;
*dp = build_declnlist( name, shapes, (declnlist) NULL );
if( nexttok() == tEOF ) break;
ungettok();
dp = &( (*dp)->next );
}
ungettok();
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