home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.unix
- From: seiwald@vix.com (Christopher Seiwald)
- Subject: v27i085: jam - just another make, Part05/05
- References: <1.753385306.22859@gw.home.vix.com>
- Sender: unix-sources-moderator@gw.home.vix.com
- Approved: vixie@gw.home.vix.com
-
- Submitted-By: seiwald@vix.com (Christopher Seiwald)
- Posting-Number: Volume 27, Issue 85
- Archive-Name: jam/part05
-
- Submitted-by: seiwald@vix.com
- Archive-name: jam - make(1) redux/part05
-
- #!/bin/sh
- # This is part 05 of jam - make(1) redux
- # ============= jamgram.h ==============
- if test -f 'jamgram.h' -a X"$1" != X"-c"; then
- echo 'x - skipping jamgram.h (File already exists)'
- else
- echo 'x - extracting jamgram.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'jamgram.h' &&
- X# define _BANG 257
- X# define _BANG_EQUALS 258
- X# define _AMPERAMPER 259
- X# define _LPAREN 260
- X# define _RPAREN 261
- X# define _COLON 262
- X# define _SEMIC 263
- X# define _LANGLE 264
- X# define _LANGLE_EQUALS 265
- X# define _EQUALS 266
- X# define _RANGLE 267
- X# define _RANGLE_EQUALS 268
- X# define ACTIONS 269
- X# define CASE 270
- X# define DEFAULT 271
- X# define ELSE 272
- X# define FOR 273
- X# define IF 274
- X# define IGNORE 275
- X# define IN 276
- X# define INCLUDE 277
- X# define ON 278
- X# define PIECEMEAL 279
- X# define QUIETLY 280
- X# define RULE 281
- X# define SWITCH 282
- X# define TOGETHER 283
- X# define UPDATED 284
- X# define _LBRACE 285
- X# define _BARBAR 286
- X# define _RBRACE 287
- X# define ARG 288
- X# define STRING 289
- SHAR_EOF
- chmod 0444 jamgram.h ||
- echo 'restore of jamgram.h failed'
- Wc_c="`wc -c < 'jamgram.h'`"
- test 680 -eq "$Wc_c" ||
- echo 'jamgram.h: original size 680, current size' "$Wc_c"
- fi
- # ============= jamgram.y ==============
- if test -f 'jamgram.y' -a X"$1" != X"-c"; then
- echo 'x - skipping jamgram.y (File already exists)'
- else
- echo 'x - extracting jamgram.y (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'jamgram.y' &&
- X%token _BANG
- X%token _BANG_EQUALS
- X%token _AMPERAMPER
- X%token _LPAREN
- X%token _RPAREN
- X%token _COLON
- X%token _SEMIC
- X%token _LANGLE
- X%token _LANGLE_EQUALS
- X%token _EQUALS
- X%token _RANGLE
- X%token _RANGLE_EQUALS
- X%token ACTIONS
- X%token CASE
- X%token DEFAULT
- X%token ELSE
- X%token FOR
- X%token IF
- X%token IGNORE
- X%token IN
- X%token INCLUDE
- X%token ON
- X%token PIECEMEAL
- X%token QUIETLY
- X%token RULE
- X%token SWITCH
- X%token TOGETHER
- X%token UPDATED
- X%token _LBRACE
- X%token _BARBAR
- X%token _RBRACE
- X/*
- X * Copyright 1993 Christopher Seiwald.
- X */
- X
- X/*
- X * jamgram.yy - jam grammar
- X */
- X
- X%token ARG STRING
- X
- X%left _BARBAR
- X%left _AMPERAMPER
- X%left _BANG
- X
- X%{
- X#include "lists.h"
- X#include "parse.h"
- X#include "scan.h"
- X#include "compile.h"
- X#include "newstr.h"
- X
- X# define F0 (void (*)())0
- X# define P0 (PARSE *)0
- X# define L0 (LIST *)0
- X# define S0 (char *)0
- X
- X# define pset( l,r ) parse_make( compile_set,P0,P0,S0,S0,l,r,0 )
- X# define psettings( l,p ) parse_make( compile_settings,p,P0,S0,S0,l,L0,0 )
- X# define pseton( l,r ) parse_make( F0,P0,P0,S0,S0,l,r,0 )
- X# define psetdef( l,r ) parse_make( compile_setdefault,P0,P0,S0,S0,l,r,0 )
- X# define prule( s,l,r ) parse_make( compile_rule,P0,P0,s,S0,l,r,0 )
- X# define prules( l,r ) parse_make( compile_rules,l,r,S0,S0,L0,L0,0 )
- X# define pfor( s,p,l ) parse_make( compile_foreach,p,P0,s,S0,l,L0,0 )
- X# define psetc( s,p ) parse_make( compile_setcomp,p,P0,s,S0,L0,L0,0 )
- X# define psete( s,s1,f ) parse_make( compile_setexec,P0,P0,s,s1,L0,L0,f )
- X# define pincl( l ) parse_make( compile_include,P0,P0,S0,S0,l,L0,0 )
- X# define pswitch( l,p ) parse_make( compile_switch,p,P0,S0,S0,l,L0,0 )
- X# define pcases( l,r ) parse_make( F0,l,r,S0,S0,L0,L0,0 )
- X# define pcase( s,p ) parse_make( F0,p,P0,s,S0,L0,L0,0 )
- X# define pif( l,r ) parse_make( compile_if,l,r,S0,S0,L0,L0,0 )
- X# define pthen( l,r ) parse_make( F0,l,r,S0,S0,L0,L0,0 )
- X# define pcond( c,l,r ) parse_make( F0,l,r,S0,S0,L0,L0,c )
- X# define pcomp( c,l,r ) parse_make( F0,P0,P0,S0,S0,l,r,c )
- X
- X%}
- X
- X%%
- X
- X/*
- X * stmts - the contents of a JAMFILE
- X */
- X
- Xstmts :
- X {
- X compile_builtins();
- X }
- X | stmts rule
- X {
- X (*($2.parse->func))( $2.parse, L0, L0 );
- X parse_free( $2.parse );
- X }
- X ;
- X
- X/*
- X * rules - a strings of rule's together
- X * rule - any one of jam's rules
- X */
- X
- Xrules : /* empty */
- X { $$.parse = prules( P0, P0 ); }
- X | rules rule
- X { $$.parse = prules( $1.parse, $2.parse ); }
- X ;
- X
- Xrule : INCLUDE args _SEMIC
- X { $$.parse = pincl( $2.list ); }
- X | ARG args _SEMIC
- X { $$.parse = prule( $1.string, $2.list, L0 ); }
- X | ARG args _COLON args _SEMIC
- X { $$.parse = prule( $1.string, $2.list, $4.list ); }
- X | arg1 _EQUALS args _SEMIC
- X { $$.parse = pset( $1.list, $3.list ); }
- X | arg1 DEFAULT _EQUALS args _SEMIC
- X { $$.parse = psetdef( $1.list, $4.list ); }
- X | arg1 ON args _EQUALS args _SEMIC
- X { $$.parse = psettings( $3.list, pseton( $1.list, $5.list ) ); }
- X | FOR ARG IN args _LBRACE rules _RBRACE
- X { $$.parse = pfor( $2.string, $6.parse, $4.list ); }
- X | SWITCH args _LBRACE cases _RBRACE
- X { $$.parse = pswitch( $2.list, $4.parse ); }
- X | IF cond _LBRACE rules _RBRACE
- X { $$.parse = pif( $2.parse, pthen( $4.parse, P0 ) ); }
- X | IF cond _LBRACE rules _RBRACE ELSE rule
- X { $$.parse = pif( $2.parse, pthen( $4.parse, $7.parse ) ); }
- X | RULE ARG rule
- X { $$.parse = psetc( $2.string, $3.parse ); }
- X | ACTIONS eflags ARG
- X { scan_asstring = 1; }
- X STRING
- X { $$.parse = psete( $3.string, $5.string, $2.number );
- X scan_asstring = 0; }
- X | _LBRACE rules _RBRACE
- X { $$.parse = $2.parse; }
- X ;
- X
- X/*
- X * cond - a conditional for 'if'
- X */
- X
- Xcond : args
- X { $$.parse = pcomp( COND_EXISTS, $1.list, L0 ); }
- X | args _EQUALS args
- X { $$.parse = pcomp( COND_EQUALS, $1.list, $3.list ); }
- X | args _BANG_EQUALS args
- X { $$.parse = pcomp( COND_NOTEQ, $1.list, $3.list ); }
- X | args _LANGLE args
- X { $$.parse = pcomp( COND_LESS, $1.list, $3.list ); }
- X | args _LANGLE_EQUALS args
- X { $$.parse = pcomp( COND_LESSEQ, $1.list, $3.list ); }
- X | args _RANGLE args
- X { $$.parse = pcomp( COND_MORE, $1.list, $3.list ); }
- X | args _RANGLE_EQUALS args
- X { $$.parse = pcomp( COND_MOREEQ, $1.list, $3.list ); }
- X | _BANG cond
- X { $$.parse = pcond( COND_NOT, $2.parse, P0 ); }
- X | cond _AMPERAMPER cond
- X { $$.parse = pcond( COND_AND, $1.parse, $3.parse ); }
- X | cond _BARBAR cond
- X { $$.parse = pcond( COND_OR, $1.parse, $3.parse ); }
- X | _LPAREN cond _RPAREN
- X { $$.parse = $2.parse; }
- X ;
- X
- X/*
- X * cases - action elements inside a 'switch'
- X * case - a single action element inside a 'switch'
- X *
- X * Unfortunately, a right-recursive rule.
- X */
- X
- Xcases : /* empty */
- X { $$.parse = P0; }
- X | case cases
- X { $$.parse = pcases( $1.parse, $2.parse ); }
- X ;
- X
- Xcase : CASE ARG _COLON rules
- X { $$.parse = pcase( $2.string, $4.parse ); }
- X ;
- X
- X/*
- X * args - zero or more ARGs in a LIST
- X * arg1 - exactly one ARG in a LIST
- X */
- X
- Xargs : /* empty */
- X { $$.list = L0; }
- X | args ARG
- X { $$.list = list_new( $1.list, copystr( $2.string ) ); }
- X ;
- X
- Xarg1 : ARG
- X { $$.list = list_new( L0, copystr( $1.string ) ); }
- X ;
- X
- X/*
- X * eflags - zero or more modifiers to 'executes'
- X * eflag - a single modifier to 'executes'
- X */
- X
- Xeflags : /* empty */
- X { $$.number = 0; }
- X | eflags eflag
- X { $$.number = $1.number | $2.number; }
- X ;
- X
- Xeflag : UPDATED
- X { $$.number = EXEC_UPDATED; }
- X | TOGETHER
- X { $$.number = EXEC_TOGETHER; }
- X | IGNORE
- X { $$.number = EXEC_IGNORE; }
- X | QUIETLY
- X { $$.number = EXEC_QUIETLY; }
- X | PIECEMEAL
- X { $$.number = EXEC_PIECEMEAL; }
- X ;
- X
- SHAR_EOF
- chmod 0444 jamgram.y ||
- echo 'restore of jamgram.y failed'
- Wc_c="`wc -c < 'jamgram.y'`"
- test 5366 -eq "$Wc_c" ||
- echo 'jamgram.y: original size 5366, current size' "$Wc_c"
- fi
- # ============= jamgram.yy ==============
- if test -f 'jamgram.yy' -a X"$1" != X"-c"; then
- echo 'x - skipping jamgram.yy (File already exists)'
- else
- echo 'x - extracting jamgram.yy (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'jamgram.yy' &&
- X/*
- X * Copyright 1993 Christopher Seiwald.
- X */
- X
- X/*
- X * jamgram.yy - jam grammar
- X */
- X
- X%token ARG STRING
- X
- X%left `||`
- X%left `&&`
- X%left `!`
- X
- X%{
- X#include "lists.h"
- X#include "parse.h"
- X#include "scan.h"
- X#include "compile.h"
- X#include "newstr.h"
- X
- X# define F0 (void (*)())0
- X# define P0 (PARSE *)0
- X# define L0 (LIST *)0
- X# define S0 (char *)0
- X
- X# define pset( l,r ) parse_make( compile_set,P0,P0,S0,S0,l,r,0 )
- X# define psettings( l,p ) parse_make( compile_settings,p,P0,S0,S0,l,L0,0 )
- X# define pseton( l,r ) parse_make( F0,P0,P0,S0,S0,l,r,0 )
- X# define psetdef( l,r ) parse_make( compile_setdefault,P0,P0,S0,S0,l,r,0 )
- X# define prule( s,l,r ) parse_make( compile_rule,P0,P0,s,S0,l,r,0 )
- X# define prules( l,r ) parse_make( compile_rules,l,r,S0,S0,L0,L0,0 )
- X# define pfor( s,p,l ) parse_make( compile_foreach,p,P0,s,S0,l,L0,0 )
- X# define psetc( s,p ) parse_make( compile_setcomp,p,P0,s,S0,L0,L0,0 )
- X# define psete( s,s1,f ) parse_make( compile_setexec,P0,P0,s,s1,L0,L0,f )
- X# define pincl( l ) parse_make( compile_include,P0,P0,S0,S0,l,L0,0 )
- X# define pswitch( l,p ) parse_make( compile_switch,p,P0,S0,S0,l,L0,0 )
- X# define pcases( l,r ) parse_make( F0,l,r,S0,S0,L0,L0,0 )
- X# define pcase( s,p ) parse_make( F0,p,P0,s,S0,L0,L0,0 )
- X# define pif( l,r ) parse_make( compile_if,l,r,S0,S0,L0,L0,0 )
- X# define pthen( l,r ) parse_make( F0,l,r,S0,S0,L0,L0,0 )
- X# define pcond( c,l,r ) parse_make( F0,l,r,S0,S0,L0,L0,c )
- X# define pcomp( c,l,r ) parse_make( F0,P0,P0,S0,S0,l,r,c )
- X
- X%}
- X
- X%%
- X
- X/*
- X * stmts - the contents of a JAMFILE
- X */
- X
- Xstmts :
- X {
- X compile_builtins();
- X }
- X | stmts rule
- X {
- X (*($2.parse->func))( $2.parse, L0, L0 );
- X parse_free( $2.parse );
- X }
- X ;
- X
- X/*
- X * rules - a strings of rule's together
- X * rule - any one of jam's rules
- X */
- X
- Xrules : /* empty */
- X { $$.parse = prules( P0, P0 ); }
- X | rules rule
- X { $$.parse = prules( $1.parse, $2.parse ); }
- X ;
- X
- Xrule : `include` args `;`
- X { $$.parse = pincl( $2.list ); }
- X | ARG args `;`
- X { $$.parse = prule( $1.string, $2.list, L0 ); }
- X | ARG args `:` args `;`
- X { $$.parse = prule( $1.string, $2.list, $4.list ); }
- X | arg1 `=` args `;`
- X { $$.parse = pset( $1.list, $3.list ); }
- X | arg1 `default` `=` args `;`
- X { $$.parse = psetdef( $1.list, $4.list ); }
- X | arg1 `on` args `=` args `;`
- X { $$.parse = psettings( $3.list, pseton( $1.list, $5.list ) ); }
- X | `for` ARG `in` args `{` rules `}`
- X { $$.parse = pfor( $2.string, $6.parse, $4.list ); }
- X | `switch` args `{` cases `}`
- X { $$.parse = pswitch( $2.list, $4.parse ); }
- X | `if` cond `{` rules `}`
- X { $$.parse = pif( $2.parse, pthen( $4.parse, P0 ) ); }
- X | `if` cond `{` rules `}` `else` rule
- X { $$.parse = pif( $2.parse, pthen( $4.parse, $7.parse ) ); }
- X | `rule` ARG rule
- X { $$.parse = psetc( $2.string, $3.parse ); }
- X | `actions` eflags ARG
- X { scan_asstring = 1; }
- X STRING
- X { $$.parse = psete( $3.string, $5.string, $2.number );
- X scan_asstring = 0; }
- X | `{` rules `}`
- X { $$.parse = $2.parse; }
- X ;
- X
- X/*
- X * cond - a conditional for 'if'
- X */
- X
- Xcond : args
- X { $$.parse = pcomp( COND_EXISTS, $1.list, L0 ); }
- X | args `=` args
- X { $$.parse = pcomp( COND_EQUALS, $1.list, $3.list ); }
- X | args `!=` args
- X { $$.parse = pcomp( COND_NOTEQ, $1.list, $3.list ); }
- X | args `<` args
- X { $$.parse = pcomp( COND_LESS, $1.list, $3.list ); }
- X | args `<=` args
- X { $$.parse = pcomp( COND_LESSEQ, $1.list, $3.list ); }
- X | args `>` args
- X { $$.parse = pcomp( COND_MORE, $1.list, $3.list ); }
- X | args `>=` args
- X { $$.parse = pcomp( COND_MOREEQ, $1.list, $3.list ); }
- X | `!` cond
- X { $$.parse = pcond( COND_NOT, $2.parse, P0 ); }
- X | cond `&&` cond
- X { $$.parse = pcond( COND_AND, $1.parse, $3.parse ); }
- X | cond `||` cond
- X { $$.parse = pcond( COND_OR, $1.parse, $3.parse ); }
- X | `(` cond `)`
- X { $$.parse = $2.parse; }
- X ;
- X
- X/*
- X * cases - action elements inside a 'switch'
- X * case - a single action element inside a 'switch'
- X *
- X * Unfortunately, a right-recursive rule.
- X */
- X
- Xcases : /* empty */
- X { $$.parse = P0; }
- X | case cases
- X { $$.parse = pcases( $1.parse, $2.parse ); }
- X ;
- X
- Xcase : `case` ARG `:` rules
- X { $$.parse = pcase( $2.string, $4.parse ); }
- X ;
- X
- X/*
- X * args - zero or more ARGs in a LIST
- X * arg1 - exactly one ARG in a LIST
- X */
- X
- Xargs : /* empty */
- X { $$.list = L0; }
- X | args ARG
- X { $$.list = list_new( $1.list, copystr( $2.string ) ); }
- X ;
- X
- Xarg1 : ARG
- X { $$.list = list_new( L0, copystr( $1.string ) ); }
- X ;
- X
- X/*
- X * eflags - zero or more modifiers to 'executes'
- X * eflag - a single modifier to 'executes'
- X */
- X
- Xeflags : /* empty */
- X { $$.number = 0; }
- X | eflags eflag
- X { $$.number = $1.number | $2.number; }
- X ;
- X
- Xeflag : `updated`
- X { $$.number = EXEC_UPDATED; }
- X | `together`
- X { $$.number = EXEC_TOGETHER; }
- X | `ignore`
- X { $$.number = EXEC_IGNORE; }
- X | `quietly`
- X { $$.number = EXEC_QUIETLY; }
- X | `piecemeal`
- X { $$.number = EXEC_PIECEMEAL; }
- X ;
- X
- SHAR_EOF
- chmod 0444 jamgram.yy ||
- echo 'restore of jamgram.yy failed'
- Wc_c="`wc -c < 'jamgram.yy'`"
- test 4795 -eq "$Wc_c" ||
- echo 'jamgram.yy: original size 4795, current size' "$Wc_c"
- fi
- # ============= jamgramtab.h ==============
- if test -f 'jamgramtab.h' -a X"$1" != X"-c"; then
- echo 'x - skipping jamgramtab.h (File already exists)'
- else
- echo 'x - extracting jamgramtab.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'jamgramtab.h' &&
- X { "!", _BANG },
- X { "!=", _BANG_EQUALS },
- X { "&&", _AMPERAMPER },
- X { "(", _LPAREN },
- X { ")", _RPAREN },
- X { ":", _COLON },
- X { ";", _SEMIC },
- X { "<", _LANGLE },
- X { "<=", _LANGLE_EQUALS },
- X { "=", _EQUALS },
- X { ">", _RANGLE },
- X { ">=", _RANGLE_EQUALS },
- X { "actions", ACTIONS },
- X { "case", CASE },
- X { "default", DEFAULT },
- X { "else", ELSE },
- X { "for", FOR },
- X { "if", IF },
- X { "ignore", IGNORE },
- X { "in", IN },
- X { "include", INCLUDE },
- X { "on", ON },
- X { "piecemeal", PIECEMEAL },
- X { "quietly", QUIETLY },
- X { "rule", RULE },
- X { "switch", SWITCH },
- X { "together", TOGETHER },
- X { "updated", UPDATED },
- X { "{", _LBRACE },
- X { "||", _BARBAR },
- X { "}", _RBRACE },
- SHAR_EOF
- chmod 0444 jamgramtab.h ||
- echo 'restore of jamgramtab.h failed'
- Wc_c="`wc -c < 'jamgramtab.h'`"
- test 655 -eq "$Wc_c" ||
- echo 'jamgramtab.h: original size 655, current size' "$Wc_c"
- fi
- # ============= yyacc ==============
- if test -f 'yyacc' -a X"$1" != X"-c"; then
- echo 'x - skipping yyacc (File already exists)'
- else
- echo 'x - extracting yyacc (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'yyacc' &&
- X#!/bin/sh
- X
- X# yyacc - yacc wrapper
- X#
- X# Allows tokens to be written as `literal` and then automatically
- X# substituted with #defined tokens.
- X#
- X# Usage:
- X# yyacc file.yy [ file.y filetab.h ]
- X#
- X# inputs:
- X# file.yy yacc grammar with ` literals
- X#
- X# outputs:
- X# file.y yacc grammar
- X# filetab.h array of string <-> token mappings
- X#
- X# 3-13-93
- X# Documented and p moved in sed command (for some reason,
- X# s/x/y/p doesn't work).
- X# 10-12-93
- X# Take basename as second argument.
- X
- Xin=${1?}
- Xout=`basename $1 .yy`
- Xouty=${2-$out.y}
- Xouth=${3-${out}tab.h}
- X
- XT=/tmp/yy$$
- Xtrap 'rm -f $T.*' 0
- X
- Xsed '
- X : 1
- X /`/{
- X h
- X s/[^`]*`\([^`]*\)`.*/\1/
- X p
- X g
- X s/[^`]*`[^`]*`//
- X b 1
- X }
- X d
- X' $in | sort -u | sed '
- X h
- X y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
- X s/:/_COLON/
- X s/!/_BANG/
- X s/&&/_AMPERAMPER/
- X s/&/_AMPER/
- X s/+/_PLUS/
- X s/||/_BARBAR/
- X s/|/_BAR/
- X s/;/_SEMIC/
- X s/-/_MINUS/
- X s/</_LANGLE/
- X s/>/_RANGLE/
- X s/\./_PERIOD/
- X s/?/_QUESTION/
- X s/=/_EQUALS/
- X s/,/_COMMA/
- X s/\[/_LBRACKET/
- X s/]/_RBRACKET/
- X s/{/_LBRACE/
- X s/}/_RBRACE/
- X s/(/_LPAREN/
- X s/)/_RPAREN/
- X s/FILE/_FILE_/
- X G
- X s/\n/ /
- X' > $T.1
- X
- Xsed '
- X s:^\(.*\) \(.*\)$:s/`\2`/\1/g:
- X s:\.:\\.:g
- X s:\[:\\[:g
- X' $T.1 > $T.s
- X
- Xrm -f $outy $outh
- X
- X(
- X sed 's:^\(.*\) \(.*\)$:%token \1:' $T.1
- X sed -f $T.s $in
- X) > $outy
- X
- X(
- X sed 's:^\(.*\) \(.*\)$: { "\2", \1 },:' $T.1
- X) > $outh
- SHAR_EOF
- chmod 0444 yyacc ||
- echo 'restore of yyacc failed'
- Wc_c="`wc -c < 'yyacc'`"
- test 1301 -eq "$Wc_c" ||
- echo 'yyacc: original size 1301, current size' "$Wc_c"
- fi
- exit 0
-