1986-03-26 15:11:02 +00:00
|
|
|
/* S T A T E M E N T S */
|
|
|
|
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
1986-05-01 19:06:53 +00:00
|
|
|
#ifndef NORCSID
|
1986-03-20 14:52:03 +00:00
|
|
|
static char *RcsId = "$Header$";
|
1986-05-01 19:06:53 +00:00
|
|
|
#endif
|
1986-04-06 17:42:56 +00:00
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
#include <assert.h>
|
1986-04-06 17:42:56 +00:00
|
|
|
#include <em_arith.h>
|
1986-04-17 09:28:09 +00:00
|
|
|
#include <em_label.h>
|
1986-04-28 18:06:58 +00:00
|
|
|
|
1986-04-22 22:36:16 +00:00
|
|
|
#include "idf.h"
|
1986-04-06 17:42:56 +00:00
|
|
|
#include "LLlex.h"
|
1986-04-22 22:36:16 +00:00
|
|
|
#include "scope.h"
|
|
|
|
#include "def.h"
|
1986-04-17 09:28:09 +00:00
|
|
|
#include "type.h"
|
1986-04-06 17:42:56 +00:00
|
|
|
#include "node.h"
|
1986-04-15 17:51:53 +00:00
|
|
|
|
|
|
|
static int loopcount = 0; /* Count nested loops */
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
|
|
|
|
1986-06-04 09:01:48 +00:00
|
|
|
statement(register struct node **pnd;)
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
1986-04-17 09:28:09 +00:00
|
|
|
register struct node *nd;
|
1986-04-06 17:42:56 +00:00
|
|
|
} :
|
1986-03-20 14:52:03 +00:00
|
|
|
/*
|
|
|
|
* This part is not in the reference grammar. The reference grammar
|
|
|
|
* states : assignment | ProcedureCall | ...
|
|
|
|
* but this gives LL(1) conflicts
|
|
|
|
*/
|
1986-04-17 09:28:09 +00:00
|
|
|
designator(pnd)
|
|
|
|
[ { nd = MkNode(Call, *pnd, NULLNODE, &dot);
|
|
|
|
nd->nd_symb = '(';
|
1986-04-09 18:14:49 +00:00
|
|
|
}
|
1986-04-17 09:28:09 +00:00
|
|
|
ActualParameters(&(nd->nd_right))?
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
1986-04-17 09:28:09 +00:00
|
|
|
BECOMES { nd = MkNode(Stat, *pnd, NULLNODE, &dot); }
|
|
|
|
expression(&(nd->nd_right))
|
1986-03-20 14:52:03 +00:00
|
|
|
]
|
1986-04-17 09:28:09 +00:00
|
|
|
{ *pnd = nd; }
|
1986-03-20 14:52:03 +00:00
|
|
|
/*
|
|
|
|
* end of changed part
|
|
|
|
*/
|
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
IfStatement(pnd)
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
CaseStatement(pnd)
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
WhileStatement(pnd)
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
RepeatStatement(pnd)
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
{ loopcount++; }
|
|
|
|
LoopStatement(pnd)
|
|
|
|
{ loopcount--; }
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
ForStatement(pnd)
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
WithStatement(pnd)
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
|
EXIT
|
1986-05-30 18:48:00 +00:00
|
|
|
{ if (!loopcount) error("EXIT not in a LOOP");
|
1986-06-04 09:01:48 +00:00
|
|
|
*pnd = MkLeaf(Stat, &dot);
|
1986-04-15 17:51:53 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
1986-05-30 18:48:00 +00:00
|
|
|
ReturnStatement(pnd)
|
1986-06-04 09:01:48 +00:00
|
|
|
|
|
|
|
|
/* empty */ { *pnd = 0; }
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The next two rules in-line in "Statement", because of an LL(1) conflict
|
|
|
|
|
|
|
|
assignment:
|
|
|
|
designator BECOMES expression
|
|
|
|
;
|
|
|
|
|
|
|
|
ProcedureCall:
|
|
|
|
designator ActualParameters?
|
|
|
|
;
|
|
|
|
*/
|
|
|
|
|
1986-06-04 09:01:48 +00:00
|
|
|
StatementSequence(register struct node **pnd;)
|
|
|
|
{
|
1986-06-17 12:04:05 +00:00
|
|
|
struct node *nd;
|
1986-06-04 09:01:48 +00:00
|
|
|
} :
|
1986-04-15 17:51:53 +00:00
|
|
|
statement(pnd)
|
|
|
|
[
|
1986-06-17 12:04:05 +00:00
|
|
|
';' statement(&nd)
|
|
|
|
{ if (nd) {
|
|
|
|
*pnd = MkNode(Link, *pnd, nd, &dot);
|
|
|
|
(*pnd)->nd_symb = ';';
|
|
|
|
pnd = &((*pnd)->nd_right);
|
|
|
|
}
|
1986-04-15 17:51:53 +00:00
|
|
|
}
|
|
|
|
]*
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
IfStatement(struct node **pnd;)
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
1986-04-15 17:51:53 +00:00
|
|
|
register struct node *nd;
|
1986-04-06 17:42:56 +00:00
|
|
|
} :
|
1986-06-04 09:01:48 +00:00
|
|
|
IF { nd = MkLeaf(Stat, &dot);
|
1986-04-15 17:51:53 +00:00
|
|
|
*pnd = nd;
|
|
|
|
}
|
|
|
|
expression(&(nd->nd_left))
|
1986-06-04 09:01:48 +00:00
|
|
|
THEN { nd->nd_right = MkLeaf(Link, &dot);
|
|
|
|
nd = nd->nd_right;
|
1986-04-15 17:51:53 +00:00
|
|
|
}
|
|
|
|
StatementSequence(&(nd->nd_left))
|
|
|
|
[
|
1986-06-04 09:01:48 +00:00
|
|
|
ELSIF { nd->nd_right = MkLeaf(Stat, &dot);
|
1986-04-15 17:51:53 +00:00
|
|
|
nd = nd->nd_right;
|
|
|
|
nd->nd_symb = IF;
|
|
|
|
}
|
|
|
|
expression(&(nd->nd_left))
|
1986-06-04 09:01:48 +00:00
|
|
|
THEN { nd->nd_right = MkLeaf(Link, &dot);
|
1986-04-15 17:51:53 +00:00
|
|
|
nd = nd->nd_right;
|
|
|
|
}
|
|
|
|
StatementSequence(&(nd->nd_left))
|
|
|
|
]*
|
|
|
|
[
|
|
|
|
ELSE
|
|
|
|
StatementSequence(&(nd->nd_right))
|
|
|
|
]?
|
1986-03-20 14:52:03 +00:00
|
|
|
END
|
|
|
|
;
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
CaseStatement(struct node **pnd;)
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
1986-04-15 17:51:53 +00:00
|
|
|
register struct node *nd;
|
|
|
|
struct type *tp = 0;
|
1986-04-06 17:42:56 +00:00
|
|
|
} :
|
1986-06-04 09:01:48 +00:00
|
|
|
CASE { *pnd = nd = MkLeaf(Stat, &dot); }
|
1986-04-15 17:51:53 +00:00
|
|
|
expression(&(nd->nd_left))
|
|
|
|
OF
|
|
|
|
case(&(nd->nd_right), &tp)
|
|
|
|
{ nd = nd->nd_right; }
|
|
|
|
[
|
|
|
|
'|'
|
|
|
|
case(&(nd->nd_right), &tp)
|
|
|
|
{ nd = nd->nd_right; }
|
|
|
|
]*
|
|
|
|
[ ELSE StatementSequence(&(nd->nd_right)) ]?
|
1986-03-20 14:52:03 +00:00
|
|
|
END
|
|
|
|
;
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
case(struct node **pnd; struct type **ptp;) :
|
1986-04-17 09:28:09 +00:00
|
|
|
[ CaseLabelList(ptp, pnd)
|
1986-04-15 17:51:53 +00:00
|
|
|
':' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); }
|
|
|
|
StatementSequence(&((*pnd)->nd_right))
|
|
|
|
]?
|
|
|
|
{ *pnd = MkNode(Link, *pnd, NULLNODE, &dot);
|
|
|
|
(*pnd)->nd_symb = '|';
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
WhileStatement(struct node **pnd;)
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
1986-04-15 17:51:53 +00:00
|
|
|
register struct node *nd;
|
1986-04-06 17:42:56 +00:00
|
|
|
}:
|
1986-06-04 09:01:48 +00:00
|
|
|
WHILE { *pnd = nd = MkLeaf(Stat, &dot); }
|
1986-04-15 17:51:53 +00:00
|
|
|
expression(&(nd->nd_left))
|
|
|
|
DO
|
|
|
|
StatementSequence(&(nd->nd_right))
|
|
|
|
END
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
RepeatStatement(struct node **pnd;)
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
1986-04-15 17:51:53 +00:00
|
|
|
register struct node *nd;
|
1986-04-06 17:42:56 +00:00
|
|
|
}:
|
1986-06-04 09:01:48 +00:00
|
|
|
REPEAT { *pnd = nd = MkLeaf(Stat, &dot); }
|
1986-04-15 17:51:53 +00:00
|
|
|
StatementSequence(&(nd->nd_left))
|
|
|
|
UNTIL
|
|
|
|
expression(&(nd->nd_right))
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
ForStatement(struct node **pnd;)
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
1986-04-15 17:51:53 +00:00
|
|
|
register struct node *nd;
|
1986-05-30 18:48:00 +00:00
|
|
|
struct node *dummy;
|
1986-04-06 17:42:56 +00:00
|
|
|
}:
|
1986-06-04 09:01:48 +00:00
|
|
|
FOR { *pnd = nd = MkLeaf(Stat, &dot); }
|
|
|
|
IDENT { nd->nd_IDF = dot.TOK_IDF; }
|
|
|
|
BECOMES { nd->nd_left = MkLeaf(Stat, &dot);
|
|
|
|
nd = nd->nd_left;
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
expression(&(nd->nd_left))
|
|
|
|
TO
|
1986-04-15 17:51:53 +00:00
|
|
|
expression(&(nd->nd_right))
|
|
|
|
[
|
1986-05-30 18:48:00 +00:00
|
|
|
BY
|
|
|
|
ConstExpression(&dummy)
|
1986-07-08 14:59:02 +00:00
|
|
|
{ if (!(dummy->nd_type->tp_fund & T_INTORCARD)) {
|
1986-05-30 18:48:00 +00:00
|
|
|
error("illegal type in BY clause");
|
|
|
|
}
|
|
|
|
nd->nd_INT = dummy->nd_INT;
|
|
|
|
FreeNode(dummy);
|
1986-04-15 17:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
1986-05-30 18:48:00 +00:00
|
|
|
{ nd->nd_INT = 1; }
|
1986-04-15 17:51:53 +00:00
|
|
|
]
|
|
|
|
DO
|
|
|
|
StatementSequence(&((*pnd)->nd_right))
|
|
|
|
END
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
LoopStatement(struct node **pnd;):
|
1986-06-04 09:01:48 +00:00
|
|
|
LOOP { *pnd = MkLeaf(Stat, &dot); }
|
1986-04-15 17:51:53 +00:00
|
|
|
StatementSequence(&((*pnd)->nd_right))
|
|
|
|
END
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-15 17:51:53 +00:00
|
|
|
WithStatement(struct node **pnd;)
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
1986-04-15 17:51:53 +00:00
|
|
|
register struct node *nd;
|
1986-04-06 17:42:56 +00:00
|
|
|
}:
|
1986-06-04 09:01:48 +00:00
|
|
|
WITH { *pnd = nd = MkLeaf(Stat, &dot); }
|
1986-04-15 17:51:53 +00:00
|
|
|
designator(&(nd->nd_left))
|
|
|
|
DO
|
|
|
|
StatementSequence(&(nd->nd_right))
|
|
|
|
END
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
|
|
|
ReturnStatement(struct node **pnd;)
|
|
|
|
{
|
|
|
|
register struct def *df = CurrentScope->sc_definedby;
|
|
|
|
register struct node *nd;
|
1986-06-20 14:36:49 +00:00
|
|
|
extern int return_occurred;
|
1986-05-30 18:48:00 +00:00
|
|
|
} :
|
|
|
|
|
1986-06-20 14:36:49 +00:00
|
|
|
RETURN { *pnd = nd = MkLeaf(Stat, &dot);
|
|
|
|
return_occurred = 1;
|
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
[
|
|
|
|
expression(&(nd->nd_right))
|
|
|
|
{ if (scopeclosed(CurrentScope)) {
|
|
|
|
error("a module body has no result value");
|
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
else if (! ResultType(df->df_type)) {
|
1986-05-30 18:48:00 +00:00
|
|
|
error("procedure \"%s\" has no result value", df->df_idf->id_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
{ if (ResultType(df->df_type)) {
|
1986-05-30 18:48:00 +00:00
|
|
|
error("procedure \"%s\" must return a value", df->df_idf->id_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
;
|