1. Homepage
  2. Programming
  3. 159.341 Programming Languages - Assignment 1: Imperative string-processing language parser/interpreter

159.341 Programming Languages - Assignment 1: Imperative string-processing language parser/interpreter

Engage in a Conversation
Massey159.341Programming LanguagesConcurrencyEBNFImperative string-processing languageParserInterpreter

159.341 – 2024 Semester 1   Assignment 1 CourseNana.COM

Deadline: Evaluation:
Late Submission
: Work: CourseNana.COM

Purpose:
Problem to solve: CourseNana.COM

20 marks – which is 20% of your final grade
2 marks off per day late
This assignment is to be done
individually – your submission may be checked for plagiarism against other assignments and against Internet repositories. CourseNana.COM

To reinforce ideas covered in the lectures for understanding grammars, parsers and imperative programming language concepts. CourseNana.COM

Write a parser/interpreter for a simple, imperative string-processing language. CourseNana.COM

Requirements: CourseNana.COM

The interpreter must implement the language described below. The interpreter should read input from the standard input (stdin) and write output to the standard output (stdout). The interpreter should read statements from the user one at a time and perform the associated action immediately. If invalid input is provided, the interpreter should attempt to recover and try to provide a useful error message. CourseNana.COM

Strings Language: CourseNana.COM

The EBNF grammar for the strings processing language is given below, note that bold names are used for EBNF tokens and italics names are used for tokens from the lexer (defined below). CourseNana.COM

program := { statement }
statement := append id expression end
CourseNana.COM

| | | | | | | | CourseNana.COM

list end
exit end
print expression end printlength expression end printwords expression end printwordcount expression end set id expression end reverse id end
CourseNana.COM

expression :=
value := id | constant | literal
CourseNana.COM

value { plus value } CourseNana.COM

The (incomplete) regular expressions for the tokens in the language are given below. Please note that if you use a language regular expression library then you may need to adjust the syntax for the expressions below. E.g. the '+' character is a special character in regular expressions. You may also need to use syntax to only match characters at the start of the input etc. CourseNana.COM

append
exit
list
print
printlength
printwords

Literals: CourseNana.COM

The string literals in this language are enclosed with double-quotes ("...") and may contain: CourseNana.COM

Command CourseNana.COM

 append
 list
 exit
 print
 printlength
 printwords
 printwordcount
 set

reverse CourseNana.COM

Words: CourseNana.COM

Parameters CourseNana.COM

id expression expression CourseNana.COM

expression expression expression
id expression id
CourseNana.COM

Behaviour CourseNana.COM

Evaluate the expression and print its length (characters) Evaluate the expression and print the individual words Evaluate the expression and print the number of words
CourseNana.COM

Set the contents of the variable to the expression
Reverse the order of the words in the contents of the variable.
CourseNana.COM

Some of the commands require words to be identified within a string. For this language, a word consists of any set of letters or digits separated by whitespace (or punctuation characters). The only exceptions to this are words that contain a single-quote or hypen character. For example, "let's" or "runner-up" are considered a single word. CourseNana.COM

Notes: CourseNana.COM

Your program should read from the standard input and write to the standard output, your program should not open or close any files. CourseNana.COM

One of the first things you should do is determine what language you are going to use for your program. The assignment can be completed in most languages, but some may make it easier than others. A good regular expression engine may be helpful. CourseNana.COM

The first major part of the assignment is to write a parser. You may want to consider a recursive descent parser to base your code on. This type of parser looks at the next token from the lexer and from this can decide which rule to match. For example, if the statement starts with the print token then the parser should expect to parse an expression followed by an end token. CourseNana.COM

The other main part of the assignment is writing the interpreter that will execute instructions from the program it reads. To do this, you will need to decide what data structures you will use for your symbol table which will store all the variables in your program (and provide a way to access their contents). This language has only one implicit type (a string), so your symbol table does not need to store any information about the type of the variable. CourseNana.COM

Decisions: CourseNana.COM

There are some features that have been left (intentionally) unspecified. CourseNana.COM

  • The regular expression for string literals has not been defined. How are you going to match CourseNana.COM

    string literals that contain punctuation? CourseNana.COM

  • How is your interpreter going to respond when the user enters invalid input? Your program CourseNana.COM

    should try to provide some type of error handling and should not just crash. A common approach is just to read and ignore all input until it reaches the next end token (the ';' character). CourseNana.COM

    These decisions are left up to you to make but you should document them within your assignment (in the comments is fine). CourseNana.COM

    Sample Behaviour: CourseNana.COM

    Sample input/output from the interpreter - input typed by the user is highlighted in bold (see the Stream Site for more examples). CourseNana.COM

    ---------------------------------------- 159.341 2024 Semester 1, Assignment 1 Submitted by Rick Deckard, 20191187 ---------------------------------------- set one "The cat"; CourseNana.COM

    set two "sat on the mat";
    set sentence one + SPACE + two;
    append sentence " by itself.";
    print sentence;
    The cat sat on the mat by itself. printwordcount sentence;
    Wordcount is: 8
    printwords sentence;
    Words are:
    The
    cat
    sat
    on
    the
    mat
    by
    itself
    printlength sentence;
    Length is: 33
    list;
    Identifier list (3):
    one: "The cat"
    CourseNana.COM

1. Place the following comments at the top of your program code and provide the appropriate CourseNana.COM

information (your name and ID).
Family Name, Given Name, StudentID, Assignment number, 159.341 CourseNana.COM

explain what the program is doing . . .

2. Ensure that your program prints this information to the console, for example: CourseNana.COM

   "----------------------------------------"
   "  159.341 Assignment 1 Semester 1 2024  "
   "  Submitted by: Rick Deckard, 20191187  "
   "----------------------------------------"

Hand-in: Submit your program (as a zip file) electronically through the form on the stream site. Marks will be allocated for correctness, fitness of purpose, sensible use of data structures/algorithms, use of language features and sensible comments. Good comments will help me to award you marks even if your code is not quite perfect. CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Massey代写,159.341代写,Programming Languages代写,Concurrency代写,EBNF代写,Imperative string-processing language代写,Parser代写,Interpreter代写,Massey代编,159.341代编,Programming Languages代编,Concurrency代编,EBNF代编,Imperative string-processing language代编,Parser代编,Interpreter代编,Massey代考,159.341代考,Programming Languages代考,Concurrency代考,EBNF代考,Imperative string-processing language代考,Parser代考,Interpreter代考,Masseyhelp,159.341help,Programming Languageshelp,Concurrencyhelp,EBNFhelp,Imperative string-processing languagehelp,Parserhelp,Interpreterhelp,Massey作业代写,159.341作业代写,Programming Languages作业代写,Concurrency作业代写,EBNF作业代写,Imperative string-processing language作业代写,Parser作业代写,Interpreter作业代写,Massey编程代写,159.341编程代写,Programming Languages编程代写,Concurrency编程代写,EBNF编程代写,Imperative string-processing language编程代写,Parser编程代写,Interpreter编程代写,Masseyprogramming help,159.341programming help,Programming Languagesprogramming help,Concurrencyprogramming help,EBNFprogramming help,Imperative string-processing languageprogramming help,Parserprogramming help,Interpreterprogramming help,Masseyassignment help,159.341assignment help,Programming Languagesassignment help,Concurrencyassignment help,EBNFassignment help,Imperative string-processing languageassignment help,Parserassignment help,Interpreterassignment help,Masseysolution,159.341solution,Programming Languagessolution,Concurrencysolution,EBNFsolution,Imperative string-processing languagesolution,Parsersolution,Interpretersolution,