1994-06-24 11:31:16 +00:00
|
|
|
/* $Id$ */
|
1987-03-09 21:59:22 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1987-01-06 15:16:53 +00:00
|
|
|
/* EXPRESSION SYNTAX PARSER */
|
|
|
|
|
|
|
|
%lexical LLlex;
|
|
|
|
%start If_expr, if_expression;
|
|
|
|
|
|
|
|
{
|
|
|
|
#include "LLlex.h"
|
1987-08-19 10:36:37 +00:00
|
|
|
#include <em_arith.h>
|
1987-01-06 15:16:53 +00:00
|
|
|
|
1987-08-19 10:36:37 +00:00
|
|
|
extern arith ifval;
|
1987-01-06 15:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if_expression
|
|
|
|
:
|
|
|
|
constant_expression(&ifval)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* 7.1 */
|
1987-08-19 10:36:37 +00:00
|
|
|
primary(arith *pval;)
|
1987-01-06 15:16:53 +00:00
|
|
|
:
|
|
|
|
constant(pval)
|
|
|
|
|
|
|
|
|
'(' expression(pval) ')'
|
|
|
|
;
|
|
|
|
|
1987-08-19 10:36:37 +00:00
|
|
|
unary(arith *pval;)
|
1987-01-06 15:16:53 +00:00
|
|
|
{int oper;}
|
|
|
|
:
|
|
|
|
unop(&oper)
|
|
|
|
unary(pval)
|
|
|
|
{ ch7mon(oper, pval); }
|
|
|
|
|
|
|
|
|
primary(pval)
|
|
|
|
;
|
|
|
|
|
1987-08-19 10:36:37 +00:00
|
|
|
binary_expression(int maxrank; arith *pval;)
|
|
|
|
{int oper; arith val1;}
|
1987-01-06 15:16:53 +00:00
|
|
|
:
|
|
|
|
unary(pval)
|
|
|
|
[%while (rank_of(DOT) <= maxrank)
|
|
|
|
binop(&oper)
|
|
|
|
binary_expression(rank_of(oper)-1, &val1)
|
|
|
|
{
|
|
|
|
ch7bin(pval, oper, val1);
|
|
|
|
}
|
|
|
|
]*
|
|
|
|
;
|
|
|
|
|
|
|
|
/* 7.13 */
|
1987-08-19 10:36:37 +00:00
|
|
|
conditional_expression(arith *pval;)
|
|
|
|
{arith val1 = 0, val2 = 0;}
|
1987-01-06 15:16:53 +00:00
|
|
|
:
|
|
|
|
/* allow all binary operators */
|
|
|
|
binary_expression(rank_of('?') - 1, pval)
|
|
|
|
[ '?'
|
|
|
|
expression(&val1)
|
|
|
|
':'
|
|
|
|
assignment_expression(&val2)
|
|
|
|
{ *pval = (*pval ? val1 : val2); }
|
|
|
|
]?
|
|
|
|
;
|
|
|
|
|
|
|
|
/* 7.14 */
|
1987-08-19 10:36:37 +00:00
|
|
|
assignment_expression(arith *pval;)
|
1987-01-06 15:16:53 +00:00
|
|
|
:
|
|
|
|
conditional_expression(pval)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* 7.15 */
|
1987-08-19 10:36:37 +00:00
|
|
|
expression(arith *pval;)
|
|
|
|
{arith val1;}
|
1987-01-06 15:16:53 +00:00
|
|
|
:
|
|
|
|
assignment_expression(pval)
|
|
|
|
[ ','
|
|
|
|
assignment_expression(&val1)
|
|
|
|
{
|
|
|
|
ch7bin(pval, ',', val1);
|
|
|
|
}
|
|
|
|
]*
|
|
|
|
;
|
|
|
|
|
|
|
|
unop(int *oper;) :
|
|
|
|
[ '-' | '!' | '~' ]
|
|
|
|
{*oper = DOT;}
|
|
|
|
;
|
|
|
|
|
|
|
|
multop:
|
|
|
|
'*' | '/' | '%'
|
|
|
|
;
|
|
|
|
|
|
|
|
addop:
|
|
|
|
'+' | '-'
|
|
|
|
;
|
|
|
|
|
|
|
|
shiftop:
|
|
|
|
LEFT | RIGHT
|
|
|
|
;
|
|
|
|
|
|
|
|
relop:
|
|
|
|
'<' | '>' | LESSEQ | GREATEREQ
|
|
|
|
;
|
|
|
|
|
|
|
|
eqop:
|
|
|
|
EQUAL | NOTEQUAL
|
|
|
|
;
|
|
|
|
|
|
|
|
arithop:
|
|
|
|
multop | addop | shiftop
|
|
|
|
|
|
|
|
|
'&' | '^' | '|'
|
|
|
|
;
|
|
|
|
|
|
|
|
binop(int *oper;) :
|
|
|
|
[ arithop | relop | eqop | AND | OR ]
|
|
|
|
{*oper = DOT;}
|
|
|
|
;
|
|
|
|
|
1987-08-19 10:36:37 +00:00
|
|
|
constant(arith *pval;) :
|
1987-01-06 15:16:53 +00:00
|
|
|
INTEGER
|
|
|
|
{*pval = dot.tk_val;}
|
|
|
|
;
|
|
|
|
|
1987-08-19 10:36:37 +00:00
|
|
|
constant_expression (arith *pval;) :
|
1987-01-06 15:16:53 +00:00
|
|
|
assignment_expression(pval)
|
|
|
|
;
|