forked from countingpine/tinybasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_enum.bas
More file actions
69 lines (55 loc) · 1.66 KB
/
parse_enum.bas
File metadata and controls
69 lines (55 loc) · 1.66 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
58
59
60
61
62
63
64
65
66
67
68
69
'::::::::
function parse_enum _
( _
) as node_t ptr
dim as string ident
dim as sym_t ptr members = callocate( sizeof( sym_t ) * 512 )
dim as integer member_count
dim as integer i
ident = lexer_stack.curr_lex->tk_str
read_token( ) ' dump identifier
if match( TK_EOL ) = 0 then
expected( "end of line", lexer_stack.curr_lex->tk_str )
end if
if sym_exists( ident ) then
die( "Symbol '" & ident & "' already exists!" )
end if
dim as sym_t ptr sym
sym = sym_add_enum( ident )
dim as integer curr_val = 0
while (lexer_stack.curr_lex->tk_typ <> TK_END) and (lexer_stack.curr_lex->tk_typ <> TK_EOF)
while match( TK_EOL )
' cycle away the blank lines
wend
members[member_count].ident = lexer_stack.curr_lex->tk_str
members[member_count]._alias = lexer_stack.curr_lex->tk_str
read_token( ) ' dump identifier
if match( TK_CHAR_EQ ) then
dim as node_t ptr expr = parse_expression( )
if expr->typ <> NODE_LITINT then
expected( "constant", lexer_stack.curr_lex->tk_str )
end if
curr_val = val( expr->_i )
free(expr)
end if
members[member_count].enum_val = curr_val
sym_add_enum_member( members[member_count].ident, curr_val )
if match( TK_EOL ) = 0 then
expected( "end of line1", lexer_stack.curr_lex->tk_str )
end if
member_count += 1
curr_val += 1
wend
sym->members = members
sym->member_count = member_count
if match( TK_END ) = 0 then
expected( "END", lexer_stack.curr_lex->tk_str )
end if
if match( TK_ENUM ) = 0 then
expected( "ENUM", lexer_stack.curr_lex->tk_str )
end if
if match( TK_EOL ) = 0 then
expected( "end of line", lexer_stack.curr_lex->tk_str )
end if
function = tree_node_enum( sym )
end function