FreeBASIC  0.91.0
parser-compound-scope.bas
Go to the documentation of this file.
1 '' SCOPE..END SCOPE compound statement parsing
2 ''
3 '' chng: sep/2004 written [v1ctor]
4 
5 #include once "fb.bi"
6 #include once "fbint.bi"
7 #include once "parser.bi"
8 #include once "ast.bi"
9 
10 '' ScopeStmtBegin = SCOPE .
12  dim as ASTNODE ptr n = any
13  dim as FB_CMPSTMTSTK ptr stk = any
14 
15  if( fbLangOptIsSet( FB_LANG_OPT_SCOPE ) = FALSE ) then
16  errReportNotAllowed( FB_LANG_OPT_SCOPE )
17  '' error recovery: skip the whole compound stmt
18  hSkipCompound( FB_TK_SCOPE )
19  exit sub
20  end if
21 
22  '' SCOPE
23  lexSkipToken( )
24 
25  n = astScopeBegin( )
26  if( n = NULL ) then
27  errReport( FB_ERRMSG_RECLEVELTOODEEP )
28  end if
29 
30  ''
31  stk = cCompStmtPush( FB_TK_SCOPE )
32  stk->scopenode = n
33 
34  '' deprecated quirk: implicit vars inside implicit scope blocks
35  '' must be allocated in the function scope
36  stk->scp.lastis_scope = fbGetIsScope( )
37  fbSetIsScope( TRUE )
38 end sub
39 
40 '' ScopeStmtEnd = END SCOPE .
42  dim as FB_CMPSTMTSTK ptr stk = any
43 
44  stk = cCompStmtGetTOS( FB_TK_SCOPE )
45  if( stk = NULL ) then
46  hSkipStmt( )
47  exit sub
48  end if
49 
50  '' END SCOPE
51  lexSkipToken( )
52  lexSkipToken( )
53 
54  fbSetIsScope( stk->scp.lastis_scope )
55 
56  if( stk->scopenode <> NULL ) then
57  astScopeEnd( stk->scopenode )
58  end if
59 
60  '' pop from stmt stack
61  cCompStmtPop( stk )
62 end sub
63