FreeBASIC  0.91.0
parser-quirk-console.bas
Go to the documentation of this file.
1 '' quirk console statements (VIEW, LOCATE) 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 "rtl.bi"
10 #include once "ast.bi"
11 
12 '':::::
13 '' ViewStmt = VIEW (PRINT (Expression TO Expression)?) .
14 ''
15 function cViewStmt(byval is_func as integer) as ASTNODE ptr
16  dim as ASTNODE ptr expr1, expr2
17  dim as integer default_view, default_view_value
18 
19  function = NULL
20 
21  default_view = is_func
22  default_view_value = iif(is_func,-1,0)
23 
24  '' PRINT
25  if( lexGetLookAhead( 1 ) <> FB_TK_PRINT ) then
26  exit function
27  end if
28 
29  lexSkipToken( )
30  lexSkipToken( )
31 
32  '' (Expression TO Expression)?
33  if( is_func = FALSE ) then
34  expr1 = cExpression( )
35  if( expr1 <> NULL ) then
36  if( hMatch( FB_TK_TO ) = FALSE ) then
37  errReport( FB_ERRMSG_SYNTAXERROR )
38  expr1 = astNewCONSTi( 0 )
39  end if
40  hMatchExpressionEx( expr2, FB_DATATYPE_INTEGER )
41  else
42  default_view = TRUE
43  end if
44  end if
45 
46  if( default_view ) then
47  if( is_func ) then
48  hMatchLPRNT( )
49  hMatchRPRNT( )
50  end if
51  expr1 = astNewCONSTi( default_view_value )
52  expr2 = astNewCONSTi( default_view_value )
53  end if
54 
55  expr1 = rtlConsoleView( expr1, expr2 )
56  if (is_func = FALSE) then
57  astAdd(expr1)
58  end if
59 
60  function = expr1
61 end function
62 
63 function cWidthStmt(byval isfunc as integer) as ASTNODE ptr
64  dim as ASTNODE ptr fnum, width_arg, height_arg, dev_name
65  dim as integer checkrprnt
66 
67  function = NULL
68 
69  '' WIDTH
70  lexSkipToken( )
71 
72  if( isfunc ) then
73  '' '('?
74  checkrprnt = hMatch( CHAR_LPRNT )
75  else
76  checkrprnt = FALSE
77  end if
78 
79  if( isfunc ) then
80  '' used as function?
81  if( checkrprnt = FALSE ) then
82  return rtlWidthScreen( NULL, NULL, isfunc )
83  '' ()?
84  elseif( hMatch( CHAR_RPRNT ) ) then
85  return rtlWidthScreen( NULL, NULL, isfunc )
86  end if
87  end if
88 
89  if( hMatch( FB_TK_LPRINT ) ) then
90  ' fb_WidthDev
91  dev_name = astNewCONSTstr( "LPT1:" )
92  hMatchExpressionEx( width_arg, FB_DATATYPE_INTEGER )
93 
94  function = rtlWidthDev( dev_name, width_arg, isfunc )
95 
96  elseif( hMatch( CHAR_SHARP ) ) then
97  ' fb_WidthFile
98 
99  hMatchExpressionEx( fnum, FB_DATATYPE_INTEGER )
100 
101  if( hMatch( CHAR_COMMA ) ) then
102  hMatchExpressionEx( width_arg, FB_DATATYPE_INTEGER )
103  else
104  width_arg = astNewCONSTi( -1 )
105  end if
106 
107  function = rtlWidthFile( fnum, width_arg, isfunc )
108 
109  elseif( hMatch( CHAR_COMMA ) ) then
110  ' fb_WidthScreen
111  width_arg = astNewCONSTi( -1 )
112  hMatchExpressionEx( height_arg, FB_DATATYPE_INTEGER )
113  function = rtlWidthScreen( width_arg, height_arg, isfunc )
114 
115  else
116  hMatchExpressionEx( dev_name, FB_DATATYPE_STRING )
117  ' fb_WidthDev
118  if( symbIsString( astGetDataType( dev_name ) ) ) then
119  if( hMatch( CHAR_COMMA ) ) then
120  hMatchExpressionEx( width_arg, FB_DATATYPE_INTEGER )
121  else
122  width_arg = astNewCONSTi( -1 )
123  end if
124  function = rtlWidthDev( dev_name, width_arg, isfunc )
125 
126  else
127  ' fb_WidthScreen
128  width_arg = dev_name
129  dev_name = NULL
130 
131  if( hMatch( CHAR_COMMA ) ) then
132  hMatchExpressionEx( height_arg, FB_DATATYPE_INTEGER )
133  else
134  height_arg = astNewCONSTi( -1 )
135  end if
136  function = rtlWidthScreen( width_arg, height_arg, isfunc )
137 
138  end if
139  end if
140 
141  if( checkrprnt ) then
142  '' ')'
143  hMatchRPRNT( )
144  end if
145 
146 end function
147 
148 function cColorStmt(byval isfunc as integer) as ASTNODE ptr
149  dim as ASTNODE ptr fore_color, back_color = NULL
150 
151  function = NULL
152 
153  '' COLOR
154  lexSkipToken( )
155 
156  if( isfunc ) then
157  '' '('?
158  if( hMatch( CHAR_LPRNT ) = TRUE ) then
159  fore_color = cExpression( )
160  if( hMatch( CHAR_COMMA ) = TRUE ) then
161  hMatchExpression( back_color )
162  end if
163  hMatchRPRNT( )
164  end if
165  else
166  '' '('?
167  if( hMatch( CHAR_LPRNT ) = TRUE ) then
168  '' expr?
169  fore_color = cExpression( )
170  if( hMatch( CHAR_COMMA ) = TRUE ) then
171  '' ',' expr ')'
172  hMatchExpression( back_color )
173  hMatchRPRNT( )
174  else
175  '' ')' (',' expr)?
176  hMatchRPRNT( )
177  if( hMatch( CHAR_COMMA ) = TRUE ) then
178  hMatchExpression( back_color )
179  end if
180  end if
181  else
182  '' expr? (',' expr)?
183  fore_color = cExpression( )
184  if( hMatch( CHAR_COMMA ) = TRUE ) then
185  hMatchExpression( back_color )
186  end if
187  end if
188  end if
189 
190  function = rtlColor( fore_color, back_color, isfunc )
191 end function
192 
193 '':::::
194 '' ScreenFunct = SCREEN '(' expr ',' expr ( ',' expr )? ')'
195 '' | SCREEN ( '(' ')' )? -- returns the current active/visible pages
196 ''
197 function cScreenFunct() as ASTNODE ptr
198  function = NULL
199 
200  '' SCREEN
201  lexSkipToken( )
202 
203  dim as integer match_paren = FALSE
204  dim as ASTNODE ptr yexpr = NULL
205  '' '('?
206  if( lexGetToken( ) = CHAR_LPRNT ) then
207  lexSkipToken( )
208  match_paren = TRUE
209  yexpr = cExpression( )
210  end if
211 
212  '' pageset?
213  if( yexpr = NULL ) then
214  function = rtlPageSet( NULL, NULL, TRUE )
215  '' readXY..
216  else
217  dim as ASTNODE ptr xexpr, fexpr
218  hMatchCOMMA( )
219  hMatchExpressionEx( xexpr, FB_DATATYPE_INTEGER )
220  fexpr = NULL
221  if( hMatch( CHAR_COMMA ) ) then
222  hMatchExpressionEx( fexpr, FB_DATATYPE_INTEGER )
223  end if
224  function = rtlConsoleReadXY( yexpr, xexpr, fexpr )
225  end if
226 
227  if( match_paren ) then
228  hMatchRPRNT( )
229  end if
230 end function
231