I need help with my compiler design project
Budget: $30 – $250 USD
You are required to write a compiler which generates SSM assembly code for the language
LP23x. You are provided with a formal grammar for LP23x and a prototype compiler, as well
as grammars for two simpler variants of the language (LP23xs and LP23xef: these
correspond to the language subsets assessed in tasks 1 and 2, respectively). Note that these
three grammars are essentially solutions to the tasks set for Part 1 of the coursework, except
that variables are declared explicitly (this makes life slightly easier for a compiler writer).
You are provided with some test inputs (the expected output is given as a header comment
in each file). This is not an exhaustive test suite and you are free to write your own tests.
Assessment will be carried out by automated testing using these and other tests.
The semantics of the language is essentially standard and most language constructs have an
obvious counterpart in languages like Java and C. Key differences and similarities:
• LP23x is untyped. All expressions evaluate to a 32-bit signed integer.
• LP23x has three types of variables: global variables, formal parameters, and local
variables. Global variables are statically allocated. Formal parameters and local
variables are stack-allocated. The scope of a formal parameter or local variable is the
body of the function in which it is declared. Formal parameter and local variable
names are allowed to clash with global variable names (creating a hole in the scope
of the global variable) but all local variable and formal parameter names within a
given function must be distinct.
• In Boolean constructs, 0 is treated as False and all other values are treated as True.
Comparison and logical operators all evaluate to either 0 or 1.
• If a function call terminates without executing a return statement, the function
returns 0 by default. Return statements are also allowed in the main program block,
where the effect is to halt execution (the return expression is evaluated but its value
is ignored in this case).
• As in C and Java, the && and || operators have “short circuit” semantics. When the
first argument of && evaluates to False (0), the second argument is not evaluated
and the operator returns 0 immediately. Dually, when the first argument of ||
evaluates to True (any non-zero value), the second argument is not evaluated and
the operator returns 1.
• All other operator and function arguments are evaluated left to right and passed by
value (fully evaluated before the call).
• New arrays are created using expressions of the form malloc[e] where the value
of e determines the size of the new array. The behaviour of malloc is to allocate a
block of heap memory of the specified size, initialise its contents to all zeroes, and
return its start address. Arrays in LP23x are like arrays in C (not Java): arrays do not
have a length field and there is no run-time bounds checking. If a program attempts
to use a non-array value as an array, or to access an array out of bounds, the
expected behaviour is undefined (none of the provided test inputs do these things).
(TO BE CONTINUED...)
(MORE INFORMATION IN THE PDF ATTACHED)
LP23x. You are provided with a formal grammar for LP23x and a prototype compiler, as well
as grammars for two simpler variants of the language (LP23xs and LP23xef: these
correspond to the language subsets assessed in tasks 1 and 2, respectively). Note that these
three grammars are essentially solutions to the tasks set for Part 1 of the coursework, except
that variables are declared explicitly (this makes life slightly easier for a compiler writer).
You are provided with some test inputs (the expected output is given as a header comment
in each file). This is not an exhaustive test suite and you are free to write your own tests.
Assessment will be carried out by automated testing using these and other tests.
The semantics of the language is essentially standard and most language constructs have an
obvious counterpart in languages like Java and C. Key differences and similarities:
• LP23x is untyped. All expressions evaluate to a 32-bit signed integer.
• LP23x has three types of variables: global variables, formal parameters, and local
variables. Global variables are statically allocated. Formal parameters and local
variables are stack-allocated. The scope of a formal parameter or local variable is the
body of the function in which it is declared. Formal parameter and local variable
names are allowed to clash with global variable names (creating a hole in the scope
of the global variable) but all local variable and formal parameter names within a
given function must be distinct.
• In Boolean constructs, 0 is treated as False and all other values are treated as True.
Comparison and logical operators all evaluate to either 0 or 1.
• If a function call terminates without executing a return statement, the function
returns 0 by default. Return statements are also allowed in the main program block,
where the effect is to halt execution (the return expression is evaluated but its value
is ignored in this case).
• As in C and Java, the && and || operators have “short circuit” semantics. When the
first argument of && evaluates to False (0), the second argument is not evaluated
and the operator returns 0 immediately. Dually, when the first argument of ||
evaluates to True (any non-zero value), the second argument is not evaluated and
the operator returns 1.
• All other operator and function arguments are evaluated left to right and passed by
value (fully evaluated before the call).
• New arrays are created using expressions of the form malloc[e] where the value
of e determines the size of the new array. The behaviour of malloc is to allocate a
block of heap memory of the specified size, initialise its contents to all zeroes, and
return its start address. Arrays in LP23x are like arrays in C (not Java): arrays do not
have a length field and there is no run-time bounds checking. If a program attempts
to use a non-array value as an array, or to access an array out of bounds, the
expected behaviour is undefined (none of the provided test inputs do these things).
(TO BE CONTINUED...)
(MORE INFORMATION IN THE PDF ATTACHED)