Skip to content
2,094 changes: 1,315 additions & 779 deletions lang/basic/src/basic.g

Large diffs are not rendered by default.

1,498 changes: 776 additions & 722 deletions lang/cem/cemcom.ansi/declar.g

Large diffs are not rendered by default.

686 changes: 387 additions & 299 deletions lang/cem/cemcom.ansi/expression.g

Large diffs are not rendered by default.

1,544 changes: 807 additions & 737 deletions lang/cem/cemcom.ansi/ival.g

Large diffs are not rendered by default.

417 changes: 215 additions & 202 deletions lang/cem/cemcom.ansi/program.g

Large diffs are not rendered by default.

886 changes: 436 additions & 450 deletions lang/cem/cemcom.ansi/statement.g

Large diffs are not rendered by default.

1,043 changes: 542 additions & 501 deletions lang/cem/cemcom/declar.g

Large diffs are not rendered by default.

630 changes: 339 additions & 291 deletions lang/cem/cemcom/expression.g

Large diffs are not rendered by default.

1,424 changes: 735 additions & 689 deletions lang/cem/cemcom/ival.g

Large diffs are not rendered by default.

372 changes: 189 additions & 183 deletions lang/cem/cemcom/program.g

Large diffs are not rendered by default.

925 changes: 452 additions & 473 deletions lang/cem/cemcom/statement.g

Large diffs are not rendered by default.

269 changes: 150 additions & 119 deletions lang/cem/cpp.ansi/expression.g
Original file line number Diff line number Diff line change
Expand Up @@ -2,138 +2,169 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/

/*
* Reformat from the repository root (requires clang-format):
*
* python3 util/LLgen/formatter.py -i lang/cem/cpp.ansi/expression.g
*/
/* EXPRESSION SYNTAX PARSER */

%lexical LLlex;
%start If_expr, if_expression;
%lexical LLlex;
%start If_expr, if_expression;

{
#include "arith.h"
#include "LLlex.h"
#include "ch3mon.h"
#include "ch3bin.h"
#include "expr.h"
#include "arith.h"
#include "LLlex.h"
#include "ch3mon.h"
#include "ch3bin.h"
#include "expr.h"

extern arith ifval;
extern arith ifval;
}

if_expression
{ int is_unsigned = 0; }
:
constant_expression(&ifval, &is_unsigned)
;
{
int is_unsigned = 0;
}
: constant_expression(&ifval, &is_unsigned)
;

/* 7.1 */
primary(arith *pval; int *is_uns;)
:
constant(pval, is_uns)
|
'(' expression(pval, is_uns) ')'
;

unary(arith *pval; int *is_uns;)
{int oper;}
:
unop(&oper)
unary(pval, is_uns)
{ ch3mon(oper, pval, is_uns); }
|
primary(pval, is_uns)
;

binary_expression(int maxrank; arith *pval; int *is_uns;)
{int oper; arith val1; int u;}
:
unary(pval, is_uns)
[%while (rank_of(DOT) <= maxrank)
binop(&oper)
binary_expression(rank_of(oper)-1, &val1, &u)
{
ch3bin(pval, is_uns, oper, val1, u);
}
]*
;
primary(arith* pval; int* is_uns;)
: constant(pval, is_uns)
| '('
expression(pval, is_uns)
')'
;

unary(arith* pval; int* is_uns;)
{
int oper;
}
: unop(&oper)
unary(pval, is_uns)
{ ch3mon(oper, pval, is_uns); }
| primary(pval, is_uns)
;

binary_expression(int maxrank; arith* pval; int* is_uns;)
{
int oper;
arith val1;
int u;
}
: unary(pval, is_uns)
[
%while (rank_of(DOT) <= maxrank)
binop(&oper)
binary_expression(rank_of(oper) - 1, &val1, &u)
{ ch3bin(pval, is_uns, oper, val1, u); }
]*
;

/* 7.13 */
conditional_expression(arith *pval; int *is_uns)
{arith val1 = 0, val2 = 0; int u;}
:
/* allow all binary operators */
binary_expression(rank_of('?') - 1, pval, is_uns)
[ '?'
expression(&val1, is_uns)
':'
assignment_expression(&val2, &u)
{ if (*pval) *pval = val1;
else { *pval = val2; *is_uns = u; }
}
]?
;
conditional_expression(arith* pval; int* is_uns)
{
arith val1 = 0, val2 = 0;
int u;
}
:
/* allow all binary operators */
binary_expression(rank_of('?') - 1, pval, is_uns)
[
'?'
expression(&val1, is_uns)
':'
assignment_expression(&val2, &u)
{ if (*pval) *pval = val1; else { *pval = val2; *is_uns = u; } }
]?
;

/* 7.14 */
assignment_expression(arith *pval; int *is_uns)
:
conditional_expression(pval, is_uns)
;
assignment_expression(arith* pval; int* is_uns)
: conditional_expression(pval, is_uns)
;

/* 7.15 */
expression(arith *pval; int *is_uns)
{arith val1;
int is_uns1;
}
:
assignment_expression(pval,is_uns)
[ ','
assignment_expression(&val1, &is_uns1)
{
ch3bin(pval, is_uns, ',', val1, is_uns1);
}
]*
;

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;}
;

constant(arith *pval; int *is_uns) :
INTEGER
{*pval = dot.tk_val;
*is_uns = dot.tk_unsigned;
}
;

constant_expression (arith *pval; int *is_uns) :
assignment_expression(pval, is_uns)
;
expression(arith* pval; int* is_uns)
{
arith val1;
int is_uns1;
}
: assignment_expression(pval, is_uns)
[
','
assignment_expression(&val1, &is_uns1)
{ ch3bin(pval, is_uns, ',', val1, is_uns1); }
]*
;

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; }
;

constant(arith* pval; int* is_uns)
: INTEGER
{
*pval = dot.tk_val;
*is_uns = dot.tk_unsigned;
}
;

constant_expression(arith* pval; int* is_uns)
: assignment_expression(pval, is_uns)
;
Loading
Loading