some more fixes, and tried to make smaller
This commit is contained in:
parent
3de7f959d3
commit
51169956dc
12 changed files with 102 additions and 79 deletions
|
@ -32,7 +32,7 @@ int proclevel = 0; /* nesting level of procedures */
|
||||||
int return_occurred; /* set if a return occurs in a block */
|
int return_occurred; /* set if a return occurs in a block */
|
||||||
|
|
||||||
#define needs_static_link() (proclevel > 1)
|
#define needs_static_link() (proclevel > 1)
|
||||||
|
extern struct node *EmptyStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* inline in declaration: need space
|
/* inline in declaration: need space
|
||||||
|
@ -82,11 +82,13 @@ block(struct node **pnd;) :
|
||||||
[ %persistent
|
[ %persistent
|
||||||
declaration
|
declaration
|
||||||
]*
|
]*
|
||||||
{ return_occurred = 0; *pnd = 0; }
|
{ return_occurred = 0; }
|
||||||
[ %persistent
|
[ %default
|
||||||
BEGIN
|
BEGIN
|
||||||
StatementSequence(pnd)
|
StatementSequence(pnd)
|
||||||
]?
|
|
|
||||||
|
{ *pnd = EmptyStatement; }
|
||||||
|
]
|
||||||
END
|
END
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -164,7 +166,7 @@ TypeDeclaration
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
}:
|
}:
|
||||||
IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE);
|
IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE);
|
||||||
nd = MkLeaf(Name, &dot);
|
nd = dot2leaf(Name);
|
||||||
}
|
}
|
||||||
'=' type(&tp)
|
'=' type(&tp)
|
||||||
{ DeclareType(nd, df, tp);
|
{ DeclareType(nd, df, tp);
|
||||||
|
@ -218,10 +220,10 @@ IdentList(struct node **p;)
|
||||||
{
|
{
|
||||||
register struct node *q;
|
register struct node *q;
|
||||||
} :
|
} :
|
||||||
IDENT { *p = q = MkLeaf(Value, &dot); }
|
IDENT { *p = q = dot2leaf(Value); }
|
||||||
[ %persistent
|
[ %persistent
|
||||||
',' IDENT
|
',' IDENT
|
||||||
{ q->nd_left = MkLeaf(Value, &dot);
|
{ q->nd_left = dot2leaf(Value);
|
||||||
q = q->nd_left;
|
q = q->nd_left;
|
||||||
}
|
}
|
||||||
]*
|
]*
|
||||||
|
@ -376,7 +378,7 @@ variant(struct scope *scope; arith *cnt; struct type *tp; int *palign;)
|
||||||
CaseLabelList(struct type **ptp; struct node **pnd;):
|
CaseLabelList(struct type **ptp; struct node **pnd;):
|
||||||
CaseLabels(ptp, pnd)
|
CaseLabels(ptp, pnd)
|
||||||
[
|
[
|
||||||
{ *pnd = MkNode(Link, *pnd, NULLNODE, &dot); }
|
{ *pnd = dot2node(Link, *pnd, NULLNODE); }
|
||||||
',' CaseLabels(ptp, &((*pnd)->nd_right))
|
',' CaseLabels(ptp, &((*pnd)->nd_right))
|
||||||
{ pnd = &((*pnd)->nd_right); }
|
{ pnd = &((*pnd)->nd_right); }
|
||||||
]*
|
]*
|
||||||
|
@ -394,7 +396,7 @@ CaseLabels(struct type **ptp; register struct node **pnd;)
|
||||||
nd = *pnd;
|
nd = *pnd;
|
||||||
}
|
}
|
||||||
[
|
[
|
||||||
UPTO { *pnd = MkNode(Link,nd,NULLNODE,&dot); }
|
UPTO { *pnd = dot2node(Link,nd,NULLNODE); }
|
||||||
ConstExpression(&(*pnd)->nd_right)
|
ConstExpression(&(*pnd)->nd_right)
|
||||||
{ if (!ChkCompat(&((*pnd)->nd_right), nd->nd_type,
|
{ if (!ChkCompat(&((*pnd)->nd_right), nd->nd_type,
|
||||||
"case label")) {
|
"case label")) {
|
||||||
|
@ -518,7 +520,7 @@ IdentAddr(struct node **pnd;)
|
||||||
{
|
{
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
} :
|
} :
|
||||||
IDENT { nd = MkLeaf(Name, &dot); }
|
IDENT { nd = dot2leaf(Name); }
|
||||||
[ '['
|
[ '['
|
||||||
ConstExpression(&(nd->nd_left))
|
ConstExpression(&(nd->nd_left))
|
||||||
']'
|
']'
|
||||||
|
|
|
@ -239,7 +239,7 @@ DeclProc(type, id)
|
||||||
/* In a definition module
|
/* In a definition module
|
||||||
*/
|
*/
|
||||||
df = define(id, CurrentScope, type);
|
df = define(id, CurrentScope, type);
|
||||||
df->for_node = MkLeaf(Name, &dot);
|
df->for_node = dot2leaf(Name);
|
||||||
if (CurrentScope->sc_definedby->df_flags & D_FOREIGN) {
|
if (CurrentScope->sc_definedby->df_flags & D_FOREIGN) {
|
||||||
df->for_name = id->id_text;
|
df->for_name = id->id_text;
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ GetDefinitionModule(id, incr)
|
||||||
register struct node *n;
|
register struct node *n;
|
||||||
extern struct node *Modules;
|
extern struct node *Modules;
|
||||||
|
|
||||||
n = MkLeaf(Name, &dot);
|
n = dot2leaf(Name);
|
||||||
n->nd_IDF = id;
|
n->nd_IDF = id;
|
||||||
n->nd_symb = IDENT;
|
n->nd_symb = IDENT;
|
||||||
if (nd_end) nd_end->nd_left = n;
|
if (nd_end) nd_end->nd_left = n;
|
||||||
|
|
|
@ -197,7 +197,7 @@ EnterParamList(ppr, Idlist, type, VARp, off)
|
||||||
|
|
||||||
if (! idlist) {
|
if (! idlist) {
|
||||||
/* Can only happen when a procedure type is defined */
|
/* Can only happen when a procedure type is defined */
|
||||||
dummy = Idlist = idlist = MkLeaf(Name, &dot);
|
dummy = Idlist = idlist = dot2leaf(Name);
|
||||||
}
|
}
|
||||||
for ( ; idlist; idlist = idlist->nd_left) {
|
for ( ; idlist; idlist = idlist->nd_left) {
|
||||||
pr = new_paramlist();
|
pr = new_paramlist();
|
||||||
|
|
|
@ -36,7 +36,7 @@ number(struct node **p;) :
|
||||||
INTEGER
|
INTEGER
|
||||||
|
|
|
|
||||||
REAL
|
REAL
|
||||||
] { *p = MkLeaf(Value, &dot);
|
] { *p = dot2leaf(Value);
|
||||||
(*p)->nd_type = toktype;
|
(*p)->nd_type = toktype;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -45,14 +45,14 @@ number(struct node **p;) :
|
||||||
qualident(struct node **p;)
|
qualident(struct node **p;)
|
||||||
{
|
{
|
||||||
} :
|
} :
|
||||||
IDENT { *p = MkLeaf(Name, &dot); }
|
IDENT { *p = dot2leaf(Name); }
|
||||||
[
|
[
|
||||||
selector(p)
|
selector(p)
|
||||||
]*
|
]*
|
||||||
;
|
;
|
||||||
|
|
||||||
selector(struct node **pnd;):
|
selector(struct node **pnd;):
|
||||||
'.' { *pnd = MkNode(Link,*pnd,NULLNODE,&dot); }
|
'.' { *pnd = dot2node(Link,*pnd,NULLNODE); }
|
||||||
IDENT { (*pnd)->nd_IDF = dot.TOK_IDF; }
|
IDENT { (*pnd)->nd_IDF = dot.TOK_IDF; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -60,11 +60,11 @@ ExpList(struct node **pnd;)
|
||||||
{
|
{
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
} :
|
} :
|
||||||
expression(pnd) { *pnd = nd = MkNode(Link,*pnd,NULLNODE,&dot);
|
expression(pnd) { *pnd = nd = dot2node(Link,*pnd,NULLNODE);
|
||||||
nd->nd_symb = ',';
|
nd->nd_symb = ',';
|
||||||
}
|
}
|
||||||
[
|
[
|
||||||
',' { nd->nd_right = MkLeaf(Link, &dot);
|
',' { nd->nd_right = dot2leaf(Link);
|
||||||
nd = nd->nd_right;
|
nd = nd->nd_right;
|
||||||
}
|
}
|
||||||
expression(&(nd->nd_left))
|
expression(&(nd->nd_left))
|
||||||
|
@ -101,7 +101,7 @@ expression(struct node **pnd;)
|
||||||
[
|
[
|
||||||
/* relation */
|
/* relation */
|
||||||
[ '=' | '#' | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN ]
|
[ '=' | '#' | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN ]
|
||||||
{ *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); }
|
{ *pnd = dot2node(Oper, *pnd, NULLNODE); }
|
||||||
SimpleExpression(&((*pnd)->nd_right))
|
SimpleExpression(&((*pnd)->nd_right))
|
||||||
]?
|
]?
|
||||||
;
|
;
|
||||||
|
@ -118,7 +118,7 @@ SimpleExpression(struct node **pnd;)
|
||||||
} :
|
} :
|
||||||
[
|
[
|
||||||
[ '+' | '-' ]
|
[ '+' | '-' ]
|
||||||
{ nd = MkLeaf(Uoper, &dot);
|
{ nd = dot2leaf(Uoper);
|
||||||
/* priority of unary operator ??? */
|
/* priority of unary operator ??? */
|
||||||
}
|
}
|
||||||
]?
|
]?
|
||||||
|
@ -132,7 +132,7 @@ SimpleExpression(struct node **pnd;)
|
||||||
[
|
[
|
||||||
/* AddOperator */
|
/* AddOperator */
|
||||||
[ '+' | '-' | OR ]
|
[ '+' | '-' | OR ]
|
||||||
{ nd = MkNode(Oper, nd, NULLNODE, &dot); }
|
{ nd = dot2node(Oper, nd, NULLNODE); }
|
||||||
term(&(nd->nd_right))
|
term(&(nd->nd_right))
|
||||||
]*
|
]*
|
||||||
{ *pnd = nd; }
|
{ *pnd = nd; }
|
||||||
|
@ -152,7 +152,7 @@ term(struct node **pnd;)
|
||||||
[
|
[
|
||||||
/* MulOperator */
|
/* MulOperator */
|
||||||
[ '*' | '/' | DIV | MOD | AND ]
|
[ '*' | '/' | DIV | MOD | AND ]
|
||||||
{ nd = MkNode(Oper, nd, NULLNODE, &dot); }
|
{ nd = dot2node(Oper, nd, NULLNODE); }
|
||||||
factor(&(nd->nd_right))
|
factor(&(nd->nd_right))
|
||||||
]*
|
]*
|
||||||
{ *pnd = nd; }
|
{ *pnd = nd; }
|
||||||
|
@ -172,7 +172,7 @@ factor(register struct node **p;)
|
||||||
[
|
[
|
||||||
designator_tail(p)?
|
designator_tail(p)?
|
||||||
[
|
[
|
||||||
{ *p = MkNode(Call, *p, NULLNODE, &dot); }
|
{ *p = dot2node(Call, *p, NULLNODE); }
|
||||||
ActualParameters(&((*p)->nd_right))
|
ActualParameters(&((*p)->nd_right))
|
||||||
]?
|
]?
|
||||||
|
|
|
|
||||||
|
@ -189,11 +189,11 @@ factor(register struct node **p;)
|
||||||
REAL
|
REAL
|
||||||
|
|
|
|
||||||
STRING
|
STRING
|
||||||
] { *p = MkLeaf(Value, &dot);
|
] { *p = dot2leaf(Value);
|
||||||
(*p)->nd_type = toktype;
|
(*p)->nd_type = toktype;
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
'(' { nd = MkLeaf(Uoper, &dot); }
|
'(' { nd = dot2leaf(Uoper); }
|
||||||
expression(p)
|
expression(p)
|
||||||
{ /* In some cases we must leave the '(' as an unary
|
{ /* In some cases we must leave the '(' as an unary
|
||||||
operator, because otherwise we cannot see that the
|
operator, because otherwise we cannot see that the
|
||||||
|
@ -212,7 +212,7 @@ factor(register struct node **p;)
|
||||||
}
|
}
|
||||||
')'
|
')'
|
||||||
|
|
|
|
||||||
NOT { *p = MkLeaf(Uoper, &dot); }
|
NOT { *p = dot2leaf(Uoper); }
|
||||||
factor(&((*p)->nd_right))
|
factor(&((*p)->nd_right))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ bare_set(struct node **pnd;)
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
} :
|
} :
|
||||||
'{' { dot.tk_symb = SET;
|
'{' { dot.tk_symb = SET;
|
||||||
*pnd = nd = MkLeaf(Xset, &dot);
|
*pnd = nd = dot2leaf(Xset);
|
||||||
nd->nd_type = bitset_type;
|
nd->nd_type = bitset_type;
|
||||||
}
|
}
|
||||||
[
|
[
|
||||||
|
@ -244,10 +244,10 @@ element(register struct node *nd;)
|
||||||
expression(&nd1)
|
expression(&nd1)
|
||||||
[
|
[
|
||||||
UPTO
|
UPTO
|
||||||
{ nd1 = MkNode(Link, nd1, NULLNODE, &dot);}
|
{ nd1 = dot2node(Link, nd1, NULLNODE);}
|
||||||
expression(&(nd1->nd_right))
|
expression(&(nd1->nd_right))
|
||||||
]?
|
]?
|
||||||
{ nd->nd_right = MkNode(Link, nd1, NULLNODE, &dot);
|
{ nd->nd_right = dot2node(Link, nd1, NULLNODE);
|
||||||
nd->nd_right->nd_symb = ',';
|
nd->nd_right->nd_symb = ',';
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -273,18 +273,18 @@ visible_designator_tail(struct node **pnd;)
|
||||||
register struct node *nd = *pnd;
|
register struct node *nd = *pnd;
|
||||||
}:
|
}:
|
||||||
[
|
[
|
||||||
'[' { nd = MkNode(Arrsel, nd, NULLNODE, &dot); }
|
'[' { nd = dot2node(Arrsel, nd, NULLNODE); }
|
||||||
expression(&(nd->nd_right))
|
expression(&(nd->nd_right))
|
||||||
[
|
[
|
||||||
','
|
','
|
||||||
{ nd = MkNode(Arrsel, nd, NULLNODE, &dot);
|
{ nd = dot2node(Arrsel, nd, NULLNODE);
|
||||||
nd->nd_symb = '[';
|
nd->nd_symb = '[';
|
||||||
}
|
}
|
||||||
expression(&(nd->nd_right))
|
expression(&(nd->nd_right))
|
||||||
]*
|
]*
|
||||||
']'
|
']'
|
||||||
|
|
|
|
||||||
'^' { nd = MkNode(Arrow, NULLNODE, nd, &dot); }
|
'^' { nd = dot2node(Arrow, NULLNODE, nd); }
|
||||||
]
|
]
|
||||||
{ *pnd = nd; }
|
{ *pnd = nd; }
|
||||||
;
|
;
|
||||||
|
|
|
@ -40,6 +40,7 @@ int pass_1;
|
||||||
struct def *Defined;
|
struct def *Defined;
|
||||||
extern int err_occurred;
|
extern int err_occurred;
|
||||||
extern int fp_used; /* set if floating point used */
|
extern int fp_used; /* set if floating point used */
|
||||||
|
struct node *EmptyStatement;
|
||||||
|
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
register char **argv;
|
register char **argv;
|
||||||
|
@ -86,6 +87,8 @@ Compile(src, dst)
|
||||||
InitScope();
|
InitScope();
|
||||||
InitTypes();
|
InitTypes();
|
||||||
AddStandards();
|
AddStandards();
|
||||||
|
EmptyStatement = dot2leaf(Stat);
|
||||||
|
EmptyStatement->nd_symb = ';';
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (options['l']) {
|
if (options['l']) {
|
||||||
LexScan();
|
LexScan();
|
||||||
|
|
|
@ -43,7 +43,7 @@ struct node {
|
||||||
|
|
||||||
/* ALLOCDEF "node" 50 */
|
/* ALLOCDEF "node" 50 */
|
||||||
|
|
||||||
extern struct node *MkNode(), *MkLeaf();
|
extern struct node *MkNode(), *MkLeaf(), *dot2node(), *dot2leaf();
|
||||||
|
|
||||||
#define NULLNODE ((struct node *) 0)
|
#define NULLNODE ((struct node *) 0)
|
||||||
|
|
||||||
|
|
|
@ -37,18 +37,30 @@ MkNode(class, left, right, token)
|
||||||
return nd;
|
return nd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct node *
|
||||||
|
dot2node(class, left, right)
|
||||||
|
struct node *left, *right;
|
||||||
|
{
|
||||||
|
return MkNode(class, left, right, &dot);
|
||||||
|
}
|
||||||
|
|
||||||
struct node *
|
struct node *
|
||||||
MkLeaf(class, token)
|
MkLeaf(class, token)
|
||||||
struct token *token;
|
struct token *token;
|
||||||
{
|
{
|
||||||
register struct node *nd = new_node();
|
register struct node *nd = new_node();
|
||||||
|
|
||||||
nd->nd_left = nd->nd_right = 0;
|
|
||||||
nd->nd_token = *token;
|
nd->nd_token = *token;
|
||||||
nd->nd_class = class;
|
nd->nd_class = class;
|
||||||
return nd;
|
return nd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct node *
|
||||||
|
dot2leaf(class)
|
||||||
|
{
|
||||||
|
return MkLeaf(class, &dot);
|
||||||
|
}
|
||||||
|
|
||||||
FreeNode(nd)
|
FreeNode(nd)
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
{
|
{
|
||||||
|
|
|
@ -99,7 +99,7 @@ import(int local;)
|
||||||
extern struct def *GetDefinitionModule();
|
extern struct def *GetDefinitionModule();
|
||||||
} :
|
} :
|
||||||
[ FROM
|
[ FROM
|
||||||
IDENT { FromId = MkLeaf(Name, &dot);
|
IDENT { FromId = dot2leaf(Name);
|
||||||
if (local) df = lookfor(FromId,enclosing(CurrVis),0);
|
if (local) df = lookfor(FromId,enclosing(CurrVis),0);
|
||||||
else df = GetDefinitionModule(dot.TOK_IDF, 1);
|
else df = GetDefinitionModule(dot.TOK_IDF, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
static int loopcount = 0; /* Count nested loops */
|
static int loopcount = 0; /* Count nested loops */
|
||||||
|
extern struct node *EmptyStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
statement(register struct node **pnd;)
|
statement(register struct node **pnd;)
|
||||||
|
@ -35,7 +36,7 @@ statement(register struct node **pnd;)
|
||||||
* but this gives LL(1) conflicts
|
* but this gives LL(1) conflicts
|
||||||
*/
|
*/
|
||||||
designator(pnd)
|
designator(pnd)
|
||||||
[ { nd = MkNode(Call, *pnd, NULLNODE, &dot);
|
[ { nd = dot2node(Call, *pnd, NULLNODE);
|
||||||
nd->nd_symb = '(';
|
nd->nd_symb = '(';
|
||||||
}
|
}
|
||||||
ActualParameters(&(nd->nd_right))?
|
ActualParameters(&(nd->nd_right))?
|
||||||
|
@ -45,7 +46,7 @@ statement(register struct node **pnd;)
|
||||||
DOT = BECOMES;
|
DOT = BECOMES;
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
{ nd = MkNode(Stat, *pnd, NULLNODE, &dot); }
|
{ nd = dot2node(Stat, *pnd, NULLNODE); }
|
||||||
expression(&(nd->nd_right))
|
expression(&(nd->nd_right))
|
||||||
]
|
]
|
||||||
{ *pnd = nd; }
|
{ *pnd = nd; }
|
||||||
|
@ -57,19 +58,19 @@ statement(register struct node **pnd;)
|
||||||
|
|
|
|
||||||
CaseStatement(pnd)
|
CaseStatement(pnd)
|
||||||
|
|
|
|
||||||
WHILE { *pnd = nd = MkLeaf(Stat, &dot); }
|
WHILE { *pnd = nd = dot2leaf(Stat); }
|
||||||
expression(&(nd->nd_left))
|
expression(&(nd->nd_left))
|
||||||
DO
|
DO
|
||||||
StatementSequence(&(nd->nd_right))
|
StatementSequence(&(nd->nd_right))
|
||||||
END
|
END
|
||||||
|
|
|
|
||||||
REPEAT { *pnd = nd = MkLeaf(Stat, &dot); }
|
REPEAT { *pnd = nd = dot2leaf(Stat); }
|
||||||
StatementSequence(&(nd->nd_left))
|
StatementSequence(&(nd->nd_left))
|
||||||
UNTIL
|
UNTIL
|
||||||
expression(&(nd->nd_right))
|
expression(&(nd->nd_right))
|
||||||
|
|
|
|
||||||
{ loopcount++; }
|
{ loopcount++; }
|
||||||
LOOP { *pnd = nd = MkLeaf(Stat, &dot); }
|
LOOP { *pnd = nd = dot2leaf(Stat); }
|
||||||
StatementSequence(&((*pnd)->nd_right))
|
StatementSequence(&((*pnd)->nd_right))
|
||||||
END
|
END
|
||||||
{ loopcount--; }
|
{ loopcount--; }
|
||||||
|
@ -80,13 +81,13 @@ statement(register struct node **pnd;)
|
||||||
|
|
|
|
||||||
EXIT
|
EXIT
|
||||||
{ if (!loopcount) error("EXIT not in a LOOP");
|
{ if (!loopcount) error("EXIT not in a LOOP");
|
||||||
*pnd = MkLeaf(Stat, &dot);
|
*pnd = dot2leaf(Stat);
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
ReturnStatement(pnd)
|
ReturnStatement(pnd)
|
||||||
{ return_occurred = 1; }
|
{ return_occurred = 1; }
|
||||||
|
|
|
|
||||||
/* empty */ { *pnd = 0; }
|
/* empty */ { *pnd = EmptyStatement; }
|
||||||
;
|
;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -108,14 +109,11 @@ StatementSequence(register struct node **pnd;)
|
||||||
statement(pnd)
|
statement(pnd)
|
||||||
[ %persistent
|
[ %persistent
|
||||||
';' statement(&nd)
|
';' statement(&nd)
|
||||||
{ if (nd) {
|
{ register struct node *nd1 = dot2node(Link, *pnd, nd);
|
||||||
register struct node *nd1 =
|
|
||||||
MkNode(Link, *pnd, nd, &dot);
|
|
||||||
|
|
||||||
*pnd = nd1;
|
*pnd = nd1;
|
||||||
nd1->nd_symb = ';';
|
nd1->nd_symb = ';';
|
||||||
pnd = &(nd1->nd_right);
|
pnd = &(nd1->nd_right);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]*
|
]*
|
||||||
;
|
;
|
||||||
|
@ -124,21 +122,21 @@ IfStatement(struct node **pnd;)
|
||||||
{
|
{
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
} :
|
} :
|
||||||
IF { nd = MkLeaf(Stat, &dot);
|
IF { nd = dot2leaf(Stat);
|
||||||
*pnd = nd;
|
*pnd = nd;
|
||||||
}
|
}
|
||||||
expression(&(nd->nd_left))
|
expression(&(nd->nd_left))
|
||||||
THEN { nd->nd_right = MkLeaf(Link, &dot);
|
THEN { nd->nd_right = dot2leaf(Link);
|
||||||
nd = nd->nd_right;
|
nd = nd->nd_right;
|
||||||
}
|
}
|
||||||
StatementSequence(&(nd->nd_left))
|
StatementSequence(&(nd->nd_left))
|
||||||
[
|
[
|
||||||
ELSIF { nd->nd_right = MkLeaf(Stat, &dot);
|
ELSIF { nd->nd_right = dot2leaf(Stat);
|
||||||
nd = nd->nd_right;
|
nd = nd->nd_right;
|
||||||
nd->nd_symb = IF;
|
nd->nd_symb = IF;
|
||||||
}
|
}
|
||||||
expression(&(nd->nd_left))
|
expression(&(nd->nd_left))
|
||||||
THEN { nd->nd_right = MkLeaf(Link, &dot);
|
THEN { nd->nd_right = dot2leaf(Link);
|
||||||
nd = nd->nd_right;
|
nd = nd->nd_right;
|
||||||
}
|
}
|
||||||
StatementSequence(&(nd->nd_left))
|
StatementSequence(&(nd->nd_left))
|
||||||
|
@ -155,7 +153,7 @@ CaseStatement(struct node **pnd;)
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
struct type *tp = 0;
|
struct type *tp = 0;
|
||||||
} :
|
} :
|
||||||
CASE { *pnd = nd = MkLeaf(Stat, &dot); }
|
CASE { *pnd = nd = dot2leaf(Stat); }
|
||||||
expression(&(nd->nd_left))
|
expression(&(nd->nd_left))
|
||||||
OF
|
OF
|
||||||
case(&(nd->nd_right), &tp)
|
case(&(nd->nd_right), &tp)
|
||||||
|
@ -166,21 +164,16 @@ CaseStatement(struct node **pnd;)
|
||||||
{ nd = nd->nd_right; }
|
{ nd = nd->nd_right; }
|
||||||
]*
|
]*
|
||||||
[ ELSE StatementSequence(&(nd->nd_right))
|
[ ELSE StatementSequence(&(nd->nd_right))
|
||||||
{ if (! nd->nd_right) {
|
|
||||||
nd->nd_right = MkLeaf(Stat, &dot);
|
|
||||||
nd->nd_right->nd_symb = ';';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]?
|
]?
|
||||||
END
|
END
|
||||||
;
|
;
|
||||||
|
|
||||||
case(struct node **pnd; struct type **ptp;) :
|
case(struct node **pnd; struct type **ptp;) :
|
||||||
[ CaseLabelList(ptp, pnd)
|
[ CaseLabelList(ptp, pnd)
|
||||||
':' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); }
|
':' { *pnd = dot2node(Link, *pnd, NULLNODE); }
|
||||||
StatementSequence(&((*pnd)->nd_right))
|
StatementSequence(&((*pnd)->nd_right))
|
||||||
]?
|
]?
|
||||||
{ *pnd = MkNode(Link, *pnd, NULLNODE, &dot);
|
{ *pnd = dot2node(Link, *pnd, NULLNODE);
|
||||||
(*pnd)->nd_symb = '|';
|
(*pnd)->nd_symb = '|';
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -190,7 +183,7 @@ WhileStatement(struct node **pnd;)
|
||||||
{
|
{
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
}:
|
}:
|
||||||
WHILE { *pnd = nd = MkLeaf(Stat, &dot); }
|
WHILE { *pnd = nd = dot2leaf(Stat); }
|
||||||
expression(&(nd->nd_left))
|
expression(&(nd->nd_left))
|
||||||
DO
|
DO
|
||||||
StatementSequence(&(nd->nd_right))
|
StatementSequence(&(nd->nd_right))
|
||||||
|
@ -201,7 +194,7 @@ RepeatStatement(struct node **pnd;)
|
||||||
{
|
{
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
}:
|
}:
|
||||||
REPEAT { *pnd = nd = MkLeaf(Stat, &dot); }
|
REPEAT { *pnd = nd = dot2leaf(Stat); }
|
||||||
StatementSequence(&(nd->nd_left))
|
StatementSequence(&(nd->nd_left))
|
||||||
UNTIL
|
UNTIL
|
||||||
expression(&(nd->nd_right))
|
expression(&(nd->nd_right))
|
||||||
|
@ -213,9 +206,9 @@ ForStatement(struct node **pnd;)
|
||||||
register struct node *nd, *nd1;
|
register struct node *nd, *nd1;
|
||||||
struct node *dummy;
|
struct node *dummy;
|
||||||
}:
|
}:
|
||||||
FOR { *pnd = nd = MkLeaf(Stat, &dot); }
|
FOR { *pnd = nd = dot2leaf(Stat); }
|
||||||
IDENT { nd->nd_IDF = dot.TOK_IDF; }
|
IDENT { nd->nd_IDF = dot.TOK_IDF; }
|
||||||
BECOMES { nd->nd_left = nd1 = MkLeaf(Stat, &dot); }
|
BECOMES { nd->nd_left = nd1 = dot2leaf(Stat); }
|
||||||
expression(&(nd1->nd_left))
|
expression(&(nd1->nd_left))
|
||||||
TO
|
TO
|
||||||
expression(&(nd1->nd_right))
|
expression(&(nd1->nd_right))
|
||||||
|
@ -238,7 +231,7 @@ ForStatement(struct node **pnd;)
|
||||||
|
|
||||||
/* inline in Statement; lack of space
|
/* inline in Statement; lack of space
|
||||||
LoopStatement(struct node **pnd;):
|
LoopStatement(struct node **pnd;):
|
||||||
LOOP { *pnd = MkLeaf(Stat, &dot); }
|
LOOP { *pnd = dot2leaf(Stat); }
|
||||||
StatementSequence(&((*pnd)->nd_right))
|
StatementSequence(&((*pnd)->nd_right))
|
||||||
END
|
END
|
||||||
;
|
;
|
||||||
|
@ -248,7 +241,7 @@ WithStatement(struct node **pnd;)
|
||||||
{
|
{
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
}:
|
}:
|
||||||
WITH { *pnd = nd = MkLeaf(Stat, &dot); }
|
WITH { *pnd = nd = dot2leaf(Stat); }
|
||||||
designator(&(nd->nd_left))
|
designator(&(nd->nd_left))
|
||||||
DO
|
DO
|
||||||
StatementSequence(&(nd->nd_right))
|
StatementSequence(&(nd->nd_right))
|
||||||
|
@ -261,7 +254,7 @@ ReturnStatement(struct node **pnd;)
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
} :
|
} :
|
||||||
|
|
||||||
RETURN { *pnd = nd = MkLeaf(Stat, &dot); }
|
RETURN { *pnd = nd = dot2leaf(Stat); }
|
||||||
[
|
[
|
||||||
expression(&(nd->nd_right))
|
expression(&(nd->nd_right))
|
||||||
{ if (scopeclosed(CurrentScope)) {
|
{ if (scopeclosed(CurrentScope)) {
|
||||||
|
|
|
@ -396,6 +396,16 @@ WalkCall(nd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC
|
||||||
|
ForLoopVarExpr(nd)
|
||||||
|
register struct node *nd;
|
||||||
|
{
|
||||||
|
register struct type *tp;
|
||||||
|
|
||||||
|
CodePExpr(nd);
|
||||||
|
CodeCoercion(tp, BaseType(tp));
|
||||||
|
}
|
||||||
|
|
||||||
WalkStat(nd, exit_label)
|
WalkStat(nd, exit_label)
|
||||||
register struct node *nd;
|
register struct node *nd;
|
||||||
label exit_label;
|
label exit_label;
|
||||||
|
@ -430,9 +440,9 @@ WalkStat(nd, exit_label)
|
||||||
C_bra(l2);
|
C_bra(l2);
|
||||||
C_df_ilb(l1);
|
C_df_ilb(l1);
|
||||||
WalkNode(right->nd_right, exit_label);
|
WalkNode(right->nd_right, exit_label);
|
||||||
C_df_ilb(l2);
|
l1 = l2;
|
||||||
}
|
}
|
||||||
else C_df_ilb(l1);
|
C_df_ilb(l1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,20 +493,21 @@ WalkStat(nd, exit_label)
|
||||||
label l2 = ++text_label;
|
label l2 = ++text_label;
|
||||||
int uns = 0;
|
int uns = 0;
|
||||||
arith stepsize;
|
arith stepsize;
|
||||||
|
struct type *bstp;
|
||||||
|
|
||||||
good_forvar = DoForInit(nd);
|
good_forvar = DoForInit(nd);
|
||||||
if ((stepsize = left->nd_INT) == 0) {
|
if ((stepsize = left->nd_INT) == 0) {
|
||||||
node_warning(left,
|
node_warning(left,
|
||||||
W_ORDINARY,
|
W_ORDINARY,
|
||||||
"zero stepsize in FOR loop");
|
"zero stepsize in FOR loop");
|
||||||
}
|
}
|
||||||
if (stepsize < 0) {
|
if (stepsize < 0) {
|
||||||
stepsize = -stepsize;
|
stepsize = -stepsize;
|
||||||
}
|
}
|
||||||
fnd = left->nd_right;
|
fnd = left->nd_right;
|
||||||
if (good_forvar) {
|
if (good_forvar) {
|
||||||
uns = BaseType(nd->nd_type)->tp_fund !=
|
bstp = BaseType(nd->nd_type);
|
||||||
T_INTEGER;
|
uns = bstp->tp_fund != T_INTEGER;
|
||||||
C_dup(int_size);
|
C_dup(int_size);
|
||||||
CodePExpr(fnd);
|
CodePExpr(fnd);
|
||||||
tmp = NewInt();
|
tmp = NewInt();
|
||||||
|
@ -504,16 +515,17 @@ WalkStat(nd, exit_label)
|
||||||
C_lol(tmp);
|
C_lol(tmp);
|
||||||
if (uns) C_cmu(int_size);
|
if (uns) C_cmu(int_size);
|
||||||
else C_cmi(int_size);
|
else C_cmi(int_size);
|
||||||
|
RangeCheck(bstp, nd->nd_type);
|
||||||
if (left->nd_INT >= 0) {
|
if (left->nd_INT >= 0) {
|
||||||
C_zgt(l2);
|
C_zgt(l2);
|
||||||
CodeDStore(nd);
|
CodeDStore(nd);
|
||||||
C_lol(tmp);
|
C_lol(tmp);
|
||||||
CodePExpr(nd);
|
ForLoopVarExpr(nd);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
C_zlt(l2);
|
C_zlt(l2);
|
||||||
|
C_dup(int_size);
|
||||||
CodeDStore(nd);
|
CodeDStore(nd);
|
||||||
CodePExpr(nd);
|
|
||||||
C_lol(tmp);
|
C_lol(tmp);
|
||||||
}
|
}
|
||||||
C_sbu(int_size);
|
C_sbu(int_size);
|
||||||
|
@ -534,8 +546,9 @@ WalkStat(nd, exit_label)
|
||||||
C_dup(int_size);
|
C_dup(int_size);
|
||||||
C_zeq(l2);
|
C_zeq(l2);
|
||||||
C_loc(left->nd_INT);
|
C_loc(left->nd_INT);
|
||||||
CodePExpr(nd);
|
ForLoopVarExpr(nd);
|
||||||
C_adu(int_size);
|
C_adu(int_size);
|
||||||
|
RangeCheck(bstp, nd->nd_type);
|
||||||
CodeDStore(nd);
|
CodeDStore(nd);
|
||||||
}
|
}
|
||||||
C_bra(l1);
|
C_bra(l1);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
extern int (*WalkTable[])();
|
extern int (*WalkTable[])();
|
||||||
|
|
||||||
#define WalkNode(xnd, xlab) if (! xnd) ; else (*WalkTable[(xnd)->nd_class])((xnd), (xlab))
|
#define WalkNode(xnd, xlab) (*WalkTable[(xnd)->nd_class])((xnd), (xlab))
|
||||||
|
|
||||||
extern label text_label;
|
extern label text_label;
|
||||||
extern label data_label;
|
extern label data_label;
|
||||||
|
|
Loading…
Add table
Reference in a new issue