forked from countingpine/tinybasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_extern.bas
More file actions
57 lines (45 loc) · 1.22 KB
/
parse_extern.bas
File metadata and controls
57 lines (45 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'::::::::
function parse_extern _
( _
) as node_t ptr
dim as datatype_t ptr dt
dim as string ident
dim as integer is_array
dim as integer array_size
dim as sym_t ptr sym
if match( TK_AS ) = 0 then
expected( "'AS'", "'" & lexer_stack.curr_lex->tk_str & "'" )
end if
dt = parse_datatype( )
ident = lexer_stack.curr_lex->tk_str
read_token( ) ' dump ident
' Will it be an array?
if match( TK_CHAR_LPAREN ) then
is_array = -1
if match_str( "0" ) = 0 then
expected( "0", lexer_stack.curr_lex->tk_str )
end if
if match( TK_TO ) = 0 then
expected( "TO", lexer_stack.curr_lex->tk_str )
end if
array_size = val(lexer_stack.curr_lex->tk_str) + 1
read_token( ) ' dump ubound
if match( TK_CHAR_RPAREN ) = 0 then
expected( "')'", lexer_stack.curr_lex->tk_str )
end if
end if
if match( TK_EOL ) = 0 then
expected( "end of line", lexer_stack.curr_lex->tk_str )
end if
' No symbol with this name?
if sym_exists( ident ) then
die( "Symbol '" & ident & "' already exists!" )
end if
' Allocate the symbol
sym = sym_add_extern( ident, dt, is_array, array_size )
dim as node_t ptr node = callocate( sizeof( node_t ) )
node->typ = NODE_EXTERN
node->sym = sym
node->dt = *dt
function = node
end function