ack/lang/m2/comp/expression.g

161 lines
2.2 KiB
Plaintext
Raw Normal View History

1986-03-27 17:37:41 +00:00
/* E X P R E S S I O N S */
1986-03-20 14:52:03 +00:00
{
static char *RcsId = "$Header$";
1986-03-27 17:37:41 +00:00
#include <alloc.h>
#include <em_arith.h>
#include <em_label.h>
#include "LLlex.h"
#include "idf.h"
#include "def.h"
#include "scope.h"
1986-03-20 14:52:03 +00:00
}
number:
INTEGER
|
REAL
;
1986-03-27 17:37:41 +00:00
qualident(int types; struct def **pdf; char *str;)
{
int scope;
1986-04-02 17:34:21 +00:00
int module;
1986-03-27 17:37:41 +00:00
register struct def *df;
struct def *lookfor();
} :
IDENT { if (types) {
1986-04-03 00:44:39 +00:00
df = lookfor(dot.TOK_IDF, CurrentScope, 1);
*pdf = df;
1986-03-29 01:04:49 +00:00
if (df->df_kind == D_ERROR) types = 0;
1986-03-27 17:37:41 +00:00
}
}
[
{ if (types &&!(scope = has_selectors(df))) {
types = 0;
*pdf = ill_df;
}
}
/* selector */
'.' IDENT
{ if (types) {
1986-04-02 17:34:21 +00:00
module = (df->df_kind == D_MODULE);
1986-03-27 17:37:41 +00:00
df = lookup(dot.TOK_IDF, scope);
if (!df) {
types = 0;
df = ill_df;
1986-04-03 17:41:26 +00:00
id_not_declared(dot.TOK_IDF);
1986-03-27 17:37:41 +00:00
}
1986-04-02 17:34:21 +00:00
else
if (module &&
!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) {
error("identifier \"%s\" not exported from qualifying module", dot.TOK_IDF->id_text);
}
1986-03-27 17:37:41 +00:00
}
}
]*
{ if (types && !(types & df->df_kind)) {
error("identifier \"%s\" is not a %s",
1986-03-29 01:04:49 +00:00
df->df_idf->id_text, str);
1986-03-27 17:37:41 +00:00
}
}
1986-03-20 14:52:03 +00:00
;
selector:
'.' /* field */ IDENT
;
ExpList:
expression [ ',' expression ]*
;
ConstExpression:
expression
/*
* Changed rule in new Modula-2.
* Check that the expression is a constant expression and evaluate!
*/
;
expression:
SimpleExpression [ relation SimpleExpression ]?
;
relation:
'=' | '#' | UNEQUAL | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN
;
SimpleExpression:
[ '+' | '-' ]? term [ AddOperator term ]*
;
AddOperator:
'+' | '-' | OR
;
term:
factor [ MulOperator factor ]*
;
MulOperator:
'*' | '/' | DIV | MOD | AND | '&'
;
1986-03-27 17:37:41 +00:00
factor
{
struct def *df;
} :
qualident(0, &df, (char *) 0)
1986-03-20 14:52:03 +00:00
[
designator_tail? ActualParameters?
|
bare_set
]
|
bare_set
| %default
number
|
STRING
|
'(' expression ')'
|
NOT factor
;
bare_set:
'{' [ element [ ',' element ]* ]? '}'
;
ActualParameters:
'(' ExpList? ')'
;
element:
expression [ UPTO expression ]?
;
1986-03-27 17:37:41 +00:00
designator
{
struct def *df;
} :
qualident(0, &df, (char *) 0)
designator_tail?
1986-03-20 14:52:03 +00:00
;
designator_tail:
visible_designator_tail
1986-03-27 17:37:41 +00:00
[
selector
|
visible_designator_tail
]*
1986-03-20 14:52:03 +00:00
;
visible_designator_tail:
1986-03-27 17:37:41 +00:00
'[' ExpList ']'
|
'^'
1986-03-20 14:52:03 +00:00
;