comp5570-assign4 CO557 Assignment 4 David Barnes Version XXXXXXXXXX Please ensure that you are always working from the latest version of the assessment, which you can find on the Moodle page in the...

1 answer below »
it is file attached


comp5570-assign4 CO557 Assignment 4 David Barnes Version 2021.12.12.15.00 Please ensure that you are always working from the latest version of the assessment, which you can find on the Moodle page in the Assessments section. You may notify me of errors or seek clarifications either via the anonymous question asking page available from the Assessments section on the Moodle page, or via email to [email protected] Introduction This assignment is designed to provide you with a practical understanding of the task of writing the syntax analysis parts of a compiler for a high-level language called Boaz. Boaz is a language designed by me for this particular assessment so you should not expect to find any additional information about it elsewhere on the Web/Internet. This document is the definitive definition/description of Boaz. Date set: 6th December 2021. Date due: 24th January 2022. 21st January 2022. Deadline 23:55. Submission: Moodle page for COMP5570. Submit a single zip file of the source files of your complete implementation and the scripts required to compile and/or run it. Requirements The main requirement of this assessment is to write a lexical analyser and recursive-descent parser for the language defined in this document. Boaz source files are stored in a text file whose name ends in a '.boaz' suffix. Your program must analyse a single Boaz source file named as its only command-line argument. Your program will only be tested with files with the correct suffix. The grammar to which valid programs must conform is given below. There is a further challenge element, concerned with type checking, worth 20% of the marks. The program must not output anything other than a single diagnostic message on standard output at the end of the parse. The message must be: ok for a successful parse or error for an unsuccessful parse. Ferrae Thompson Ferrae Thompson A single error in the source file should cause the parser to output the error notification and stop the parse. No error recovery is required. Note that the message must be written to standard output (System.out in Java) regardless of whether the parse is successful or not. You may implement the program in a language of your choice under the constraints that the language must be available to the marker on raptor and it must be possible for the marker both to compile (where required by the language) and execute your code without having to install a particular IDE or any other software, such as libraries or build tools. These constraints are important. Any libraries required must either be bundled with your submission or already pre-installed and accessible to the marker. Plagiarism and Duplication of Material The work you submit must be your own. We will run checks on all submitted work in an effort to identify possible plagiarism, and take disciplinary action against anyone found to have committed plagiarism. Some guidelines on avoiding plagiarism: • One of the most common reasons for programming plagiarism is leaving work until the last minute. Avoid this by making sure that you know what you have to do (that is not necessarily the same as how to do it) as soon as an assessment is set. Then decide what you will need to do in order to complete the assignment. This will typically involve doing some background reading and programming practice. If in doubt about what is required, ask a member of the course team. • Another common reason is working too closely with one or more other students on the course. Do not program together with someone else, by which I mean do not work together at a single PC, or side by side, typing in more or less the same code or doing the equivalent in an online setting. By all means discuss parts of an assignment, but do not thereby end up submitting the same code. • It is not acceptable to submit code that differs only in the comments and variable names, for instance. It is very easy for us to detect when this has been done and we will check for it. • Never let someone else have a copy of your code, no matter how desperate they are. Always advise someone in this position to seek help from their class supervisor or lecturer. Otherwise, they will never properly learn for themselves. • It is not acceptable to post assignments on sites such as Freelancer and we treat such actions as evidence of attempted plagiarism, regardless of whether or not work is payed for. In addition, posting anywhere other than kent.ac.uk would be an infringement of the author’s copyright. • It is not acceptable to post assignments on sites such as Chegg, Freelancer, etc. and we treat such actions as evidence of attempted plagiarism, regardless of whether or not work is paid for. Further advice on plagiarism and collaboration is available from https://www.cs.kent.ac.uk/teaching/student/assessment/plagiarism.local Ferrae Thompson You are reminded of the rules about plagiarism that can be found in the Stage Handbook. These rules apply to programming assignments. We reserve the right to apply checks to programs submitted for assignment in order to guard against plagiarism and to use programs submitted to test and refine our plagiarism detection methods both during the course and in the future. Grammar for Boaz Here is the grammar of the Boaz language. Note that this has been expressed in a slightly different form from that in the book/slides. You should use this grammar as the basis for structuring your parser. Each rule of the grammar has a ‘non-terminal’ symbol on the left-hand side of the ‘::=’ symbol. On the right-hand side of ‘::=’ is a mix of ‘terminal’ symbols, non-terminal symbols and grammatical notation, terminated with a semicolon. The meaning of the grammatical notation is described below. • The notation ::= means 'is defined as'. • A semicolon marks the end of each non-terminal 'rule'. • Parentheses group terminal and non-terminal symbols as a single item. • A ? means the single preceding item is optional or the preceding parenthesized items as a group are optional. For instance: a b ? c means that both ac and abc are valid and (a b) ? c means that both c and abc are valid. • One or more items enclosed between curly brackets means the enclosed items occur zero or more times. For instance: { a b } means that ab may occur 0, 1, 2 or more times; e.g., abab, abababab,ababababababab are all valid. • A | separates alternatives. For instance: { a | b | c } means that either a or b or c is valid. • Items all in upper-case are terminal symbols: an identifier (IDENTIFIER), keyword (BEGIN, IF, etc.), integer constant (INT_CONST) or character constant (CHAR_CONST). • Items enclosed in single quotes are terminal symbols, e.g. ';' and ':='. In the grammar be careful to distinguish between those characters not enclosed between single-quote characters (e.g., ::= and ;) and those that look similar but are enclosed (e.g., ':=' and ';'). program ::= PROGRAM IDENTIFIER varDecs BEGIN statements END ; varDecs ::= { varDec ';' } ; varDec ::= type varList ; type ::= INT | CHAR; varList ::= IDENTIFIER { ',' IDENTIFIER } ; statements ::= { statement ';' } ; statement ::= assignStatement | ifStatement | printStatement | whileStatement ; assignStatement ::= IDENTIFIER ':=' expression ; ifStatement ::= IF expression THEN statements ( ELSE statements ) ? FI ; printStatement ::= PRINT expression ; whileStatement ::= WHILE expression DO statements OD; expression ::= term { binaryOp term } ; binaryOp ::= arithmeticOp | booleanOp | relationalOp ; arithmeticOp ::= '+' | '-' | '*' | '/' ; booleanOp ::= '&' | '|' ; relationalOp ::= '=' | '!=' | '<' |="" '="">' | '<=' |="" '="">=' ; term ::= INT_CONST | CHAR_CONST | IDENTIFIER | '(' expression ')' | unaryOp term ; unaryOp ::= '-' | '!' ; Comments Comments are not permitted in Boaz programs. Example program The following (nonsense) program illustrates the main syntactic features defined by the grammar. program example int num, sum; char ch; begin sum := 0; num := 1; ch := "a"; while ch < "z" do if num / 3 != 0 & ch != "y" then sum := sum + num * 2; ch := ch + 1; else sum := sum - num; ch := "m"; fi; num := num + 1; od; print sum; print ch; end definitions of terminal symbols: lexical analysis • the following are all keywords of the language: begin, char, do, "z"="" do="" if="" num="" 3="" !="0" &="" ch="" !="y" then="" sum="" :="sum" +="" num="" *="" 2;="" ch="" :="ch" +="" 1;="" else="" sum="" :="sum" -="" num;="" ch="" :="m" ;="" fi;="" num="" :="num" +="" 1;="" od;="" print="" sum;="" print="" ch;="" end="" definitions="" of="" terminal="" symbols:="" lexical="" analysis="" •="" the="" following="" are="" all="" keywords="" of="" the="" language:="" begin,="" char,="">
Answered Same DayJan 23, 2022

Answer To: comp5570-assign4 CO557 Assignment 4 David Barnes Version XXXXXXXXXX Please ensure that you are...

Tanisha answered on Jan 24 2022
119 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here