Using c++ I made a parse tree that when given an appropriate language it will parse the language checking for any errors and if there are no errors then it will execute the program. If errors exist in the code it will tell on what line the errors exist and why it is incorrect
SEMANTIC RULES FOR THIS LANGUAGE
- There are only two types: integer and string
- Variables are assigned a value using set
- An expression can be printed using either print or println
- There is one single scope for variables
- Variable names must be unique
- Adding two integers gets the sum
- Subtracting two integers gets the difference
- Multiplying two integers gets the product
- Dividing two integers gets the quotient
- Adding two strings will concatenate the strings
- Multiplying an integer and a string results in a string repeated integer times ( 3 * "hi" = "hihihi" )
- Dividing two strings results in a string where the first instance of the denominator that is found in the numerator is removed
EXAMPLE PROGRAM
int x;
int y;
string z;
set x 5;
set y 3;
set z "hi";
println x+y;
println z*x;
OUTPUT OF ABOVE PROGRAM
hihihihihi
8