FreeBASIC  0.91.0
parser-compound-while.bas
Go to the documentation of this file.
1 '' WHILE..WEND compound statement parsing
2 ''
3 '' chng: sep/2004 written [v1ctor]
4 
5 
6 #include once "fb.bi"
7 #include once "fbint.bi"
8 #include once "parser.bi"
9 #include once "ast.bi"
10 
11 '':::::
12 ''WhileStmtBegin = WHILE Expression .
13 ''
15  dim as ASTNODE ptr expr = any
16  dim as FBSYMBOL ptr il = any, el = any
17  dim as FB_CMPSTMTSTK ptr stk = any
18 
19  '' WHILE
20  lexSkipToken( )
21 
22  '' add ini and end labels
23  il = symbAddLabel( NULL )
24  el = symbAddLabel( NULL, FB_SYMBOPT_NONE )
25 
26  '' emit ini label
27  astAdd( astNewLABEL( il ) )
28 
29  '' Expression
30  expr = cExpression( )
31  if( expr = NULL ) then
32  errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
33  '' error recovery: fake an expr
34  expr = astNewCONSTi( 0 )
35  end if
36 
37  '' branch
38  expr = astBuildBranch( expr, el, FALSE )
39  if( expr = NULL ) then
40  errReport( FB_ERRMSG_INVALIDDATATYPES )
41  else
42  astAdd( expr )
43  end if
44 
45  '' push to stmt stack
46  stk = cCompStmtPush( FB_TK_WHILE )
47  stk->scopenode = astScopeBegin( )
48  stk->while.cmplabel = il
49  stk->while.endlabel = el
50 end sub
51 
52 '' WhileStmtEnd = WEND
54  dim as FB_CMPSTMTSTK ptr stk = any
55 
56  stk = cCompStmtGetTOS( FB_TK_WHILE )
57  if( stk = NULL ) then
58  hSkipStmt( )
59  exit sub
60  end if
61 
62  '' WEND
63  lexSkipToken( )
64 
65  if( stk->scopenode <> NULL ) then
66  astScopeEnd( stk->scopenode )
67  end if
68 
69  astAdd( astNewBRANCH( AST_OP_JMP, stk->while.cmplabel ) )
70 
71  '' end label (loop exit)
72  astAdd( astNewLABEL( stk->while.endlabel ) )
73 
74  '' pop from stmt stack
75  cCompStmtPop( stk )
76 end sub
77