


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A programming assignment for a university course, csci 169 – software paradigms, offered at the george washington university's school of engineering and applied science, department of computer science. Students are tasked with implementing a static type checker, tcc, for the c-- programming language. The ebnf grammar for c-- and explains the requirements for the type checker, including error handling and detection of type inconsistencies and incompatibilities.
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



The George Washington University School of Engineering and Applied Science Department of Computer Science CSci 169 – Software Paradigms – Fall 2007 Programming Assignment # 3: A Static Type Checker Due Date: Wednesday, November 14, 2007 Instructor: A. Bellaachia
Send the electronic version of your assignment to: [email protected]
The following represents the EBNF grammar for a very simple language, called C--:
program ----> {stmt} stmt ----> var_dec ";" | assign ";" | read_stat ";" | write_stat ";" | if_stmt ";" | while_stmt ";" var_dec ----> type var assign ----> var "=" expr expr ----> add_expr add_expr ----> mul_expr {("+"|"-") mul_expr} mul_expr ----> simple_expr {("*"|"/"|"%") simple_expr } simple_expr ----> id | var | "(" expr ")" read_stat ----> "READ" "(" expr ")" write_stat ----> "PRINT" "(" expr ")" type ----> "int" | "float" | "boolean" id ----> Digit | Digit id Digit ----> [0-9]+ boolean ----> "0" | "1"; var ----> [A-Z, a-z]+ block ----> program [ block ] if_stmt ----> "if" bool_stmt ":" [block] [ "else:" [block] ] "end if" while_stmt ----> "while" bool_stmt "do" [block] "end while" bool_stmt ----> and_stmt | rel_stmt |boolean and_stmt ----> bool_stmt {("and"|"or") bool_stmt} rel_stmt ----> simple_expr (">"|"<"|">="|"==") simple_expr
In this project, you would like to implement, in C++, a strict static type checker, we call TCC for C--. Remember, you only need to check the types of all statements. TCC reads a C--program and should:
{ Int x ; Int y ; Int z ; X = 10 ; Y = 20 ; print (x); print (x+y); read(z) z = z + x + y; print (z); }
{ if 5 > 1: { if (4>3) and (2 <5) : { print 1; print 2; } else: { print 3; print (3+1) } end if; } end if; }
Call your lexical analyzer (); //to get the next token. else if (nextToken == LEFT_PAREN_CODE ) { Call your lexical analyzer (); expr(); if (nextToken == RIGHT_PAREN_CODE ) Call your lexical analyzer (); else errors(); } else errors(); /* The expression has an error. */