fixed the spaceing t#34
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
extern int yylex(void);
|
||||
void yyerror(const char *err);
|
||||
extern char* yytext;
|
||||
extern int yyleng;
|
||||
extern int yychar;
|
||||
extern SymbolTable * cur;
|
||||
//char* cur_value;
|
||||
@ -122,8 +123,8 @@ idlist:
|
||||
;
|
||||
|
||||
sblock:
|
||||
L_BRACE {cur = CreateScope(cur,2,2);} statement_list {cur = getParent(cur);} R_BRACE
|
||||
| L_BRACE {cur = CreateScope(cur,2,2);} dblock statement_list {cur = getParent(cur);} R_BRACE
|
||||
L_BRACE {column_number += yyleng; cur = CreateScope(cur,line_number,column_number);} statement_list {cur = getParent(cur);} R_BRACE
|
||||
| L_BRACE {column_number += yyleng; cur = CreateScope(cur,line_number,column_number);} dblock statement_list {cur = getParent(cur);} R_BRACE
|
||||
;
|
||||
|
||||
dblock:
|
||||
|
@ -7,9 +7,11 @@
|
||||
%{
|
||||
#include <stdbool.h>
|
||||
#include "../tmp/grammar.tab.h"
|
||||
#include "../src/symbol_table.h"
|
||||
#ifndef DEBUG
|
||||
#define DEBUG 0
|
||||
#endif
|
||||
extern SymbolTable * cur;
|
||||
|
||||
int line_number = 1, column_number = 1;
|
||||
%}
|
||||
|
74
tests/sprint2/test/sp2_llnode.alpha
Normal file
74
tests/sprint2/test/sp2_llnode.alpha
Normal file
@ -0,0 +1,74 @@
|
||||
type rec: [integer: x; integer: y]
|
||||
type T1: integer -> integer
|
||||
type T2: rec -> integer
|
||||
|
||||
type llnode: [address: prev; integer: val; address: next]
|
||||
type list: integer -> llnode
|
||||
|
||||
function foo : T1
|
||||
function bar1 : T2
|
||||
function bar2 : T2
|
||||
function make_list : list
|
||||
make_list(a) := {
|
||||
[integer:orig_a; address: ret; address: curr; address: temp]
|
||||
if (a < 0 | a = 0) then {
|
||||
return null;
|
||||
} else {
|
||||
ret := reserve llnode;
|
||||
ret.prev := null;
|
||||
ret.next := null;
|
||||
ret.val := a;
|
||||
while (0 < a) {
|
||||
temp := reserve llnode;
|
||||
temp.prev := null;
|
||||
temp.next := null;
|
||||
temp.val := val;
|
||||
if (a = orig_a) then {
|
||||
ret.next := temp;
|
||||
temp.prev := ret;
|
||||
curr := temp;
|
||||
} else {
|
||||
curr.next := temp;
|
||||
temp.prev := curr;
|
||||
curr := temp;
|
||||
}
|
||||
a := a - 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foo(x) := {
|
||||
return x * x;
|
||||
}
|
||||
bar1(a) := {
|
||||
return a.x * a.y;
|
||||
}
|
||||
|
||||
bar2 as (r,s) := {
|
||||
if (r < s) then {
|
||||
while (!(r < s)) {
|
||||
r := r + 1;
|
||||
}
|
||||
} else {
|
||||
[integer: x]
|
||||
x := 0;
|
||||
while (x < 10) {
|
||||
r := r + s;
|
||||
}
|
||||
}
|
||||
return r * s;
|
||||
}
|
||||
entry(arg) := {
|
||||
[ integer: result ; rec: w; llnode: li]
|
||||
li := make_list(6);
|
||||
result := foo(5);
|
||||
w := reserve w;
|
||||
w.x := 5;
|
||||
w.y := 7;
|
||||
result := bar1(w);
|
||||
result := bar2(5,7);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user