size_t symbol_openscope(Parser* p);
void symbol_closescope(Parser* p, size_t scope);
void symbol_import(Parser* p, char* name, char* alias);
+void symbol_export(Parser* p, char* path);
// src/type_checks.c
void check_int(Parser* p, AstNode* a);
error(p, "expected end of file");
}
+ symbol_export(p, NULL);
symbol_closescope(p, scope);
EXIT_RULE();
}
sym->value = ast_int(42);
}
+/* Symbol File Generation
+ *****************************************************************************/
+
+static const char SymTypes[5] = {
+ [SYM_MODULE] = 'M',
+ [SYM_CONST] = 'C',
+ [SYM_VAR] = 'V',
+ [SYM_TYPE] = 'T',
+ [SYM_PROC] = 'P',
+};
+
+void symbol_export(Parser* p, char* path)
+{
+ (void)path;
+ for (size_t i = 0; i < p->nsyms; i++)
+ {
+ Symbol* sym = &(p->syms[i]);
+ if (!sym->export) continue;
+ printf("%c %s\n", SymTypes[sym->class], sym->name);
+ }
+}
+
+/* Symbol File Parsing
+ *****************************************************************************/
+/* TODO: write logic to parse symbol file */
+
/* Symbol Table Unit Tests
*****************************************************************************/
#ifdef CERISE_TESTS
Bar3 = Bar2
const
- A = true
- B = 42
- C = 42.0
+ A* = true
+ B* = 42
+ C* = 42.0
D = -B
E = -C
F = not A
H = false or A
type
- TypeA = Int
- TypeB = array 5*B of Int
- TypeC = array 5 of array 10 of Int
- TypeD = record
+ TypeA* = Int
+ TypeB* = array 5*B of Int
+ TypeC* = array 5 of array 10 of Int
+ TypeD* = record
x,y : Int
label : array 10 of Int
dim : record
w,h : Int
end
end
- TypeE = record
+ TypeE* = record
i : Int
a : array 5 of Int
end
- TypeF = array 5 of TypeE
+ TypeF* = array 5 of TypeE
var
- a : Bool
- b : Int
+ a* : Bool
+ b* : Int
c : Int
d : Real
e : array 5 of array 10 of Int
# return z1;
#end
-procedure Bar(a : Int) : Int
+procedure Bar*(a : Int) : Int
begin
return a;
end
-procedure Baz(a : Int)
+procedure Baz*(a : Int)
begin
if (1 > 2) then
42;