Haskell Buffer Language

In this Assignment you’ll be defining a language to manipulate text in a buffer. This assignment is very free form, you’ll be defining your own language, with your own grammar, and will write an interpreter for your language. You are free to use whatever Haskell libraries and functions you deem necessary.

The Buffer language is a language that describes the manipulation of a text buffer in relation to a cursor. The Buffer language supports the following commands:

– You can move the cursor, up, left, down, and right. If you reach the end of the buffer, then subsequent moves should not move the cursor.

– You can insert text. This writes text to the buffer and moves the cursor to the end of the text that was inserted. This text should be persist until it is written over or deleted.

– You can copy text, that is in the buffer. Copy should take another cursor position and copy everything from the current cursor position to the input cursor position, even if the input cursor position is not on the same line. Note that there is no Paste command!

– You can set the cursor to a specific location in the buffer.

Note that I have not told you how big a buffer is or should be. This is for you to decide and will impact your choice of data structures, types, and your semantics. I will not accept any implementations that are made not in good faith, such as defining your buffer to only be only a single character or a single row of text. Whatever your implementation, your buffer should be able to expand as needed and as dictated by the programs in the Buffer Language.

  1. Define the syntax for your Buffer language. (0.5 points)
  2. Write two programs in your concrete syntax. (0.25 points each)
  3. Encode your syntax into Haskell. (0.5 points)
  4. Translate the same two programs to abstract syntax as values of your data types. (0.25 points each)
  5. Define and implement the semantics of your Buffer language. Make sure to define the semantic domain either in a comment or a type synonym. (0.5 points)
  6. Does your language have expressions or statements? Say why each command is either an expression or a statement. (0.5 points)
  7. After you’ve finished your interpreter from 3. Extend your language with two new commands without changing your Haskell data types. That is to say, add these commands as syntactic sugar:
  8. Jump. Jump should move the cursor to an input position (0.25 points)
  9. Delete. Delete should take a cursor position, and delete everything from the current cursor position to the input cursor position, even if the input cursor position is not on the same line. (0.5 points)
  10. Write a program in your language that uses both jump and delete (0.25 points)
  11. Define and implement a pretty printer for your Buffer language. The location of the cursor should be shown with ‘|’ (a pipe symbol), if the cursor is not observable in the buffer (it is offscreen) then it should not be printed. An empty cell in your buffer should be represented with a ‘.’ (a dot). See the template file for examples. To nicely print in the repl you’ll probably want to use putStrLn instead of print. putStrLn actually performs the effect of printing and so any newlines “\n” will be evaluated like a newline in the repl. (1 point)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值