You are on page 1of 3

1.

Sample output

2. Lessons learned

In the program we learn about a string tokenizer as a program that breaks an expression into units.
The tokenizers are used to develop compilers for different programming languages. A valid
mathematic expression consist of Literals, Variables Operators and functions. There are also function
arguments. The following notes are important from the lessons.

Literal can only be a number in decimal format

A variable used in tokenization are restricted to single letters.

The operators act on literals and variables. The only permitted operators include +, -, *, / and ^

Function argument Separator is another name given to a comma, a comma is used in separating the
arguments.

Data modeling is important in tokenization. A number like eleven is reported as two literal instead of
one. A word line Sin is reported as three tokens. Therefore variables are single characters that can
occur together in an implicit multiplication. The solution to this is using a string buffer. For example
one buffer can be used to hold Literal characters and another buffer used to hold letters.

In order to analyse a string, a function must be configured to measure what it wants to do vs what it
measures. The programmer should ask themselves if the function works as intended and the
analyser covers all the edge cases. The edge cases could be negative numbers, tests can also be run
on the function.

3. Test Cases 1

The test case covers all the arithmetic operations

Input

(x+y), x = 2, y= 6; /* Expect value = 8 */


(x-y), x=0, y=0; /* Expect value = 0 */
((x+y)/(x-y)), x=10, y=8; /* Expect value = 9 */
((x/y)/(x-y)), x=16, y=2; /* Expect value = 0 */
(x/y), x=25, y=5; /* Expect value = 5 */

Expected output
(x+y), x = 2, y= 6; /* Expect value = 8 */
(x-y), x=0, y=0; /* Expect value = 0 */
((x+y)/(x-y)), x=10, y=8; /* Expect value = 9 */
((x/y)/(x-y)), x=16, y=2; /* Expect value = 0 */
(x/y), x=25, y=5; /* Expect value = 5 */

Actual Output

Test Case 2

Test Case 3

(x+y), x = 5, y= 5; /* Expect value = 10 */


((x+y)/(x-y)), x=12, y=8; /* Expect value = 5 */
((x/y)/(x-y)), x=16, y=2; /* Expect value = 0 */
(x/y), x=4, y=1; /* Expect value = 4*/
References

Durieux, D., Ponsard, C., & Deprez, J. C. QualiXML-an XML-based Static Code Analysis
Framework.

You might also like