1 of 9

TinyCStr

Compiler Design Lab

JNTUGV CEV

18-07-2026

2 of 9

TinyCStr features

  1. Procedural language
  2. Statically typed
  3. Set of operators : { Arithmetic operators, relational operators, ternary operator (?:), type casting operator)
  4. Set of control flow statements: { if-else, while}
  5. Set of data types : { int, double, char, string }
  6. Single line comment
  7. Limited I/O support : only output support(print)

3 of 9

TinyCStr program structure

Every TinyC program has an optional global declarations followed by one or more functions and one function must be main.

Every TinyC function has zero or more TinyC statements

Every TinyC statement is any of the following, an assignment statement, a control flow statement, a return statement, a declaration statement, a TinyC print statement

1

2

3

4 of 9

TinyCStr examples: Example 1

int main(){

int a,b,c;

a=5;

b=5;

c=a+b; // all statements are similar to C, except print

print c; // print is predefined operator in TinyCStr which prints the value of c

}

5 of 9

TinyCStr example Example2

int main(){

int a=30;

Int b =40;

c=a+b*a+a*a;

print a;

}

6 of 9

TinyCStr examples: Example 3

int a=40,b=50;

double c;

int main(){

if(a>b)

c=(double)a/b;

else

c=(double)b/a;

print c;

}

7 of 9

TinyCStr examples: Example4

int a,b,c;

double d,e,f,;

int add(int,int); //declaration of function

double mult(double,double);

int main(){

c=add(30,40);

d=mult(40.8,50.2);

a=-5;

b=-45;

c= add(a,b);

print c;

}

Int add(int a1, int a2){

return a+b;

}

8 of 9

Implementation of TinyCStr

  1. Write a compiler which takes TinyC progarm as an input and converts it to an valid assembly language code.
  2. SPIM is used to test the generated assembly language code

Compilation:

Lexical analysis -> Syntax Analysis -> Semantic Analysis -> Intermediate code generation -> Code Optimization -> Code generation

Interpretation:

Lexical analysis -> Syntax Analysis -> Semantic Analysis -> Evaluate statements

9 of 9

Translation vs Evaluation: Example

int main(){

int a,b,c;

a=5;

b=25;

c=a*a+b-20; // all statements are similar to C, except print

print c; // print is predefined operator in TinyC which prints the value of c

}

Evaluation gives :