Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
86bea46b
Kaydet (Commit)
86bea46b
authored
Nis 29, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Another directory quickly renamed.
üst
2b713b2f
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
218 additions
and
205 deletions
+218
-205
acceler.c
Parser/acceler.c
+7
-7
bitset.c
Parser/bitset.c
+3
-3
firstsets.c
Parser/firstsets.c
+13
-11
grammar.c
Parser/grammar.c
+27
-25
grammar1.c
Parser/grammar1.c
+4
-4
intrcheck.c
Parser/intrcheck.c
+12
-12
listnode.c
Parser/listnode.c
+3
-3
metagrammar.c
Parser/metagrammar.c
+2
-2
node.c
Parser/node.c
+9
-9
parser.c
Parser/parser.c
+29
-28
parser.h
Parser/parser.h
+5
-4
parsetok.c
Parser/parsetok.c
+12
-11
pgen.c
Parser/pgen.c
+36
-33
pgen.h
Parser/pgen.h
+2
-2
pgenmain.c
Parser/pgenmain.c
+18
-18
printgrammar.c
Parser/printgrammar.c
+4
-4
tokenizer.c
Parser/tokenizer.c
+27
-25
tokenizer.h
Parser/tokenizer.h
+5
-4
No files found.
Parser/acceler.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -47,11 +47,11 @@ PERFORMANCE OF THIS SOFTWARE.
#include "parser.h"
/* Forward references */
static
void
fixdfa
PROTO
((
grammar
*
,
dfa
*
));
static
void
fixstate
PROTO
((
grammar
*
,
state
*
));
static
void
fixdfa
P
y_P
ROTO
((
grammar
*
,
dfa
*
));
static
void
fixstate
P
y_P
ROTO
((
grammar
*
,
state
*
));
void
adda
ccelerators
(
g
)
PyGrammar_AddA
ccelerators
(
g
)
grammar
*
g
;
{
dfa
*
d
;
...
...
@@ -90,7 +90,7 @@ fixstate(g, s)
int
*
accel
;
int
nl
=
g
->
g_ll
.
ll_nlabels
;
s
->
s_accept
=
0
;
accel
=
NEW
(
int
,
nl
);
accel
=
PyMem_
NEW
(
int
,
nl
);
for
(
k
=
0
;
k
<
nl
;
k
++
)
accel
[
k
]
=
-
1
;
a
=
s
->
s_arc
;
...
...
@@ -103,7 +103,7 @@ fixstate(g, s)
continue
;
}
if
(
ISNONTERMINAL
(
type
))
{
dfa
*
d1
=
finddfa
(
g
,
type
);
dfa
*
d1
=
PyGrammar_FindDFA
(
g
,
type
);
int
ibit
;
if
(
type
-
NT_OFFSET
>=
(
1
<<
7
))
{
printf
(
"XXX too high nonterminal number!
\n
"
);
...
...
@@ -146,7 +146,7 @@ fixstate(g, s)
k
++
;
if
(
k
<
nl
)
{
int
i
;
s
->
s_accel
=
NEW
(
int
,
nl
-
k
);
s
->
s_accel
=
PyMem_
NEW
(
int
,
nl
-
k
);
if
(
s
->
s_accel
==
NULL
)
{
fprintf
(
stderr
,
"no mem to add parser accelerators
\n
"
);
exit
(
1
);
...
...
@@ -156,5 +156,5 @@ fixstate(g, s)
for
(
i
=
0
;
k
<
nl
;
i
++
,
k
++
)
s
->
s_accel
[
i
]
=
accel
[
k
];
}
DEL
(
accel
);
PyMem_
DEL
(
accel
);
}
Parser/bitset.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -39,10 +39,10 @@ newbitset(nbits)
int
nbits
;
{
int
nbytes
=
NBYTES
(
nbits
);
bitset
ss
=
NEW
(
BYTE
,
nbytes
);
bitset
ss
=
PyMem_
NEW
(
BYTE
,
nbytes
);
if
(
ss
==
NULL
)
fatal
(
"no mem for bitset"
);
Py_FatalError
(
"no mem for bitset"
);
ss
+=
nbytes
;
while
(
--
nbytes
>=
0
)
...
...
@@ -54,7 +54,7 @@ void
delbitset
(
ss
)
bitset
ss
;
{
DEL
(
ss
);
PyMem_
DEL
(
ss
);
}
int
...
...
Parser/firstsets.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -35,10 +35,10 @@ PERFORMANCE OF THIS SOFTWARE.
#include "grammar.h"
#include "token.h"
extern
int
debuggin
g
;
extern
int
Py_DebugFla
g
;
/* Forward */
static
void
calcfirstset
PROTO
((
grammar
*
,
dfa
*
));
static
void
calcfirstset
P
y_P
ROTO
((
grammar
*
,
dfa
*
));
void
addfirstsets
(
g
)
...
...
@@ -72,7 +72,7 @@ calcfirstset(g, d)
dfa
*
d1
;
label
*
l0
;
if
(
debuggin
g
)
if
(
Py_DebugFla
g
)
printf
(
"Calculate FIRST set for '%s'
\n
"
,
d
->
d_name
);
if
(
dummy
==
NULL
)
...
...
@@ -91,9 +91,9 @@ calcfirstset(g, d)
nbits
=
g
->
g_ll
.
ll_nlabels
;
result
=
newbitset
(
nbits
);
sym
=
NEW
(
int
,
1
);
sym
=
PyMem_
NEW
(
int
,
1
);
if
(
sym
==
NULL
)
fatal
(
"no mem for new sym in calcfirstset"
);
Py_FatalError
(
"no mem for new sym in calcfirstset"
);
nsyms
=
1
;
sym
[
0
]
=
findlabel
(
&
g
->
g_ll
,
d
->
d_type
,
(
char
*
)
NULL
);
...
...
@@ -105,13 +105,14 @@ calcfirstset(g, d)
break
;
}
if
(
j
>=
nsyms
)
{
/* New label */
RESIZE
(
sym
,
int
,
nsyms
+
1
);
PyMem_
RESIZE
(
sym
,
int
,
nsyms
+
1
);
if
(
sym
==
NULL
)
fatal
(
"no mem to resize sym in calcfirstset"
);
Py_FatalError
(
"no mem to resize sym in calcfirstset"
);
sym
[
nsyms
++
]
=
a
->
a_lbl
;
type
=
l0
[
a
->
a_lbl
].
lb_type
;
if
(
ISNONTERMINAL
(
type
))
{
d1
=
finddfa
(
g
,
type
);
d1
=
PyGrammar_FindDFA
(
g
,
type
);
if
(
d1
->
d_first
==
dummy
)
{
fprintf
(
stderr
,
"Left-recursion below '%s'
\n
"
,
...
...
@@ -120,7 +121,8 @@ calcfirstset(g, d)
else
{
if
(
d1
->
d_first
==
NULL
)
calcfirstset
(
g
,
d1
);
mergebitset
(
result
,
d1
->
d_first
,
nbits
);
mergebitset
(
result
,
d1
->
d_first
,
nbits
);
}
}
else
if
(
ISTERMINAL
(
type
))
{
...
...
@@ -129,11 +131,11 @@ calcfirstset(g, d)
}
}
d
->
d_first
=
result
;
if
(
debuggin
g
)
{
if
(
Py_DebugFla
g
)
{
printf
(
"FIRST set for '%s': {"
,
d
->
d_name
);
for
(
i
=
0
;
i
<
nbits
;
i
++
)
{
if
(
testbit
(
result
,
i
))
printf
(
" %s"
,
labelr
epr
(
&
l0
[
i
]));
printf
(
" %s"
,
PyGrammar_LabelR
epr
(
&
l0
[
i
]));
}
printf
(
" }
\n
"
);
}
...
...
Parser/grammar.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -39,7 +39,7 @@ PERFORMANCE OF THIS SOFTWARE.
#include "token.h"
#include "grammar.h"
extern
int
debuggin
g
;
extern
int
Py_DebugFla
g
;
grammar
*
newgrammar
(
start
)
...
...
@@ -47,9 +47,9 @@ newgrammar(start)
{
grammar
*
g
;
g
=
NEW
(
grammar
,
1
);
g
=
PyMem_
NEW
(
grammar
,
1
);
if
(
g
==
NULL
)
fatal
(
"no mem for new grammar"
);
Py_FatalError
(
"no mem for new grammar"
);
g
->
g_ndfas
=
0
;
g
->
g_dfa
=
NULL
;
g
->
g_start
=
start
;
...
...
@@ -67,9 +67,9 @@ adddfa(g, type, name)
{
dfa
*
d
;
RESIZE
(
g
->
g_dfa
,
dfa
,
g
->
g_ndfas
+
1
);
PyMem_
RESIZE
(
g
->
g_dfa
,
dfa
,
g
->
g_ndfas
+
1
);
if
(
g
->
g_dfa
==
NULL
)
fatal
(
"no mem to resize dfa in adddfa"
);
Py_FatalError
(
"no mem to resize dfa in adddfa"
);
d
=
&
g
->
g_dfa
[
g
->
g_ndfas
++
];
d
->
d_type
=
type
;
d
->
d_name
=
name
;
...
...
@@ -86,9 +86,9 @@ addstate(d)
{
state
*
s
;
RESIZE
(
d
->
d_state
,
state
,
d
->
d_nstates
+
1
);
PyMem_
RESIZE
(
d
->
d_state
,
state
,
d
->
d_nstates
+
1
);
if
(
d
->
d_state
==
NULL
)
fatal
(
"no mem to resize state in addstate"
);
Py_FatalError
(
"no mem to resize state in addstate"
);
s
=
&
d
->
d_state
[
d
->
d_nstates
++
];
s
->
s_narcs
=
0
;
s
->
s_arc
=
NULL
;
...
...
@@ -111,9 +111,9 @@ addarc(d, from, to, lbl)
assert
(
0
<=
to
&&
to
<
d
->
d_nstates
);
s
=
&
d
->
d_state
[
from
];
RESIZE
(
s
->
s_arc
,
arc
,
s
->
s_narcs
+
1
);
PyMem_
RESIZE
(
s
->
s_arc
,
arc
,
s
->
s_narcs
+
1
);
if
(
s
->
s_arc
==
NULL
)
fatal
(
"no mem to resize arc list in addarc"
);
Py_FatalError
(
"no mem to resize arc list in addarc"
);
a
=
&
s
->
s_arc
[
s
->
s_narcs
++
];
a
->
a_lbl
=
lbl
;
a
->
a_arrow
=
to
;
...
...
@@ -133,9 +133,9 @@ addlabel(ll, type, str)
strcmp
(
ll
->
ll_label
[
i
].
lb_str
,
str
)
==
0
)
return
i
;
}
RESIZE
(
ll
->
ll_label
,
label
,
ll
->
ll_nlabels
+
1
);
PyMem_
RESIZE
(
ll
->
ll_label
,
label
,
ll
->
ll_nlabels
+
1
);
if
(
ll
->
ll_label
==
NULL
)
fatal
(
"no mem to resize labellist in addlabel"
);
Py_FatalError
(
"no mem to resize labellist in addlabel"
);
lb
=
&
ll
->
ll_label
[
ll
->
ll_nlabels
++
];
lb
->
lb_type
=
type
;
lb
->
lb_str
=
str
;
/* XXX strdup(str) ??? */
...
...
@@ -158,12 +158,12 @@ findlabel(ll, type, str)
return
i
;
}
fprintf
(
stderr
,
"Label %d/'%s' not found
\n
"
,
type
,
str
);
fatal
(
"grammar.c:findlabel()"
);
Py_FatalError
(
"grammar.c:findlabel()"
);
return
0
;
/* Make gcc -Wall happy */
}
/* Forward */
static
void
translabel
PROTO
((
grammar
*
,
label
*
));
static
void
translabel
P
y_P
ROTO
((
grammar
*
,
label
*
));
void
translatelabels
(
g
)
...
...
@@ -186,24 +186,25 @@ translabel(g, lb)
{
int
i
;
if
(
debuggin
g
)
printf
(
"Translating label %s ...
\n
"
,
labelr
epr
(
lb
));
if
(
Py_DebugFla
g
)
printf
(
"Translating label %s ...
\n
"
,
PyGrammar_LabelR
epr
(
lb
));
if
(
lb
->
lb_type
==
NAME
)
{
for
(
i
=
0
;
i
<
g
->
g_ndfas
;
i
++
)
{
if
(
strcmp
(
lb
->
lb_str
,
g
->
g_dfa
[
i
].
d_name
)
==
0
)
{
if
(
debugging
)
printf
(
"Label %s is non-terminal %d.
\n
"
,
lb
->
lb_str
,
g
->
g_dfa
[
i
].
d_type
);
if
(
Py_DebugFlag
)
printf
(
"Label %s is non-terminal %d.
\n
"
,
lb
->
lb_str
,
g
->
g_dfa
[
i
].
d_type
);
lb
->
lb_type
=
g
->
g_dfa
[
i
].
d_type
;
lb
->
lb_str
=
NULL
;
return
;
}
}
for
(
i
=
0
;
i
<
(
int
)
N_TOKENS
;
i
++
)
{
if
(
strcmp
(
lb
->
lb_str
,
tok_name
[
i
])
==
0
)
{
if
(
debuggin
g
)
if
(
strcmp
(
lb
->
lb_str
,
_PyParser_TokenNames
[
i
])
==
0
)
{
if
(
Py_DebugFla
g
)
printf
(
"Label %s is terminal %d.
\n
"
,
lb
->
lb_str
,
i
);
lb
->
lb_type
=
i
;
...
...
@@ -218,7 +219,7 @@ translabel(g, lb)
if
(
lb
->
lb_type
==
STRING
)
{
if
(
isalpha
(
lb
->
lb_str
[
1
])
||
lb
->
lb_str
[
1
]
==
'_'
)
{
char
*
p
;
if
(
debuggin
g
)
if
(
Py_DebugFla
g
)
printf
(
"Label %s is a keyword
\n
"
,
lb
->
lb_str
);
lb
->
lb_type
=
NAME
;
lb
->
lb_str
++
;
...
...
@@ -227,7 +228,7 @@ translabel(g, lb)
*
p
=
'\0'
;
}
else
if
(
lb
->
lb_str
[
2
]
==
lb
->
lb_str
[
0
])
{
int
type
=
(
int
)
tok_1c
har
(
lb
->
lb_str
[
1
]);
int
type
=
(
int
)
PyToken_OneC
har
(
lb
->
lb_str
[
1
]);
if
(
type
!=
OP
)
{
lb
->
lb_type
=
type
;
lb
->
lb_str
=
NULL
;
...
...
@@ -237,7 +238,7 @@ translabel(g, lb)
lb
->
lb_str
);
}
else
if
(
lb
->
lb_str
[
2
]
&&
lb
->
lb_str
[
3
]
==
lb
->
lb_str
[
0
])
{
int
type
=
(
int
)
tok_2char
(
lb
->
lb_str
[
1
],
int
type
=
(
int
)
PyToken_TwoChars
(
lb
->
lb_str
[
1
],
lb
->
lb_str
[
2
]);
if
(
type
!=
OP
)
{
lb
->
lb_type
=
type
;
...
...
@@ -252,5 +253,6 @@ translabel(g, lb)
lb
->
lb_str
);
}
else
printf
(
"Can't translate label '%s'
\n
"
,
labelrepr
(
lb
));
printf
(
"Can't translate label '%s'
\n
"
,
PyGrammar_LabelRepr
(
lb
));
}
Parser/grammar1.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -39,7 +39,7 @@ PERFORMANCE OF THIS SOFTWARE.
/* Return the DFA for the given type */
dfa
*
finddfa
(
g
,
type
)
PyGrammar_FindDFA
(
g
,
type
)
grammar
*
g
;
register
int
type
;
{
...
...
@@ -63,7 +63,7 @@ finddfa(g, type)
}
char
*
labelr
epr
(
lb
)
PyGrammar_LabelR
epr
(
lb
)
label
*
lb
;
{
static
char
buf
[
100
];
...
...
@@ -80,10 +80,10 @@ labelrepr(lb)
}
else
{
if
(
lb
->
lb_str
==
NULL
)
return
tok_name
[
lb
->
lb_type
];
return
_PyParser_TokenNames
[
lb
->
lb_type
];
else
{
sprintf
(
buf
,
"%.32s(%.32s)"
,
tok_name
[
lb
->
lb_type
],
lb
->
lb_str
);
_PyParser_TokenNames
[
lb
->
lb_type
],
lb
->
lb_str
);
return
buf
;
}
}
...
...
Parser/intrcheck.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -45,12 +45,12 @@ int Py_AddPendingCall Py_PROTO((int (*func) Py_PROTO((ANY *)), ANY *arg));
#include <io.h>
void
initintr
()
PyOS_InitInterrupts
()
{
}
int
intrcheck
()
PyOS_InterruptOccurred
()
{
_wyield
();
}
...
...
@@ -76,13 +76,13 @@ intrcheck()
#include <go32.h>
void
initintr
()
PyOS_InitInterrupts
()
{
_go32_want_ctrl_break
(
1
/* TRUE */
);
}
int
intrcheck
()
PyOS_InterruptOccurred
()
{
return
_go32_was_ctrl_break_hit
();
}
...
...
@@ -92,12 +92,12 @@ intrcheck()
/* This might work for MS-DOS (untested though): */
void
initintr
()
PyOS_InitInterrupts
()
{
}
int
intrcheck
()
PyOS_InterruptOccurred
()
{
int
interrupted
=
0
;
while
(
kbhit
())
{
...
...
@@ -141,7 +141,7 @@ PyErr_SetInterrupt()
interrupted
=
1
;
}
extern
int
sigcheck
();
extern
int
PyErr_CheckSignals
();
/* ARGSUSED */
static
RETSIGTYPE
...
...
@@ -152,7 +152,7 @@ intcatcher(sig)
int
sig
;
/* Not used by required by interface */
#endif
/* _M_IX86 */
{
extern
void
goaway
PROTO
((
int
));
extern
void
Py_Exit
Py_
PROTO
((
int
));
static
char
message
[]
=
"python: to interrupt a truly hanging Python program, interrupt once more.
\n
"
;
switch
(
interrupted
++
)
{
...
...
@@ -163,15 +163,15 @@ intcatcher(sig)
break
;
case
2
:
interrupted
=
0
;
goaway
(
1
);
Py_Exit
(
1
);
break
;
}
signal
(
SIGINT
,
intcatcher
);
Py_AddPendingCall
(
sigcheck
,
NULL
);
Py_AddPendingCall
(
PyErr_CheckSignals
,
NULL
);
}
void
initintr
()
PyOS_InitInterrupts
()
{
if
(
signal
(
SIGINT
,
SIG_IGN
)
!=
SIG_IGN
)
signal
(
SIGINT
,
intcatcher
);
...
...
@@ -187,7 +187,7 @@ initintr()
}
int
intrcheck
()
PyOS_InterruptOccurred
()
{
if
(
!
interrupted
)
return
0
;
...
...
Parser/listnode.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -36,11 +36,11 @@ PERFORMANCE OF THIS SOFTWARE.
#include "node.h"
/* Forward */
static
void
list1node
PROTO
((
FILE
*
,
node
*
));
static
void
listnode
PROTO
((
FILE
*
,
node
*
));
static
void
list1node
P
y_P
ROTO
((
FILE
*
,
node
*
));
static
void
listnode
P
y_P
ROTO
((
FILE
*
,
node
*
));
void
listt
ree
(
n
)
PyNode_ListT
ree
(
n
)
node
*
n
;
{
listnode
(
stdout
,
n
);
...
...
Parser/metagrammar.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -169,7 +169,7 @@ static label labels[19] = {
{
7
,
0
},
{
8
,
0
},
};
static
grammar
gram
=
{
static
grammar
_PyParser_Grammar
=
{
6
,
dfas
,
{
19
,
labels
},
...
...
@@ -179,5 +179,5 @@ static grammar gram = {
grammar
*
meta_grammar
()
{
return
&
gram
;
return
&
_PyParser_Grammar
;
}
Parser/node.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -35,10 +35,10 @@ PERFORMANCE OF THIS SOFTWARE.
#include "node.h"
node
*
newtree
(
type
)
PyNode_New
(
type
)
int
type
;
{
node
*
n
=
NEW
(
node
,
1
);
node
*
n
=
PyMem_
NEW
(
node
,
1
);
if
(
n
==
NULL
)
return
NULL
;
n
->
n_type
=
type
;
...
...
@@ -53,7 +53,7 @@ newtree(type)
#define XXXROUNDUP(n) ((n) == 1 ? 1 : ((n) + XXX - 1) / XXX * XXX)
node
*
addc
hild
(
n1
,
type
,
str
,
lineno
)
PyNode_AddC
hild
(
n1
,
type
,
str
,
lineno
)
register
node
*
n1
;
int
type
;
char
*
str
;
...
...
@@ -65,7 +65,7 @@ addchild(n1, type, str, lineno)
if
(
XXXROUNDUP
(
nch
)
<
nch1
)
{
n
=
n1
->
n_child
;
nch1
=
XXXROUNDUP
(
nch1
);
RESIZE
(
n
,
node
,
nch1
);
PyMem_
RESIZE
(
n
,
node
,
nch1
);
if
(
n
==
NULL
)
return
NULL
;
n1
->
n_child
=
n
;
...
...
@@ -80,16 +80,16 @@ addchild(n1, type, str, lineno)
}
/* Forward */
static
void
freechildren
PROTO
((
node
*
));
static
void
freechildren
P
y_P
ROTO
((
node
*
));
void
freet
ree
(
n
)
PyNode_F
ree
(
n
)
node
*
n
;
{
if
(
n
!=
NULL
)
{
freechildren
(
n
);
DEL
(
n
);
PyMem_
DEL
(
n
);
}
}
...
...
@@ -101,7 +101,7 @@ freechildren(n)
for
(
i
=
NCH
(
n
);
--
i
>=
0
;
)
freechildren
(
CHILD
(
n
,
i
));
if
(
n
->
n_child
!=
NULL
)
DEL
(
n
->
n_child
);
PyMem_
DEL
(
n
->
n_child
);
if
(
STR
(
n
)
!=
NULL
)
DEL
(
STR
(
n
));
PyMem_
DEL
(
STR
(
n
));
}
Parser/parser.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -45,8 +45,8 @@ PERFORMANCE OF THIS SOFTWARE.
#ifdef Py_DEBUG
extern
int
debuggin
g
;
#define D(x) if (!
debuggin
g); else x
extern
int
Py_DebugFla
g
;
#define D(x) if (!
Py_DebugFla
g); else x
#else
#define D(x)
#endif
...
...
@@ -54,7 +54,7 @@ extern int debugging;
/* STACK DATA TYPE */
static
void
s_reset
PROTO
((
stack
*
));
static
void
s_reset
P
y_P
ROTO
((
stack
*
));
static
void
s_reset
(
s
)
...
...
@@ -65,7 +65,7 @@ s_reset(s)
#define s_empty(s) ((s)->s_top == &(s)->s_base[MAXSTACK])
static
int
s_push
PROTO
((
stack
*
,
dfa
*
,
node
*
));
static
int
s_push
P
y_P
ROTO
((
stack
*
,
dfa
*
,
node
*
));
static
int
s_push
(
s
,
d
,
parent
)
...
...
@@ -87,14 +87,14 @@ s_push(s, d, parent)
#ifdef Py_DEBUG
static
void
s_pop
PROTO
((
stack
*
));
static
void
s_pop
P
y_P
ROTO
((
stack
*
));
static
void
s_pop
(
s
)
register
stack
*
s
;
{
if
(
s_empty
(
s
))
fatal
(
"s_pop: parser stack underflow -- FATAL"
);
Py_FatalError
(
"s_pop: parser stack underflow -- FATAL"
);
s
->
s_top
++
;
}
...
...
@@ -108,42 +108,42 @@ s_pop(s)
/* PARSER CREATION */
parser_state
*
newparser
(
g
,
start
)
PyParser_New
(
g
,
start
)
grammar
*
g
;
int
start
;
{
parser_state
*
ps
;
if
(
!
g
->
g_accel
)
adda
ccelerators
(
g
);
ps
=
NEW
(
parser_state
,
1
);
PyGrammar_AddA
ccelerators
(
g
);
ps
=
PyMem_
NEW
(
parser_state
,
1
);
if
(
ps
==
NULL
)
return
NULL
;
ps
->
p_grammar
=
g
;
ps
->
p_tree
=
newtree
(
start
);
ps
->
p_tree
=
PyNode_New
(
start
);
if
(
ps
->
p_tree
==
NULL
)
{
DEL
(
ps
);
PyMem_
DEL
(
ps
);
return
NULL
;
}
s_reset
(
&
ps
->
p_stack
);
(
void
)
s_push
(
&
ps
->
p_stack
,
finddfa
(
g
,
start
),
ps
->
p_tree
);
(
void
)
s_push
(
&
ps
->
p_stack
,
PyGrammar_FindDFA
(
g
,
start
),
ps
->
p_tree
);
return
ps
;
}
void
delparser
(
ps
)
PyParser_Delete
(
ps
)
parser_state
*
ps
;
{
/* NB If you want to save the parse tree,
you must set p_tree to NULL before calling delparser! */
freet
ree
(
ps
->
p_tree
);
DEL
(
ps
);
PyNode_F
ree
(
ps
->
p_tree
);
PyMem_
DEL
(
ps
);
}
/* PARSER STACK OPERATIONS */
static
int
shift
PROTO
((
stack
*
,
int
,
char
*
,
int
,
int
));
static
int
shift
P
y_P
ROTO
((
stack
*
,
int
,
char
*
,
int
,
int
));
static
int
shift
(
s
,
type
,
str
,
newstate
,
lineno
)
...
...
@@ -154,7 +154,7 @@ shift(s, type, str, newstate, lineno)
int
lineno
;
{
assert
(
!
s_empty
(
s
));
if
(
addc
hild
(
s
->
s_top
->
s_parent
,
type
,
str
,
lineno
)
==
NULL
)
{
if
(
PyNode_AddC
hild
(
s
->
s_top
->
s_parent
,
type
,
str
,
lineno
)
==
NULL
)
{
fprintf
(
stderr
,
"shift: no mem in addchild
\n
"
);
return
-
1
;
}
...
...
@@ -162,7 +162,7 @@ shift(s, type, str, newstate, lineno)
return
0
;
}
static
int
push
PROTO
((
stack
*
,
int
,
dfa
*
,
int
,
int
));
static
int
push
P
y_P
ROTO
((
stack
*
,
int
,
dfa
*
,
int
,
int
));
static
int
push
(
s
,
type
,
d
,
newstate
,
lineno
)
...
...
@@ -175,7 +175,7 @@ push(s, type, d, newstate, lineno)
register
node
*
n
;
n
=
s
->
s_top
->
s_parent
;
assert
(
!
s_empty
(
s
));
if
(
addc
hild
(
n
,
type
,
(
char
*
)
NULL
,
lineno
)
==
NULL
)
{
if
(
PyNode_AddC
hild
(
n
,
type
,
(
char
*
)
NULL
,
lineno
)
==
NULL
)
{
fprintf
(
stderr
,
"push: no mem in addchild
\n
"
);
return
-
1
;
}
...
...
@@ -186,7 +186,7 @@ push(s, type, d, newstate, lineno)
/* PARSER PROPER */
static
int
classify
PROTO
((
grammar
*
,
int
,
char
*
));
static
int
classify
P
y_P
ROTO
((
grammar
*
,
int
,
char
*
));
static
int
classify
(
g
,
type
,
str
)
...
...
@@ -226,7 +226,7 @@ classify(g, type, str)
}
int
addt
oken
(
ps
,
type
,
str
,
lineno
)
PyParser_AddT
oken
(
ps
,
type
,
str
,
lineno
)
register
parser_state
*
ps
;
register
int
type
;
char
*
str
;
...
...
@@ -234,7 +234,7 @@ addtoken(ps, type, str, lineno)
{
register
int
ilabel
;
D
(
printf
(
"Token %s/'%s' ... "
,
tok_name
[
type
],
str
));
D
(
printf
(
"Token %s/'%s' ... "
,
_PyParser_TokenNames
[
type
],
str
));
/* Find out which label this token is */
ilabel
=
classify
(
ps
->
p_grammar
,
type
,
str
);
...
...
@@ -258,10 +258,11 @@ addtoken(ps, type, str, lineno)
/* Push non-terminal */
int
nt
=
(
x
>>
8
)
+
NT_OFFSET
;
int
arrow
=
x
&
((
1
<<
7
)
-
1
);
dfa
*
d1
=
finddfa
(
ps
->
p_grammar
,
nt
);
dfa
*
d1
=
PyGrammar_FindDFA
(
ps
->
p_grammar
,
nt
);
if
(
push
(
&
ps
->
p_stack
,
nt
,
d1
,
arrow
,
lineno
)
<
0
)
{
D
(
printf
(
" MemError: push
.
\n
"
));
D
(
printf
(
" MemError: push
\n
"
));
return
E_NOMEM
;
}
D
(
printf
(
" Push ...
\n
"
));
...
...
@@ -326,7 +327,7 @@ dumptree(g, n)
label
l
;
l
.
lb_type
=
TYPE
(
n
);
l
.
lb_str
=
STR
(
n
);
printf
(
"%s"
,
labelr
epr
(
&
l
));
printf
(
"%s"
,
PyGrammar_LabelR
epr
(
&
l
));
if
(
ISNONTERMINAL
(
TYPE
(
n
)))
{
printf
(
"("
);
for
(
i
=
0
;
i
<
NCH
(
n
);
i
++
)
{
...
...
@@ -353,7 +354,7 @@ showtree(g, n)
showtree
(
g
,
CHILD
(
n
,
i
));
}
else
if
(
ISTERMINAL
(
TYPE
(
n
)))
{
printf
(
"%s"
,
tok_name
[
TYPE
(
n
)]);
printf
(
"%s"
,
_PyParser_TokenNames
[
TYPE
(
n
)]);
if
(
TYPE
(
n
)
==
NUMBER
||
TYPE
(
n
)
==
NAME
)
printf
(
"(%s)"
,
STR
(
n
));
printf
(
" "
);
...
...
@@ -366,7 +367,7 @@ void
printtree
(
ps
)
parser_state
*
ps
;
{
if
(
debuggin
g
)
{
if
(
Py_DebugFla
g
)
{
printf
(
"Parse tree:
\n
"
);
dumptree
(
ps
->
p_grammar
,
ps
->
p_tree
);
printf
(
"
\n
"
);
...
...
@@ -375,7 +376,7 @@ printtree(ps)
printf
(
"
\n
"
);
}
printf
(
"Listing:
\n
"
);
listt
ree
(
ps
->
p_tree
);
PyNode_ListT
ree
(
ps
->
p_tree
);
printf
(
"
\n
"
);
}
...
...
Parser/parser.h
Dosyayı görüntüle @
86bea46b
...
...
@@ -57,10 +57,11 @@ typedef struct {
node
*
p_tree
;
/* Top of parse tree */
}
parser_state
;
parser_state
*
newparser
PROTO
((
grammar
*
g
,
int
start
));
void
delparser
PROTO
((
parser_state
*
ps
));
int
addtoken
PROTO
((
parser_state
*
ps
,
int
type
,
char
*
str
,
int
lineno
));
void
addaccelerators
PROTO
((
grammar
*
g
));
parser_state
*
PyParser_New
Py_PROTO
((
grammar
*
g
,
int
start
));
void
PyParser_Delete
Py_PROTO
((
parser_state
*
ps
));
int
PyParser_AddToken
Py_PROTO
((
parser_state
*
ps
,
int
type
,
char
*
str
,
int
lineno
));
void
PyGrammar_AddAccelerators
Py_PROTO
((
grammar
*
g
));
#ifdef __cplusplus
}
...
...
Parser/parsetok.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -41,13 +41,13 @@ PERFORMANCE OF THIS SOFTWARE.
/* Forward */
static
node
*
parsetok
PROTO
((
struct
tok_state
*
,
grammar
*
,
int
,
static
node
*
parsetok
P
y_P
ROTO
((
struct
tok_state
*
,
grammar
*
,
int
,
perrdetail
*
));
/* Parse input coming from a string. Return error code, print some errors. */
node
*
parses
tring
(
s
,
g
,
start
,
err_ret
)
PyParser_ParseS
tring
(
s
,
g
,
start
,
err_ret
)
char
*
s
;
grammar
*
g
;
int
start
;
...
...
@@ -61,7 +61,7 @@ parsestring(s, g, start, err_ret)
err_ret
->
offset
=
0
;
err_ret
->
text
=
NULL
;
if
((
tok
=
tok_setups
(
s
))
==
NULL
)
{
if
((
tok
=
PyTokenizer_FromString
(
s
))
==
NULL
)
{
err_ret
->
error
=
E_NOMEM
;
return
NULL
;
}
...
...
@@ -73,7 +73,7 @@ parsestring(s, g, start, err_ret)
/* Parse input coming from a file. Return error code, print some errors. */
node
*
parsef
ile
(
fp
,
filename
,
g
,
start
,
ps1
,
ps2
,
err_ret
)
PyParser_ParseF
ile
(
fp
,
filename
,
g
,
start
,
ps1
,
ps2
,
err_ret
)
FILE
*
fp
;
char
*
filename
;
grammar
*
g
;
...
...
@@ -89,7 +89,7 @@ parsefile(fp, filename, g, start, ps1, ps2, err_ret)
err_ret
->
offset
=
0
;
err_ret
->
text
=
NULL
;
if
((
tok
=
tok_setupf
(
fp
,
ps1
,
ps2
))
==
NULL
)
{
if
((
tok
=
PyTokenizer_FromFile
(
fp
,
ps1
,
ps2
))
==
NULL
)
{
err_ret
->
error
=
E_NOMEM
;
return
NULL
;
}
...
...
@@ -119,7 +119,7 @@ parsetok(tok, g, start, err_ret)
node
*
n
;
int
started
=
0
;
if
((
ps
=
newparser
(
g
,
start
))
==
NULL
)
{
if
((
ps
=
PyParser_New
(
g
,
start
))
==
NULL
)
{
fprintf
(
stderr
,
"no mem for new parser
\n
"
);
err_ret
->
error
=
E_NOMEM
;
return
NULL
;
...
...
@@ -131,7 +131,7 @@ parsetok(tok, g, start, err_ret)
int
len
;
char
*
str
;
type
=
tok_g
et
(
tok
,
&
a
,
&
b
);
type
=
PyTokenizer_G
et
(
tok
,
&
a
,
&
b
);
if
(
type
==
ERRORTOKEN
)
{
err_ret
->
error
=
tok
->
done
;
break
;
...
...
@@ -143,7 +143,7 @@ parsetok(tok, g, start, err_ret)
else
started
=
1
;
len
=
b
-
a
;
/* XXX this may compute NULL - NULL */
str
=
NEW
(
char
,
len
+
1
);
str
=
PyMem_
NEW
(
char
,
len
+
1
);
if
(
str
==
NULL
)
{
fprintf
(
stderr
,
"no mem for next token
\n
"
);
err_ret
->
error
=
E_NOMEM
;
...
...
@@ -153,7 +153,8 @@ parsetok(tok, g, start, err_ret)
strncpy
(
str
,
a
,
len
);
str
[
len
]
=
'\0'
;
if
((
err_ret
->
error
=
addtoken
(
ps
,
(
int
)
type
,
str
,
tok
->
lineno
))
!=
E_OK
)
PyParser_AddToken
(
ps
,
(
int
)
type
,
str
,
tok
->
lineno
))
!=
E_OK
)
break
;
}
...
...
@@ -164,7 +165,7 @@ parsetok(tok, g, start, err_ret)
else
n
=
NULL
;
delparser
(
ps
);
PyParser_Delete
(
ps
);
if
(
n
==
NULL
)
{
if
(
tok
->
lineno
<=
1
&&
tok
->
done
==
E_EOF
)
...
...
@@ -182,7 +183,7 @@ parsetok(tok, g, start, err_ret)
}
}
tok_f
ree
(
tok
);
PyTokenizer_F
ree
(
tok
);
return
n
;
}
Parser/pgen.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -42,7 +42,7 @@ PERFORMANCE OF THIS SOFTWARE.
#include "metagrammar.h"
#include "pgen.h"
extern
int
debuggin
g
;
extern
int
Py_DebugFla
g
;
/* PART ONE -- CONSTRUCT NFA -- Cf. Algorithm 3.2 from [Aho&Ullman 77] */
...
...
@@ -66,13 +66,13 @@ typedef struct _nfa {
}
nfa
;
/* Forward */
static
void
compile_rhs
PROTO
((
labellist
*
ll
,
static
void
compile_rhs
P
y_P
ROTO
((
labellist
*
ll
,
nfa
*
nf
,
node
*
n
,
int
*
pa
,
int
*
pb
));
static
void
compile_alt
PROTO
((
labellist
*
ll
,
static
void
compile_alt
P
y_P
ROTO
((
labellist
*
ll
,
nfa
*
nf
,
node
*
n
,
int
*
pa
,
int
*
pb
));
static
void
compile_item
PROTO
((
labellist
*
ll
,
static
void
compile_item
P
y_P
ROTO
((
labellist
*
ll
,
nfa
*
nf
,
node
*
n
,
int
*
pa
,
int
*
pb
));
static
void
compile_atom
PROTO
((
labellist
*
ll
,
static
void
compile_atom
P
y_P
ROTO
((
labellist
*
ll
,
nfa
*
nf
,
node
*
n
,
int
*
pa
,
int
*
pb
));
static
int
...
...
@@ -81,9 +81,9 @@ addnfastate(nf)
{
nfastate
*
st
;
RESIZE
(
nf
->
nf_state
,
nfastate
,
nf
->
nf_nstates
+
1
);
PyMem_
RESIZE
(
nf
->
nf_state
,
nfastate
,
nf
->
nf_nstates
+
1
);
if
(
nf
->
nf_state
==
NULL
)
fatal
(
"out of mem"
);
Py_FatalError
(
"out of mem"
);
st
=
&
nf
->
nf_state
[
nf
->
nf_nstates
++
];
st
->
st_narcs
=
0
;
st
->
st_arc
=
NULL
;
...
...
@@ -99,9 +99,9 @@ addnfaarc(nf, from, to, lbl)
nfaarc
*
ar
;
st
=
&
nf
->
nf_state
[
from
];
RESIZE
(
st
->
st_arc
,
nfaarc
,
st
->
st_narcs
+
1
);
PyMem_
RESIZE
(
st
->
st_arc
,
nfaarc
,
st
->
st_narcs
+
1
);
if
(
st
->
st_arc
==
NULL
)
fatal
(
"out of mem"
);
Py_FatalError
(
"out of mem"
);
ar
=
&
st
->
st_arc
[
st
->
st_narcs
++
];
ar
->
ar_label
=
lbl
;
ar
->
ar_arrow
=
to
;
...
...
@@ -114,9 +114,9 @@ newnfa(name)
nfa
*
nf
;
static
type
=
NT_OFFSET
;
/* All types will be disjunct */
nf
=
NEW
(
nfa
,
1
);
nf
=
PyMem_
NEW
(
nfa
,
1
);
if
(
nf
==
NULL
)
fatal
(
"no mem for new nfa"
);
Py_FatalError
(
"no mem for new nfa"
);
nf
->
nf_type
=
type
++
;
nf
->
nf_name
=
name
;
/* XXX strdup(name) ??? */
nf
->
nf_nstates
=
0
;
...
...
@@ -132,16 +132,16 @@ typedef struct _nfagrammar {
}
nfagrammar
;
/* Forward */
static
void
compile_rule
PROTO
((
nfagrammar
*
gr
,
node
*
n
));
static
void
compile_rule
P
y_P
ROTO
((
nfagrammar
*
gr
,
node
*
n
));
static
nfagrammar
*
newnfagrammar
()
{
nfagrammar
*
gr
;
gr
=
NEW
(
nfagrammar
,
1
);
gr
=
PyMem_
NEW
(
nfagrammar
,
1
);
if
(
gr
==
NULL
)
fatal
(
"no mem for new nfa grammar"
);
Py_FatalError
(
"no mem for new nfa grammar"
);
gr
->
gr_nnfas
=
0
;
gr
->
gr_nfa
=
NULL
;
gr
->
gr_ll
.
ll_nlabels
=
0
;
...
...
@@ -158,9 +158,9 @@ addnfa(gr, name)
nfa
*
nf
;
nf
=
newnfa
(
name
);
RESIZE
(
gr
->
gr_nfa
,
nfa
*
,
gr
->
gr_nnfas
+
1
);
PyMem_
RESIZE
(
gr
->
gr_nfa
,
nfa
*
,
gr
->
gr_nnfas
+
1
);
if
(
gr
->
gr_nfa
==
NULL
)
fatal
(
"out of mem"
);
Py_FatalError
(
"out of mem"
);
gr
->
gr_nfa
[
gr
->
gr_nnfas
++
]
=
nf
;
addlabel
(
&
gr
->
gr_ll
,
NAME
,
nf
->
nf_name
);
return
nf
;
...
...
@@ -173,7 +173,7 @@ static char REQNFMT[] = "metacompile: less than %d children\n";
#define REQN(i, count) \
if (i < count) { \
fprintf(stderr, REQNFMT, count); \
fatal
("REQN"); \
Py_FatalError
("REQN"); \
} else
#else
...
...
@@ -379,7 +379,7 @@ dumpstate(ll, nf, istate)
if
(
i
>
0
)
printf
(
"
\n
"
);
printf
(
"-> %2d %s"
,
ar
->
ar_arrow
,
labelr
epr
(
&
ll
->
ll_label
[
ar
->
ar_label
]));
PyGrammar_LabelR
epr
(
&
ll
->
ll_label
[
ar
->
ar_label
]));
ar
++
;
}
printf
(
"
\n
"
);
...
...
@@ -441,10 +441,10 @@ typedef struct _ss_dfa {
}
ss_dfa
;
/* Forward */
static
void
printssdfa
PROTO
((
int
xx_nstates
,
ss_state
*
xx_state
,
int
nbits
,
static
void
printssdfa
P
y_P
ROTO
((
int
xx_nstates
,
ss_state
*
xx_state
,
int
nbits
,
labellist
*
ll
,
char
*
msg
));
static
void
simplify
PROTO
((
int
xx_nstates
,
ss_state
*
xx_state
));
static
void
convert
PROTO
((
dfa
*
d
,
int
xx_nstates
,
ss_state
*
xx_state
));
static
void
simplify
P
y_P
ROTO
((
int
xx_nstates
,
ss_state
*
xx_state
));
static
void
convert
P
y_P
ROTO
((
dfa
*
d
,
int
xx_nstates
,
ss_state
*
xx_state
));
static
void
makedfa
(
gr
,
nf
,
d
)
...
...
@@ -463,9 +463,9 @@ makedfa(gr, nf, d)
ss
=
newbitset
(
nbits
);
addclosure
(
ss
,
nf
,
nf
->
nf_start
);
xx_state
=
NEW
(
ss_state
,
1
);
xx_state
=
PyMem_
NEW
(
ss_state
,
1
);
if
(
xx_state
==
NULL
)
fatal
(
"no mem for xx_state in makedfa"
);
Py_FatalError
(
"no mem for xx_state in makedfa"
);
xx_nstates
=
1
;
yy
=
&
xx_state
[
0
];
yy
->
ss_ss
=
ss
;
...
...
@@ -501,9 +501,10 @@ makedfa(gr, nf, d)
goto
found
;
}
/* Add new arc for this state */
RESIZE
(
yy
->
ss_arc
,
ss_arc
,
yy
->
ss_narcs
+
1
);
PyMem_RESIZE
(
yy
->
ss_arc
,
ss_arc
,
yy
->
ss_narcs
+
1
);
if
(
yy
->
ss_arc
==
NULL
)
fatal
(
"out of mem"
);
Py_FatalError
(
"out of mem"
);
zz
=
&
yy
->
ss_arc
[
yy
->
ss_narcs
++
];
zz
->
sa_label
=
ar
->
ar_label
;
zz
->
sa_bitset
=
newbitset
(
nbits
);
...
...
@@ -523,9 +524,9 @@ makedfa(gr, nf, d)
goto
done
;
}
}
RESIZE
(
xx_state
,
ss_state
,
xx_nstates
+
1
);
PyMem_
RESIZE
(
xx_state
,
ss_state
,
xx_nstates
+
1
);
if
(
xx_state
==
NULL
)
fatal
(
"out of mem"
);
Py_FatalError
(
"out of mem"
);
zz
->
sa_arrow
=
xx_nstates
;
yy
=
&
xx_state
[
xx_nstates
++
];
yy
->
ss_ss
=
zz
->
sa_bitset
;
...
...
@@ -537,13 +538,13 @@ makedfa(gr, nf, d)
}
}
if
(
debuggin
g
)
if
(
Py_DebugFla
g
)
printssdfa
(
xx_nstates
,
xx_state
,
nbits
,
&
gr
->
gr_ll
,
"before minimizing"
);
simplify
(
xx_nstates
,
xx_state
);
if
(
debuggin
g
)
if
(
Py_DebugFla
g
)
printssdfa
(
xx_nstates
,
xx_state
,
nbits
,
&
gr
->
gr_ll
,
"after minimizing"
);
...
...
@@ -582,7 +583,8 @@ printssdfa(xx_nstates, xx_state, nbits, ll, msg)
zz
=
&
yy
->
ss_arc
[
iarc
];
printf
(
" Arc to state %d, label %s
\n
"
,
zz
->
sa_arrow
,
labelrepr
(
&
ll
->
ll_label
[
zz
->
sa_label
]));
PyGrammar_LabelRepr
(
&
ll
->
ll_label
[
zz
->
sa_label
]));
}
}
}
...
...
@@ -621,7 +623,7 @@ renamestates(xx_nstates, xx_state, from, to)
{
int
i
,
j
;
if
(
debuggin
g
)
if
(
Py_DebugFla
g
)
printf
(
"Rename state %d to %d.
\n
"
,
from
,
to
);
for
(
i
=
0
;
i
<
xx_nstates
;
i
++
)
{
if
(
xx_state
[
i
].
ss_deleted
)
...
...
@@ -651,7 +653,8 @@ simplify(xx_nstates, xx_state)
continue
;
if
(
samestate
(
&
xx_state
[
i
],
&
xx_state
[
j
]))
{
xx_state
[
i
].
ss_deleted
++
;
renamestates
(
xx_nstates
,
xx_state
,
i
,
j
);
renamestates
(
xx_nstates
,
xx_state
,
i
,
j
);
changes
++
;
break
;
}
...
...
@@ -719,7 +722,7 @@ maketables(gr)
for
(
i
=
0
;
i
<
gr
->
gr_nnfas
;
i
++
)
{
nf
=
gr
->
gr_nfa
[
i
];
if
(
debuggin
g
)
{
if
(
Py_DebugFla
g
)
{
printf
(
"Dump of NFA for '%s' ...
\n
"
,
nf
->
nf_name
);
dumpnfa
(
&
gr
->
gr_ll
,
nf
);
}
...
...
Parser/pgen.h
Dosyayı görüntüle @
86bea46b
...
...
@@ -37,10 +37,10 @@ PERFORMANCE OF THIS SOFTWARE.
/* Parser generator interface */
extern
grammar
*
meta_grammar
PROTO
((
void
));
extern
grammar
*
meta_grammar
P
y_P
ROTO
((
void
));
struct
_node
;
extern
grammar
*
pgen
PROTO
((
struct
_node
*
));
extern
grammar
*
pgen
P
y_P
ROTO
((
struct
_node
*
));
#ifdef __cplusplus
}
...
...
Parser/pgenmain.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -49,17 +49,17 @@ PERFORMANCE OF THIS SOFTWARE.
#include "parsetok.h"
#include "pgen.h"
int
debuggin
g
;
int
Py_DebugFla
g
;
/* Forward */
grammar
*
getgrammar
PROTO
((
char
*
filename
));
grammar
*
getgrammar
P
y_P
ROTO
((
char
*
filename
));
#ifdef THINK_C
int
main
PROTO
((
int
,
char
**
));
char
*
askfile
PROTO
((
void
));
int
main
P
y_P
ROTO
((
int
,
char
**
));
char
*
askfile
P
y_P
ROTO
((
void
));
#endif
void
goaway
(
sts
)
Py_Exit
(
sts
)
int
sts
;
{
exit
(
sts
);
...
...
@@ -79,7 +79,7 @@ main(argc, argv)
#else
if
(
argc
!=
2
)
{
fprintf
(
stderr
,
"usage: %s grammar
\n
"
,
argv
[
0
]);
goaway
(
2
);
Py_Exit
(
2
);
}
filename
=
argv
[
1
];
#endif
...
...
@@ -87,7 +87,7 @@ main(argc, argv)
fp
=
fopen
(
"graminit.c"
,
"w"
);
if
(
fp
==
NULL
)
{
perror
(
"graminit.c"
);
goaway
(
1
);
Py_Exit
(
1
);
}
printf
(
"Writing graminit.c ...
\n
"
);
printgrammar
(
g
,
fp
);
...
...
@@ -95,12 +95,12 @@ main(argc, argv)
fp
=
fopen
(
"graminit.h"
,
"w"
);
if
(
fp
==
NULL
)
{
perror
(
"graminit.h"
);
goaway
(
1
);
Py_Exit
(
1
);
}
printf
(
"Writing graminit.h ...
\n
"
);
printnonterminals
(
g
,
fp
);
fclose
(
fp
);
goaway
(
0
);
Py_Exit
(
0
);
return
0
;
/* Make gcc -Wall happy */
}
...
...
@@ -116,10 +116,10 @@ getgrammar(filename)
fp
=
fopen
(
filename
,
"r"
);
if
(
fp
==
NULL
)
{
perror
(
filename
);
goaway
(
1
);
Py_Exit
(
1
);
}
g0
=
meta_grammar
();
n
=
parsef
ile
(
fp
,
filename
,
g0
,
g0
->
g_start
,
n
=
PyParser_ParseF
ile
(
fp
,
filename
,
g0
,
g0
->
g_start
,
(
char
*
)
NULL
,
(
char
*
)
NULL
,
&
err
);
fclose
(
fp
);
if
(
n
==
NULL
)
{
...
...
@@ -140,12 +140,12 @@ getgrammar(filename)
fprintf
(
stderr
,
"^
\n
"
);
free
(
err
.
text
);
}
goaway
(
1
);
Py_Exit
(
1
);
}
g
=
pgen
(
n
);
if
(
g
==
NULL
)
{
printf
(
"Bad grammar.
\n
"
);
goaway
(
1
);
Py_Exit
(
1
);
}
return
g
;
}
...
...
@@ -159,23 +159,23 @@ askfile()
printf
(
"Input file name: "
);
if
(
fgets
(
buf
,
sizeof
buf
,
stdin
)
==
NULL
)
{
printf
(
"EOF
\n
"
);
goaway
(
1
);
Py_Exit
(
1
);
}
/* XXX The (unsigned char *) case is needed by THINK C 3.0 */
if
(
sscanf
(
/*(unsigned char *)*/
buf
,
" %s "
,
name
)
!=
1
)
{
printf
(
"No file
\n
"
);
goaway
(
1
);
Py_Exit
(
1
);
}
return
name
;
}
#endif
void
fatal
(
msg
)
Py_FatalError
(
msg
)
char
*
msg
;
{
fprintf
(
stderr
,
"pgen: FATAL ERROR: %s
\n
"
,
msg
);
goaway
(
1
);
Py_Exit
(
1
);
}
#ifdef macintosh
...
...
@@ -191,7 +191,7 @@ guesstabsize(path)
/* No-nonsense my_readline() for tokenizer.c */
char
*
my_r
eadline
(
prompt
)
PyOS_R
eadline
(
prompt
)
char
*
prompt
;
{
int
n
=
1000
;
...
...
Parser/printgrammar.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -35,10 +35,10 @@ PERFORMANCE OF THIS SOFTWARE.
#include "grammar.h"
/* Forward */
static
void
printarcs
PROTO
((
int
,
dfa
*
,
FILE
*
));
static
void
printstates
PROTO
((
grammar
*
,
FILE
*
));
static
void
printdfas
PROTO
((
grammar
*
,
FILE
*
));
static
void
printlabels
PROTO
((
grammar
*
,
FILE
*
));
static
void
printarcs
P
y_P
ROTO
((
int
,
dfa
*
,
FILE
*
));
static
void
printstates
P
y_P
ROTO
((
grammar
*
,
FILE
*
));
static
void
printdfas
P
y_P
ROTO
((
grammar
*
,
FILE
*
));
static
void
printlabels
P
y_P
ROTO
((
grammar
*
,
FILE
*
));
void
printgrammar
(
g
,
fp
)
...
...
Parser/tokenizer.c
Dosyayı görüntüle @
86bea46b
...
...
@@ -38,7 +38,7 @@ PERFORMANCE OF THIS SOFTWARE.
#include "tokenizer.h"
#include "errcode.h"
extern
char
*
my_readline
PROTO
((
char
*
));
extern
char
*
PyOS_Readline
Py_
PROTO
((
char
*
));
/* Return malloc'ed string including trailing \n;
empty malloc'ed string for EOF;
NULL if interrupted */
...
...
@@ -47,13 +47,13 @@ extern char *my_readline PROTO((char *));
#define TABSIZE 8
/* Forward */
static
struct
tok_state
*
tok_new
PROTO
((
void
));
static
int
tok_nextc
PROTO
((
struct
tok_state
*
tok
));
static
void
tok_backup
PROTO
((
struct
tok_state
*
tok
,
int
c
));
static
struct
tok_state
*
tok_new
P
y_P
ROTO
((
void
));
static
int
tok_nextc
P
y_P
ROTO
((
struct
tok_state
*
tok
));
static
void
tok_backup
P
y_P
ROTO
((
struct
tok_state
*
tok
,
int
c
));
/* Token names */
char
*
tok_name
[]
=
{
char
*
_PyParser_TokenNames
[]
=
{
"ENDMARKER"
,
"NAME"
,
"NUMBER"
,
...
...
@@ -103,7 +103,7 @@ char *tok_name[] = {
static
struct
tok_state
*
tok_new
()
{
struct
tok_state
*
tok
=
NEW
(
struct
tok_state
,
1
);
struct
tok_state
*
tok
=
PyMem_
NEW
(
struct
tok_state
,
1
);
if
(
tok
==
NULL
)
return
NULL
;
tok
->
buf
=
tok
->
cur
=
tok
->
end
=
tok
->
inp
=
tok
->
start
=
NULL
;
...
...
@@ -124,7 +124,7 @@ tok_new()
/* Set up tokenizer for string */
struct
tok_state
*
tok_setups
(
str
)
PyTokenizer_FromString
(
str
)
char
*
str
;
{
struct
tok_state
*
tok
=
tok_new
();
...
...
@@ -138,15 +138,15 @@ tok_setups(str)
/* Set up tokenizer for file */
struct
tok_state
*
tok_setupf
(
fp
,
ps1
,
ps2
)
PyTokenizer_FromFile
(
fp
,
ps1
,
ps2
)
FILE
*
fp
;
char
*
ps1
,
*
ps2
;
{
struct
tok_state
*
tok
=
tok_new
();
if
(
tok
==
NULL
)
return
NULL
;
if
((
tok
->
buf
=
NEW
(
char
,
BUFSIZ
))
==
NULL
)
{
DEL
(
tok
);
if
((
tok
->
buf
=
PyMem_
NEW
(
char
,
BUFSIZ
))
==
NULL
)
{
PyMem_
DEL
(
tok
);
return
NULL
;
}
tok
->
cur
=
tok
->
inp
=
tok
->
buf
;
...
...
@@ -161,12 +161,12 @@ tok_setupf(fp, ps1, ps2)
/* Free a tok_state structure */
void
tok_f
ree
(
tok
)
PyTokenizer_F
ree
(
tok
)
struct
tok_state
*
tok
;
{
if
(
tok
->
fp
!=
NULL
&&
tok
->
buf
!=
NULL
)
DEL
(
tok
->
buf
);
DEL
(
tok
);
PyMem_
DEL
(
tok
->
buf
);
PyMem_
DEL
(
tok
);
}
...
...
@@ -200,7 +200,7 @@ tok_nextc(tok)
return
*
tok
->
cur
++
;
}
if
(
tok
->
prompt
!=
NULL
)
{
char
*
new
=
my_r
eadline
(
tok
->
prompt
);
char
*
new
=
PyOS_R
eadline
(
tok
->
prompt
);
if
(
tok
->
nextprompt
!=
NULL
)
tok
->
prompt
=
tok
->
nextprompt
;
if
(
new
==
NULL
)
...
...
@@ -246,7 +246,7 @@ tok_nextc(tok)
char
*
pt
;
if
(
tok
->
start
==
NULL
)
{
if
(
tok
->
buf
==
NULL
)
{
tok
->
buf
=
NEW
(
char
,
BUFSIZ
);
tok
->
buf
=
PyMem_
NEW
(
char
,
BUFSIZ
);
if
(
tok
->
buf
==
NULL
)
{
tok
->
done
=
E_NOMEM
;
return
EOF
;
...
...
@@ -281,7 +281,7 @@ tok_nextc(tok)
int
curvalid
=
tok
->
inp
-
tok
->
buf
;
int
newsize
=
curvalid
+
BUFSIZ
;
char
*
newbuf
=
tok
->
buf
;
RESIZE
(
newbuf
,
char
,
newsize
);
PyMem_
RESIZE
(
newbuf
,
char
,
newsize
);
if
(
newbuf
==
NULL
)
{
tok
->
done
=
E_NOMEM
;
tok
->
cur
=
tok
->
inp
;
...
...
@@ -334,7 +334,7 @@ tok_backup(tok, c)
{
if
(
c
!=
EOF
)
{
if
(
--
tok
->
cur
<
tok
->
buf
)
fatal
(
"tok_backup: begin of buffer"
);
Py_FatalError
(
"tok_backup: begin of buffer"
);
if
(
*
tok
->
cur
!=
c
)
*
tok
->
cur
=
c
;
}
...
...
@@ -344,7 +344,7 @@ tok_backup(tok, c)
/* Return the token corresponding to a single character */
int
tok_1c
har
(
c
)
PyToken_OneC
har
(
c
)
int
c
;
{
switch
(
c
)
{
...
...
@@ -377,7 +377,7 @@ tok_1char(c)
int
tok_2char
(
c1
,
c2
)
PyToken_TwoChars
(
c1
,
c2
)
int
c1
,
c2
;
{
switch
(
c1
)
{
...
...
@@ -417,7 +417,7 @@ tok_2char(c1, c2)
/* Get next token, after space stripping etc. */
int
tok_g
et
(
tok
,
p_start
,
p_end
)
PyTokenizer_G
et
(
tok
,
p_start
,
p_end
)
register
struct
tok_state
*
tok
;
/* In/out: tokenizer state */
char
**
p_start
,
**
p_end
;
/* Out: point to start/end of token */
{
...
...
@@ -481,7 +481,8 @@ tok_get(tok, p_start, p_end)
tok
->
pendin
--
;
}
if
(
col
!=
tok
->
indstack
[
tok
->
indent
])
{
fprintf
(
stderr
,
"inconsistent dedent
\n
"
);
fprintf
(
stderr
,
"inconsistent dedent
\n
"
);
tok
->
done
=
E_TOKEN
;
tok
->
cur
=
tok
->
inp
;
return
ERRORTOKEN
;
...
...
@@ -569,7 +570,8 @@ tok_get(tok, p_start, p_end)
#ifdef macintosh
if
(
c
==
'\r'
)
{
fprintf
(
stderr
,
"File contains
\\
r characters (incorrect line endings?)
\n
"
);
fprintf
(
stderr
,
"File contains
\\
r characters (incorrect line endings?)
\n
"
);
tok
->
done
=
E_TOKEN
;
tok
->
cur
=
tok
->
inp
;
return
ERRORTOKEN
;
...
...
@@ -726,7 +728,7 @@ tok_get(tok, p_start, p_end)
/* Check for two-character token */
{
int
c2
=
tok_nextc
(
tok
);
int
token
=
tok_2char
(
c
,
c2
);
int
token
=
PyToken_TwoChars
(
c
,
c2
);
if
(
token
!=
OP
)
{
*
p_start
=
tok
->
start
;
*
p_end
=
tok
->
cur
;
...
...
@@ -752,7 +754,7 @@ tok_get(tok, p_start, p_end)
/* Punctuation character */
*
p_start
=
tok
->
start
;
*
p_end
=
tok
->
cur
;
return
tok_1c
har
(
c
);
return
PyToken_OneC
har
(
c
);
}
...
...
@@ -763,7 +765,7 @@ tok_dump(type, start, end)
int
type
;
char
*
start
,
*
end
;
{
printf
(
"%s"
,
tok_name
[
type
]);
printf
(
"%s"
,
_PyParser_TokenNames
[
type
]);
if
(
type
==
NAME
||
type
==
NUMBER
||
type
==
STRING
||
type
==
OP
)
printf
(
"(%.*s)"
,
(
int
)(
end
-
start
),
start
);
}
...
...
Parser/tokenizer.h
Dosyayı görüntüle @
86bea46b
...
...
@@ -64,10 +64,11 @@ struct tok_state {
/* Used to allow free continuations inside them */
};
extern
struct
tok_state
*
tok_setups
PROTO
((
char
*
));
extern
struct
tok_state
*
tok_setupf
PROTO
((
FILE
*
,
char
*
,
char
*
));
extern
void
tok_free
PROTO
((
struct
tok_state
*
));
extern
int
tok_get
PROTO
((
struct
tok_state
*
,
char
**
,
char
**
));
extern
struct
tok_state
*
PyTokenizer_FromString
Py_PROTO
((
char
*
));
extern
struct
tok_state
*
PyTokenizer_FromFile
Py_PROTO
((
FILE
*
,
char
*
,
char
*
));
extern
void
PyTokenizer_Free
Py_PROTO
((
struct
tok_state
*
));
extern
int
PyTokenizer_Get
Py_PROTO
((
struct
tok_state
*
,
char
**
,
char
**
));
#ifdef __cplusplus
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment