This project implements a domain-specific language (DSL) for managing a library. Users can add/remove books, borrow/return them, search by keyword, and execute batch commands. The DSL is defined by a BNF grammar and parsed into algebraic data types.
Application Domain: Library Management System – Track books and users efficiently!
- Book: Identified by a title (String, e.g., "The Great Gatsby").
- User: A person who can borrow and return books (String, e.g., "Alice").
- Command: DSL operations that manipulate the library state.
All strings must be enclosed in double quotes ("..."). Whitespace is optional around keywords and separators.
-
Add a book:
AddBook "The Great Gatsby" -
Remove a book:
RemoveBook "1984" -
Borrow a book:
BorrowBook "Alice" "The Great Gatsby" -
Return a book:
ReturnBook "Alice" "The Great Gatsby" -
Search for a book:
SearchBook "Gatsby" -
Batch multiple commands:
Batch AddBook "1984" ; BorrowBook "Bob" "1984" ; Dump Examples -
Dump examples:
Dump Examples
Note: Supports spaces in titles (e.g., "Harry Potter and the Philosopher's Stone") and symbols like
. , ! ? - _.
<program> ::= <command>
<command> ::= <add_book> | <remove_book> | <borrow_book> | <return_book> | <search_book> | <dump> | <batch>
<add_book> ::= "AddBook" <ws> <string>
<remove_book> ::= "RemoveBook" <ws> <string>
<borrow_book> ::= "BorrowBook" <ws> <string> <ws> <string>
<return_book> ::= "ReturnBook" <ws> <string> <ws> <string>
<search_book> ::= "SearchBook" <ws> <string>
<dump> ::= "Dump" <ws> "Examples"
<batch> ::= "Batch" <ws> <command_list>
<command_list> ::= <command> ( ";" <ws> <command> )*
<string> ::= <chars>
<chars> ::= <char>
<char> ::= <letter> | <digit> | " " | "." | "," | "!" | "?" | "-" | "_"
<letter> ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
| "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<ws> ::= " "*