# SI413 Unit 2 Languages language_name: Arrr! notes_from_prof: | Language designed by LCDR Norine. It is a prefix language, meaning the operation name always comes before the arguments, and parentheses are usually not necessary. The language has a lot of keywords as opposed to operator characters. The grammar is designed to support static type checking, by separating boolean from string expressions. example_program: | !Blimey! Stash the true password ye land lubber! Scallywag! Stash Booty correctPass ~~backwards~~ !Blimey! Get the secret input from the user. They should type in "sdrawkcab" Scallywag! Avast Booty ~~Enter the password or walk the plank!~~ Stash Booty userInput Savvy? !Blimey! Now, we check if the REVERSED user input is the same as the correct password! Swab userInput --> should become "backwards" if typed correctly Cog ![ Swab userInput ]! correctPass --> should return true (Aye!) Scallywag! Avast Loot Cog ![ Swab userInput ]! correctPass !Blimey! Now that we know they have the right password, we need to check if they know where our treasure is! Scallywag! Avast Booty ~~Where is the treasure located?~~ Restash Booty userInput Savvy? !Blimey! We know it's under the tree, and the location is larger than "Port Royale" Scallywag! Avast Loot Chantey ![ Spyglass userInput ~~tree~~ ]! ![ SmallerCog ~~Port Royale~~ userInput ]! !Blimey! But is their name lucky? We need to know! x marks the lucky spot! Scallywag! Avast Booty ~~What is your first name?~~ Stash Booty firstName Savvy? Avast Booty ~~What is your last name?~~ Stash Booty lastName Savvy? Stash Booty fullName Ahoy firstName lastName Avast Booty fullName Avast Loot Spyglass fullName ~~X~~ !Blimey! Let's sail the seven seas with lots of tildes by putting dots in the string delimiters. Scallywag! Avast Booty ~.~~~~~~~~~~~~~~~~~~~~~.~ example_input_1: | sdrawkcab under the tree! Chancho the Mad example_output_1: | Aye Aye Nay example_input_2: | hunter2 out past Zombie Island! Xanadu the Insane example_output_2: | Nay Nay Aye tokens: | LP: !\[ RP: \]! LOGIC_OP: Chantey|Parley LOGIC_NOT: Scuttle STR_CONTAIN: Spyglass STR_CMP: (Smaller)?Cog CONCAT: Ahoy REVERSE: Swab INPUT: Savvy\? PRINT: Avast ASSIGN: Stash|Restash STR_LIT: (~\.*~).*?\1 BOOL_LIT: Aye|Nay STR_TYPE: Booty BOOL_TYPE: Loot ID: [a-zA-Z][a-zA-Z0-9]* ignore: [ \t\r\n] ignore: !Blimey![\s\S]*?Scallywag! grammar: | program -> stmt program -> ε stmt -> ASSIGN STR_TYPE ID str_expr -> ASSIGN BOOL_TYPE ID bool_expr -> PRINT STR_TYPE str_expr -> PRINT BOOL_TYPE bool_expr str_expr -> LP str_expr RP -> CONCAT str_expr str_expr -> REVERSE str_expr -> INPUT -> STR_LIT -> ID bool_expr -> LP bool_expr RP -> LOGIC_OP bool_expr bool_expr -> LOGIC_NOT bool_expr -> STR_CONTAIN str_expr str_expr -> STR_CMP str_expr str_expr -> BOOL_LIT -> ID semantics: | -I adopted a prefix notation for the language, for better or worse. The operators all work on arguments passed AFTER them, so string concatenate takes the two expressions after "Ahoy" and returns a single string. -True and False will remain like that under the hood, but in my language they are Aye and Nay. Those words outside of a string will be treated as boolean literals and not strings. If printed, they will output Aye and Nay respectively. -There are no escape characters in string literals. The delimiters can be ~~ or ~.~ or ~..~ or ~...~ etc., but must match on the left and right of each string literal. -Chantey means logical AND, Parley means logical OR. -Cog means string equality, SmallerCog means string less-than.