Explore BrainMass

Compilers and Language Translation: Token Identification

1. Identify the tokens in each of the following statements.

a. if (a == b1) a = x + y;
b. delta = epilson + 1.23 - sqrt(zz);
c. print(Q);

2. Assume that we are looking in a programming language that allows underscore (_) in variable names. When a scanner sees a character string such as AB_CD, is it more likely to identify this string as the single five-character token AB_CD or as three separate tokens: AB, _, CD? Explain your answer.

Solution Preview

1. Tokens are separated by comma below.

a. "if", "(", "a", "==", "b1", ")", "a", "=", "x", "+", "y", ...

Solution Summary

Answer just identifies the tokens. It does not classify them as ID, NUMBER etc..