summaryrefslogtreecommitdiff
path: root/web/spiderweb/fixes-to-be-applied/dnn.web
blob: a9c4d033cd0ed6b8749a2ec1c9422e8b4d9f6404 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
%<$DNN GRAMMAR Condenser - Ver DN-1A(2) - [PQN-OTFA]$>
% Copyright 1989--1990 by David Ness
% Not to be sold, but may be used freely for any purpose or for any purposes of
% Norman Ramsey

\let\RA\rightarrow

\def\vert{{\tt\char'174}}
\def\pb{$\.|\ldots\.|$} % C brackets (|...|)

\def\title{DNN GRAMMAR Condenser}

\def\topofcontents{\null\vfill
  \titlefalse % include headline on the contents page
  \def\rheader{\hfil}
  \centerline{\titlefont The {\ttitlefont DNN GRAMMAR} Condenser}
  \vfill}


\def\syntax##1{\leavevmode\hbox{$\langle\hbox{\sl ##1\/}\rangle$}}
\def\produces{\leavevmode\hbox{${}::={}$}}
\def\opt##1{$[$##1$]$}

#*=The {\tt SPIDER} grammar condenser.
#*Introduction.
This is an \.{AWK} program designed to read a description of a grammar and to
produce calls on |squash| instead of |reduce| where it can.

This might not look very important, but the grammar of {\tt C} is such that
MicroSoft C 5.1 can't handle the \.{WEB} for \.{WEAVE} because the |translate|
function turns out to be too large. By good luck, the condensation done here
manages to (just) avoid that!

The philosophy here is very simple. We are only `interested' in lines
which begin with |app1| or |reduce|. When they begin with |app1(pp+n...| we
table |n| in the array |data| and don't generate anything. When they begin
with |reduce| we check
and see if the |reduce| is consistent with the |app1|s. If so then we just
generate one |squash| for the whole mess.

In all other cases (an inconsistent |reduce| or neither an |app1| or
|reduce|) we generate all of the lines (if there were any) that got swallowed
into the |data| array.

#d banner = "DNN GRAMMAR.WEB Condenser -> OUT.TMP Ver DN-1A(2)"
#u#1
BEGIN {
#<Say Hello#>
#<Set initial values#>
}
#@
#<Define Functions#>
#<Pattern-action statements#>
#@
END {
#<Do final things#>
}


# #<Set init...#>=
out = "out.tmp"
Base = 0

# |dumparray()| dumps any |app1(pp+...)|'s that have been accumulated so far.
It is called when we get anything other than a |reduce| or |app1|, or if we
get a |reduce| but it isn't {\it the right stuff!}
#<Define Functions#>=
function dumparray()
{
    if (Base != 0)
    {
	for (i = 0; i < Base; ++i) print "\tapp1(pp+" data[i] ");" >out
	delete data
	Base = 0
    }
    print $0 >out
    return
}

# If we have an |app1(pp+n)| enter |n| into the table and keep going
#<Pattern-action statements#>=
#=/app1\(pp\+/#> {
match($0,"app1\\(pp\\+.*\\)")
val = substr($0,RSTART+8,RLENGTH-9)
data[Base++] = val
}

# If we hit a |reduce(...)|, see if we should process it.
#<Pattern-action statements#>=
#=/reduce/#> {
	match($0,"reduce\\(pp\\+[0-9]*\\,")
	val = substr($0,RSTART+10,RLENGTH-11)
	if (data[0] == val)
	       #<|reduce| starts where first |app1| started#>#;
	else {dumparray()}
}

# #<|reduce| starts where first |app1| started#>=
{
	match($0,",[0-9]+,")
	val = substr($0,RSTART+1,RLENGTH-2)
	if (val == (1+data[Base-1]-data[0]))
		#<|reduce| condenses right number of elements#>#;
	else {dumparray()}
}

# #<|reduce| condenses right number of elements#>=
{
	match($0,"\\(.*\\);")
	print "\tsquash" substr($0,RSTART,RLENGTH) >out
	delete data
	Base = 0
}

# When we encounter an `uninteresting' statement, dump anything that we might
have accumulated.
#<Pattern-action statements#>=
#=$0 !~ /app1|reduce/#> {dumparray()}

# #<Say Hello#>=print banner

# #<Do final...#>=

#*=Index.