Parsing Exercise

 

Dim num as integer

Dim myTextString1, myTextString2 as String

myTextString1 = "10"

myTextString2 = "5"

if ComboBox1.text = "+" then
' calculate the results

num = val(myTextString1) + val(myTextString2)

elseif ComboBox1.text = "-" then

num = val(myTextString1) - val(myTextString2)

else

num = val(myTextString1) * val(myTextString2)

end if


'put the results in the answer field
staticText1.text = str(num)

Parse each word of the statement and categorize it according to the following types:

Variables of types String or Integer

Built-in controls (examples are editfields, statictexts and comboBoxes...)

Methods

Reserve Words - words that mean something special to REALbasic

Comment indicators

Operators

For Example "+" is a temporary String. It is a String because it is quoted. It is temporary because it is not stored in a variable and therefore does not have to be Dim-ed.