FreeBASIC  0.91.0
parser-decl.bas
Go to the documentation of this file.
1 '' declarations top-level 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 
10 '':::::
11 ''Declaration = ConstDecl | TypeDecl | VariableDecl | ProcDecl | DefDecl | OptDecl.
12 ''
13 function cDeclaration _
14  ( _
15  ) as integer
16 
17  dim as FB_SYMBATTRIB attrib = FB_SYMBATTRIB_NONE
18  dim as integer tk = any
19 
20  function = FALSE
21 
22  '' QB mode?
23  if( env.clopt.lang = FB_LANG_QB ) then
24  if( lexGetType() <> FB_DATATYPE_INVALID ) then
25  return FALSE
26  end if
27  end if
28 
29  select case as const lexGetToken( )
30  case FB_TK_PUBLIC
31  if( hCheckScope( ) ) then
32  attrib = FB_SYMBATTRIB_PUBLIC
33  end if
34 
35  lexSkipToken( )
36 
37  case FB_TK_PRIVATE
38  if( hCheckScope( ) ) then
39  attrib = FB_SYMBATTRIB_PRIVATE
40  end if
41 
42  lexSkipToken( )
43 
44  case FB_TK_DECLARE
45  cProcDecl( )
46  return TRUE
47 
48  case FB_TK_DEFBYTE, FB_TK_DEFUBYTE, FB_TK_DEFSHORT, FB_TK_DEFUSHORT, _
49  FB_TK_DEFINT, FB_TK_DEFUINT, FB_TK_DEFLNG, FB_TK_DEFULNG, _
50  FB_TK_DEFSNG, FB_TK_DEFDBL, FB_TK_DEFSTR, _
51  FB_TK_DEFLNGINT, FB_TK_DEFULNGINT
52  cDefDecl( )
53  return TRUE
54 
55  case FB_TK_OPTION
56  cOptDecl( )
57  return TRUE
58 
59  end select
60 
61  tk = lexGetToken( )
62 
63  select case as const( tk )
64  case FB_TK_STATIC, FB_TK_CONST, FB_TK_VIRTUAL, FB_TK_ABSTRACT
65  '' STATIC? SUB|FUNCTION|...
66  '' CONST? (ABSTRACT|VIRTUAL)? SUB|FUNCTION|...
67  '' Note: ABSTRACT doesn't make sense on bodies, but it's still
68  '' allowed here to let cProcStmtBegin() show a nice error.
69  select case as const lexGetLookAhead( 1 )
70  case FB_TK_FUNCTION, FB_TK_SUB, FB_TK_OPERATOR, _
71  FB_TK_CONSTRUCTOR, FB_TK_DESTRUCTOR, FB_TK_PROPERTY, _
72  FB_TK_VIRTUAL, FB_TK_ABSTRACT
73  cProcStmtBegin( attrib )
74  function = TRUE
75  case else
76  select case( tk )
77  case FB_TK_CONST
78  cConstDecl( attrib )
79  function = TRUE
80  case FB_TK_STATIC
81  function = cVariableDecl( attrib )
82  case else
83  errReport( FB_ERRMSG_SYNTAXERROR )
84  end select
85  end select
86 
87  case FB_TK_FUNCTION, FB_TK_SUB, FB_TK_DESTRUCTOR, FB_TK_PROPERTY
88  if( attrib <> FB_SYMBATTRIB_NONE ) then
89  cProcStmtBegin( attrib )
90  function = TRUE
91  else
92  '' not a FUNCTION|PROPERTY '=' ?
93  select case( lexGetLookAhead( 1 ) )
94  case FB_TK_ASSIGN, FB_TK_DBLEQ
95 
96  case else
98  function = TRUE
99  end select
100  end if
101 
102  case FB_TK_CONSTRUCTOR
103  if( attrib <> FB_SYMBATTRIB_NONE ) then
104  cProcStmtBegin( attrib )
105  function = TRUE
106  else
107  '' ambiguity: it could be a constructor chain
108  if( fbIsModLevel( ) ) then
109  cProcStmtBegin( )
110  function = TRUE
111  end if
112  end if
113 
114  case FB_TK_OPERATOR
115  if( attrib <> FB_SYMBATTRIB_NONE ) then
116  cProcStmtBegin( attrib )
117  function = TRUE
118  else
119  '' ambiguity: it could be the operator '=' body
120  if( fbIsModLevel( ) ) then
121  cProcStmtBegin( )
122  function = TRUE
123  else
124  '' not OPERATOR '=' ?
125  select case( lexGetLookAhead( 1 ) )
126  case FB_TK_ASSIGN, FB_TK_DBLEQ
127 
128  case else
129  cProcStmtBegin( )
130  function = TRUE
131  end select
132  end if
133  end if
134 
135  case FB_TK_TYPE, FB_TK_UNION
136  cTypeDecl( attrib )
137  function = TRUE
138 
139  case FB_TK_ENUM
140  cEnumDecl( attrib )
141  function = TRUE
142 
143  case FB_TK_DIM, FB_TK_REDIM, FB_TK_COMMON, FB_TK_EXTERN
144  function = cVariableDecl( attrib )
145 
146  case FB_TK_VAR
147  cAutoVarDecl( attrib )
148  function = TRUE
149 
150  case else
151  if( attrib <> FB_SYMBATTRIB_NONE ) then
152  errReport( FB_ERRMSG_SYNTAXERROR )
153  hSkipStmt( )
154  function = TRUE
155  end if
156  end select
157 
158 end function
159