FreeBASIC  0.91.0
parser-quirk.bas
Go to the documentation of this file.
1 '' quirk statements (ON, OPEN, PRINT, ...) parsing top-level
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 #macro CHECK_CODEMASK( )
12  if( cCompStmtIsAllowed( FB_CMPSTMT_MASK_CODE ) = FALSE ) then
13  hSkipStmt( )
14  exit function
15  end if
16 #endmacro
17 
18 '':::::
19 ''QuirkStmt = GotoStmt
20 '' | ArrayStmt
21 '' | PrintStmt
22 '' | MidStmt
23 '' | DataStmt
24 '' | etc .
25 ''
26 function cQuirkStmt _
27  ( _
28  byval tk as FB_TOKEN = INVALID _
29  ) as integer
30 
31  function = FALSE
32 
33  if( tk = INVALID ) then
34  tk = lexGetToken( )
35 
36  select case lexGetClass( )
37  case FB_TKCLASS_KEYWORD, FB_TKCLASS_QUIRKWD
38  '' QB mode?
39  if( env.clopt.lang = FB_LANG_QB ) then
40  if( lexGetType() <> FB_DATATYPE_INVALID ) then
41  return FALSE
42  end if
43  end if
44 
45  case else
46  if( tk = CHAR_QUESTION ) then '' PRINT as '?', can't be a keyword..
47  CHECK_CODEMASK( )
48  function = cPrintStmt( tk )
49  end if
50  exit function
51  end select
52  end if
53 
54  dim as integer res = FALSE
55 
56  select case as const tk
57  case FB_TK_GOTO, FB_TK_GOSUB, FB_TK_RETURN, FB_TK_RESUME
58  CHECK_CODEMASK( )
59  res = cGotoStmt( tk )
60 
61  case FB_TK_PRINT, FB_TK_LPRINT
62  CHECK_CODEMASK( )
63  res = cPrintStmt( tk )
64 
65  case FB_TK_RESTORE, FB_TK_READ, FB_TK_DATA
66  CHECK_CODEMASK( )
67  res = cDataStmt( tk )
68 
69  case FB_TK_ERASE
70  CHECK_CODEMASK( )
71  res = cEraseStmt()
72 
73  case FB_TK_SWAP
74  CHECK_CODEMASK( )
75  res = cSwapStmt()
76 
77  case FB_TK_LINE
78  CHECK_CODEMASK( )
79  res = cLineInputStmt( )
80 
81  case FB_TK_INPUT
82  CHECK_CODEMASK( )
83  res = cInputStmt( )
84 
85  case FB_TK_POKE
86  CHECK_CODEMASK( )
87  res = cPokeStmt( )
88 
89  case FB_TK_OPEN, FB_TK_CLOSE, FB_TK_SEEK, FB_TK_PUT, FB_TK_GET, _
90  FB_TK_LOCK, FB_TK_UNLOCK, FB_TK_NAME
91  CHECK_CODEMASK( )
92  res = cFileStmt( tk )
93 
94  case FB_TK_ON
95  CHECK_CODEMASK( )
96  res = cOnStmt( )
97 
98  case FB_TK_WRITE
99  CHECK_CODEMASK( )
100  res = cWriteStmt()
101 
102  case FB_TK_ERROR
103  CHECK_CODEMASK( )
104  res = cErrorStmt()
105 
106  case FB_TK_ERR
107  CHECK_CODEMASK( )
108  res = cErrSetStmt()
109 
110  case FB_TK_VIEW
111  CHECK_CODEMASK( )
112  res = (cViewStmt(FALSE) <> NULL)
113 
114  case FB_TK_MID
115  CHECK_CODEMASK( )
116  res = cMidStmt( )
117 
118  case FB_TK_LSET, FB_TK_RSET
119  CHECK_CODEMASK( )
120  res = cLRSetStmt( tk )
121 
122  case FB_TK_WIDTH
123  CHECK_CODEMASK( )
124  res = cWidthStmt( FALSE ) <> NULL
125 
126  case FB_TK_COLOR
127  CHECK_CODEMASK( )
128  res = cColorStmt( FALSE ) <> NULL
129 
130  case FB_TK_REM
131  '' due the QB quirks..
132  if( env.clopt.lang = FB_LANG_QB ) then
133  res = cComment( )
134  end if
135 
136  end select
137 
138  if( res = FALSE ) then
139  res = cGfxStmt( tk )
140  end if
141 
142  function = res
143 
144 end function
145 
146 '':::::
147 ''QuirkFunction = QBFUNCTION ('(' ProcParamList ')')? .
148 ''
149 function cQuirkFunction(byval sym as FBSYMBOL ptr) as ASTNODE ptr
150  dim as ASTNODE ptr funcexpr = NULL
151  dim as FB_TOKEN tk = sym->key.id
152 
153  select case as const tk
154  case FB_TK_MKD, FB_TK_MKS, FB_TK_MKI, FB_TK_MKL, _
155  FB_TK_MKSHORT, FB_TK_MKLONGINT
156  funcexpr = cMKXFunct(tk)
157 
158  case FB_TK_CVD, FB_TK_CVS, FB_TK_CVI, FB_TK_CVL, _
159  FB_TK_CVSHORT, FB_TK_CVLONGINT
160  funcexpr = cCVXFunct(tk)
161 
162  case FB_TK_STR, FB_TK_WSTR, FB_TK_MID, FB_TK_STRING, FB_TK_WSTRING, _
163  FB_TK_CHR, FB_TK_WCHR, _
164  FB_TK_ASC, FB_TK_INSTR, FB_TK_INSTRREV, _
165  FB_TK_TRIM, FB_TK_RTRIM, FB_TK_LTRIM, _
166  FB_TK_LCASE, FB_TK_UCASE
167  funcexpr = cStringFunct(tk)
168 
169  case FB_TK_ABS, FB_TK_SGN, FB_TK_FIX, FB_TK_FRAC, FB_TK_LEN, FB_TK_SIZEOF, _
170  FB_TK_SIN, FB_TK_ASIN, FB_TK_COS, FB_TK_ACOS, FB_TK_TAN, FB_TK_ATN, _
171  FB_TK_SQR, FB_TK_LOG, FB_TK_EXP, FB_TK_ATAN2, FB_TK_INT
172  funcexpr = cMathFunct(tk, FALSE)
173 
174  case FB_TK_PEEK
175  funcexpr = cPeekFunct()
176 
177  case FB_TK_LBOUND, FB_TK_UBOUND
178  funcexpr = cArrayFunct(tk)
179 
180  case FB_TK_SEEK, FB_TK_INPUT, FB_TK_WINPUT, FB_TK_OPEN, FB_TK_CLOSE, _
181  FB_TK_GET, FB_TK_PUT, FB_TK_NAME
182  funcexpr = cFileFunct(tk)
183 
184  case FB_TK_ERR
185  funcexpr = cErrorFunct()
186 
187  case FB_TK_IIF
188  return cStrIdxOrMemberDeref( cIIFFunct( ) )
189 
190  case FB_TK_VA_FIRST
191  funcexpr = cVAFunct()
192 
193  case FB_TK_CBYTE, FB_TK_CSHORT, FB_TK_CINT, FB_TK_CLNG, FB_TK_CLNGINT, _
194  FB_TK_CUBYTE, FB_TK_CUSHORT, FB_TK_CUINT, FB_TK_CULNG, FB_TK_CULNGINT, _
195  FB_TK_CSNG, FB_TK_CDBL, FB_TK_CSIGN, FB_TK_CUNSG
196  return cTypeConvExpr( tk )
197 
198  case FB_TK_TYPE
199  return cStrIdxOrMemberDeref( cAnonType( ) )
200 
201  case FB_TK_VIEW
202  funcexpr = cViewStmt(TRUE)
203 
204  case FB_TK_WIDTH
205  funcexpr = cWidthStmt( TRUE )
206 
207  case FB_TK_COLOR
208  funcexpr = cColorStmt( TRUE )
209 
210  case FB_TK_SCREEN, FB_TK_SCREENQB
211  funcexpr = cScreenFunct()
212 
213  case FB_TK_THREADCALL
214  funcexpr = cThreadCallFunc()
215 
216  end select
217 
218  if( funcexpr = NULL ) then
219  funcexpr = cGfxFunct( tk )
220  end if
221 
222  function = funcexpr
223 end function
224