0% found this document useful (0 votes)
3 views3 pages

Problem Statement

The document outlines the design and implementation of a compiler for a programming language that supports various data types, variable declarations, expressions, control flow statements, and block-level scoping. It details the supported data types, operators, expressions, control flow statements, semantic rules, and error detection mechanisms. The compiler ensures type checking, scope resolution, and proper error reporting for various coding issues.

Uploaded by

cs23b038
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Problem Statement

The document outlines the design and implementation of a compiler for a programming language that supports various data types, variable declarations, expressions, control flow statements, and block-level scoping. It details the supported data types, operators, expressions, control flow statements, semantic rules, and error detection mechanisms. The compiler ensures type checking, scope resolution, and proper error reporting for various coding issues.

Uploaded by

cs23b038
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Problem Statement

We aim to design and implement a compiler for a programming language that


supports multi-variable data types, variable declarations, expressions, control
flow statements, array declarations, and block-level scoping.

Data Types Supported

These are the data types which are supported by the language:

char, short, int, long, float, double, Arrays (single and Multidimensional)

Variable Declarations

The compiler supports:

Basic variable declarations.


More than one variable can be declared in one statement
Initialization during declaration (for primitive data types)
Multi-dimensional array declarations

Operators

Arithmetic Operators: Binary ( +, -, *, /, % (modulo)) and Unary (- (negation))


Relational Operators: >, <, <=, >=, ==, !=
Logical Operators: (&&, ||, !)
Bitwise Operators (&, |, ^, <<, >>)
Assignment Operators (=, +=, -=, *=, /=)
Increment/Decrement Operators ++ // Pre-increment and post-increment,
-- // Pre-decrement and post-decrement

Expressions & Type Coercion

The compiler automatically performs type conversion for compatible types, explicit
casting if necessary during intermediate code generation, and checked types for illegal
operations

Control Flow Statements


Conditional statements: if, if-else
Iterative statements: while, for, do while

Scoping and Blocks

A Block level scope is possible


Nested scopes are permitted
Variables in inner scope can hide variables in outer scope

Semantic Rules

Type checking: Implicit type conversion, type checking in assignment statements


involving implicit type conversion, modulo operator allowed in integer type arguments

L-value Checking: Variables alone are assignable, while constant and expressions are
not allowed on the left side of an assignment operation.

Declaration Checking: Variables are not permitted to be declared in the same scope,
and a type that conflicts with that of the preceding declaration of the same identifier
shall be rejected

Scope Resolution: This searches for identifiers in the current scope. The outer scopes
are searched only if they are not found in the current scope. An error message is
displayed if the identifier is not found.

Error Detection and Reporting:

Missing terminating element at end of statement will be marked as error.

Incompatible types in an expression cause type errors to be flagged( invalid operands to


binary % (float)).

Usage of unspecified variables in any scope is flagged as an error.

The same identifiers can not be redeclared in the same scope.

There are contradictory declarations for the same identifier that are printed.

A warning is issued for the improper use of l-values in assignment statements.

Operations on constants, such as post-increment or post-decrement, are illegal.

Declaring an array in an invalid way, which involves non-integer array dimensions


You might also like