FreeBASIC  0.91.0
parser-quirk-iif.bas
Go to the documentation of this file.
1 '' quirk conditional statement (IIF) 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 '' cIIFFunct = IIF '(' condition-expr ',' true-expr ',' false-expr ')' .
12 function cIIFFunct() as ASTNODE ptr
13  dim as ASTNODE ptr expr = any, truexpr = any, falsexpr = any
14  dim as integer truecookie = any, falsecookie = any
15 
16  function = NULL
17 
18  '' The condition expression is always executed,
19  '' the true/false expressions only conditionally though.
20 
21  '' IIF
22  lexSkipToken( )
23 
24  '' '('
25  hMatchLPRNT( )
26 
27  '' condition-expr
28  hMatchExpressionEx( expr, FB_DATATYPE_INTEGER )
29 
30  '' ','
31  hMatchCOMMA( )
32 
33  '' true-expr
35  hMatchExpressionEx( truexpr, FB_DATATYPE_INTEGER )
36  truecookie = astDtorListScopeEnd( )
37 
38  '' ','
39  hMatchCOMMA( )
40 
41  '' false-expr
43  hMatchExpressionEx( falsexpr, astGetDataType( truexpr ) )
44  falsecookie = astDtorListScopeEnd( )
45 
46  '' ')'
47  hMatchRPRNT( )
48 
49  expr = astNewIIF( expr, truexpr, truecookie, falsexpr, falsecookie )
50  if( expr = NULL ) then
51  errReport( FB_ERRMSG_INVALIDDATATYPES, TRUE )
52  '' error recovery: fake an expr
53  expr = astNewCONSTi( 0 )
54  end if
55 
56  function = expr
57 end function
58