# SI413 Unit 2 Languages language_name: mashup notes_from_prof: | Language designed by George Prielipp and reviewed by Nate Schmidt. This language has infix operators and uses smiley faces for boolean literals. The variable names are typed like s.name or b.name, which allows the parser rules to completely distinguish booleans from strings. There is also a way (with the "s" command) to convert a boolean into a string. example_program: | # gets the user input # s.name <- ?; # see if they have a good name # ['Your name makes me' + s(s.name == 'George')]; # see if a string is greater than mine # ['Your string is ' + s(? > '2026') + ' greater than my string']; # 'navy' contains 'van' in reverse, so this prints :) # ['navy' <- >< 'van']; # we can also save boolean variables # b.happy <- :); b.sad <- d b.happy; # print out the not of some boolean: expect ':)' # # pythonic: print(not (True and False or False))# [d(:) & :( | :()]; example_input_1: | George 2025 example_output_1: | Your name makes me :) Your string is :( greater than my string :) tokens: | ASSIGN: <- END: ; LBRACK: \[ RBRACK: \] LPAREN: \( RPAREN: \) COMP: <|>|<=|>=|== BOOL_LIT: :\)|:\( NOT: d PLUS: \+ REV: >< BOOL_OP: &|\| INPUT: \? BTYPE: b STYPE: s IDENTIFIER: \.[a-zA-Z_$][a-zA-Z_$0-9]*? STR_LIT: '([^']|\\')*' ignore: #.*?# ignore: [ \t\n] grammar: | prog -> stmt prog -> ε stmt -> LBRACK str RBRACK END -> LBRACK bool RBRACK END -> STYPE IDENTIFIER ASSIGN str END -> BTYPE IDENTIFIER ASSIGN bool END str -> str PLUS str -> REV str -> STR_LIT -> INPUT -> STYPE IDENTIFIER -> LPAREN str RPAREN -> STYPE bool bool -> BOOL_LIT -> str COMP str -> str ASSIGN str -> NOT bool -> bool BOOL_OP bool -> BTYPE IDENTIFIER -> LPAREN bool RPAREN semantics: | A program is a list of statements separated by semi-colons. Print statements are expressions inside of brackets []. The order of evaluation for any expression can be reordered explicitly with surrounding parenthesis. All of the boolean operators return booleans, and can be chained. Strings have comparison operators that return booleans. True and False literals look like :) and :( respectively. Boolean values will be printed as :) and :(. Variables are defined as a type (s for string, b for bool) followed by .identifier. Assignment looks like a variable declaration (s .identifier) followed by the assignment operator (<--) and an expression that evaluates to the same type specified by the variable. Reassignment looks like the identifier followed by an assignment.