6 — Class: Syntax
Due Thursday, 16 October 2025, 11:59:59pm
Purpose to build a model of the syntax of a language with a simple class system
Warning This assignment is one of the two largest this semester. Getting
started early and working systematically—
Delivery Deliver your solutions in a directory called 6 within your assigned GitHub repository. The directory should contain the following items:
the executables xclass as specified below;
the sub-directory 6/Tests/ with the required integration test; and
an optional sub-directory called 6/Other/ for all auxiliary files.
Programming Task Using your favorite programming language, you are to create a syntax model of the Class language, an extension of Core with a simple class system. This task requires (1) the extension of the parser; (2) new validity-checking passes; and (3) an adaptation of the existing validity checker.
ExampleDD is an Example whose Names also contain the following keywords: if0, while0, block, def, =, /, +, ==, class, method, isa, new, –>.
See figure 8 for the grammar of the Class language.
The implementation of the parser should adapt your solution to 4 —
The adaptation of the validity checker must confirm that every occurrence of a variable in an expression or statement comes with a matching declaration or method parameter in its context. The checker consumes an error-free AST of a Class program, walks the tree, and replaces all variable occurrence that violate the validity constraint so that an IDE would be able to notify a Class programmer in a suitable manner.
No two class definitions should have the same ClassName.
In a single class, no two methods and no two fields should have the same name, respectively.
Within a method, no two parameters should have the same name.
The occurrence of every ClassName in a Statement or an Expression must refer to a defined class.
Hint Since the validity checker for Class performs distinct
tasks, the principles of Fundamentals 1 and 2 dictate that your implementation
composes several helpers—
Program ::= (Class^* Declaration^* Statement^* Expression)
Class ::= (class ClassName (FieldName^*) Method^*)
Method ::= (method MethodName (Parameter^*)
Declaration^*
Statement^*
Expression)
Declaration ::= (def Variable Expression)
Statement ::= (Variable = Expression)
| (if0 Expression Block Block)
| (while0 Expression Block)
| (Variable --> FieldName = Expression)
Block ::= Statement
| (block Declaration^* Statement^+)
Expression ::= GoodNumber
| Variable
| (Variable + Variable)
| (Variable / Variable)
| (Variable == Variable)
| (new ClassName (Variable^*))
| (Variable --> FieldName)
| (Variable --> MethodName (Variable^*))
| (Variable isa ClassName)
The set of ClassNames is the same as the set of Variables.
The set of FieldNamess is the same as the set of Variables.
The set of MethodNames is the same as the set of Variables.
The set of Parameters is the same as the set of Variables.
The set of Variables consists of all Names, minus keywords.
The set of GoodNumbers comprises all inexact numbers
(doubles) between -1000.0 and +1000.0, inclusive.
The xclass program reads one ExampleDD from STDIN, constructs the AST, performs the validity checks, and writes one of the following strings to STDOUT: The outcomes are listed in the order in which they may occur for a given program.
"parser error" if the given ExampleDD is not an element of the Class grammar;
"duplicate class name" if in the well-formed Class program two of the class definitions come with the same name;
"duplicate method, field, or parameter name" if in the well-formed Class program one class definition one method definition, or one Shape comes with (at least) two fields, methods, or parameters that have the same name;
"undeclared variable error" if in the well-formed Class program one of the variable references comes without declaration or one reference to a ClassName (in a statement or an expression) comes without a (possibly imported) class definition;
"belongs" if the given ExampleDD is a well-formed and valid Class program.
Testing Task Create 10 integration tests for xclass.
A test always consists of inputs, expected
output, and an automated procedure for comparing the actual output
with the expected one. —