Type checking in compiler

Part I: Declaration checking

The Mython language has a very simple type system as described in the Mython specification. There are only three types in Mython: integers, booleans and strings. Mython has no explicit type declarations or global variables; in general, we have to determine the type of a variable by the way it is first used in the code.

- Integers: All parameters passed in Mython are implicitly integers. Another way for a variable to get integer type is when it is first used on the left side of an assignment statement where the expression on the right side has type integer. For example, if the first use of x is x = 3 + 2, then x will have an integer type and can be used anywhere an integer is expected. An input statement can also be used to give a variable integer type. All function are type integer.

-Boolean: The only way for a variable to have boolean type is when it is first used on the left side of an assignment statement where the expression on the right side has type boolean.

-Strings: The only way for a variable to have string type is to assign a string to it on the right side of an assignment statement.

You need to see that all variables that are used in a Mython have been given a type. A variable cannot be used (on the right side of an assignment statement, in a condition for a compound statement, used in a print statement or passed as a parameter) if it hasn't given a type as described above. If this condition has been violated, print out an error message and the associated line number. Continue processing. If there is an attempt to give a different type to a name in some scope, this should also be flagged as an error. No two functions can share a name. In a given procedure/function, no two local variables or parameter can share a name. They should also not share a name with their declared scope.

Part II: Checking the Type system

The Mython specification also describes rules for type checking statements and expression. During parsing, if a type rule is violated, print an error message that explains the violation (along with associated line number) and continue processing the input.

-The left and right side of an assignment statement must have the same type. Once a variable has been given a type, that type cannot change. For example, the two statement x = 2 followed later by x = true is a violation of Mython's type system.

-input ( ) has type integer.

-Arithmetic operator (+,-,*,/) only operate on integers and the result is an integer. –

Relational operation (<,>,<=,>=,<>,==) only operate on integers and result is a Boolean.

–The expression in if and while statements must have type Boolean.

–Return expression must be type integer.

-Parameters to the print function can be integer, Boolean or strings.

-A function cannot be called until after it has been declared. Since formal parameters are implicitly integer, actual expression must also be of type integer. A function call must have the correct number of parameters. All parameters will be passed by value.

Skills: C Programming, Linux

See more: i have a still image with a design i need you to draw it in vector form with correct alignment so we can print it on t-shirt, i have 12 scanned images and each one has 30 rows and 15 column i need you will type the data from images to excel, compiler error message cs0246 type namespace name, csv file type checking, gcc compiler endian type, checking phone type imei, true type, convert true type font unicode, gdt true type font, windows gdt true type font, free true type font, true false type questions analysis, convert true type font, unicode font convert ttf true type font, true type convert unicode, convert true type, freelancer create true type symbol font, youporn type site, youporn type sites, type business letter boss, simple code conversion currency using compiler, ex4 compiler, checking compromised linux server, type website photofunia, type tamil spreadsheet

About the Employer:
( 1 review ) Riyadh, Saudi Arabia

Project ID: #12696772

Awarded to:


Grammar is given in Yacc specification, we need to write semantic actions to assign a type to a variable and do type checking in expressions. we did a similar project before.

$50 USD in 1 day
(4 Reviews)

3 freelancers are bidding on average $75 for this job


I am compiler expert, please let me do this. I am very proficient in c and c++. I have 16 years c++ developing experience now, and have worked for more than 6 years. My work is online game developing, and mainly focus More

$150 USD in 2 days
(76 Reviews)

Hello Sir/Madam! Greetings!!! Thanks for sharing the project. I can start your project right now. I am very much interested in your project concept and of course want to get involved in this project. I got more than More

$24 USD in 1 day
(0 Reviews)