AdvancedControlStructures - Advanced High Level Control...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Advanced High Level Control Structures Beta Draft - Do not distribute © 2001, By Randall Hyde Page 727 Ad vanced High Level Control Structures Chapter One 1.1 Chapter Overview V olume One introduced some basic HLA control structures lik e the IF and WHILE statements (see “ Some Basic HLA Control Structures ” on page 29 .). This section elaborates on some of those control struc- tures (discussing features that were a little too adv anced to present in V olume One) and it introduces the remaining high le v el language control structures that HLA pro vides. This includes a full discussion of HLA ’ s boolean e xpressions, the TR Y ..ENDTR Y statement, the RAISE statement, the BEGIN..END/EXIT/EXITIF statements, and the SWITCH/CASE/ENDSWITCH statement the HLA Standard Library pro vides. 1.2 Conjunction, Disjunction, and Negation in Boolean Expressions One ob vious omission in HLA ’ s high le v el control structures is the ability to use conjunction (logical AND), disjunction (logical OR), and ne g ation (logical NO T) in run-time boolean e xpressions. This omis- sion, ho we v er , has been in this te xt, not in the HLA language. HLA does pro vide these f acilities, this section will describe their use. HLA uses the “&&” operator to denote logical AND in a run-time boolean e xpression. This is a dyadic (tw o-operand) operator and the tw o operands must be le g al run-time boolean e xpressions. This operator e v aluates true if both operands e v aluate to true. Example: if( eax > 0 && ch = ‘a’ ) then mov( eax, ebx ); mov( ‘ ‘, ch ); endif; The tw o MOV statements above execute only if EAX is greater than zero and CH is equal to the character ‘a’. If either of these conditions is false, then program execution skips over the two MOV instructions. Note that the expressions on either side of the “&&” operator may be any expression that is legal in an IF statement, these expressions don’t have to be comparisons using one of the relational operators. For example, the following are all legal expressions: @z && al in 5..10 al in {‘a’..’z’} && ebx boolVar && !eax !fileio.eof( fileHandle ) && fileio.getc( fileHandle ) <> ‘ ‘ HLA uses short circuit e v aluation when compiling the “&&” operator . If the left-most operand e v alu- ates f alse, then the code that HLA generates does not bother e v aluating the second operand (since the whole e xpression must be f alse at that point). Therefore, in the last e xpression abo v e, the code will not e x ecute the call to fi leio.g etc if the fi le pointer is currently pointing at the end of the fi le. Note that an e xpression lik e “eax < 0 && ebx <> eax” is itself a le g al boolean e xpression and, therefore, may appear as the left or right operand of the “&&” operator . Therefore, e xpressions lik e the follo wing are perfectly le g al: eax < 0 && ebx <> eax && !ecx The “&&” operator is left associati ve, so the code that HLA generates evaluates the expression above in a...
View Full Document

This note was uploaded on 08/08/2011 for the course CS 101 taught by Professor Jitenderkumarchhabra during the Summer '11 term at National Institute of Technology, Calicut.

Page1 / 24

AdvancedControlStructures - Advanced High Level Control...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online