# # The IttyBitty Language # ====================== # # A program consists of one or more statements, # with the permissible token types and list of statement # grammar rules described below # # Note that tokens must all be whitespace delimited, # token names begin with a lowercase letter, # non-terminal language component names begin with an uppercase letter # # Comments in IttyBitty begin with a # and go to eoln # and are removed by the tokenizer # Tokens: # ======= # variable [a-zA-Z]+ # integer [-]?[0-9]+ # quote " # text between quotes, this is any block of non-whitespace # characters that does not contain a quote # mathop +, -, *, /, % # assignop = # compop ==, <, !=, <=, >=, > # keyword if, while, print # bracket ( ) # delimiter { } # unknown any otherwise unrecognized string of non-whitespace characters # Grammar rules # ============= # Program --> StatementList # StatementList --> Statement # StatementList --> Statement StatementList # Statement --> VarAssign # Statement --> Loop # Statement --> Conditional # Statement --> Print # VarAssign --> variable assignop Expression # Print --> print Value # Print --> print Text # Text --> quote WordList quote # WordList --> text # WordList --> text WordList # Conditional --> if Condition Block # Loop --> while Condition Block # Condition --> bracket-( Value compop Value bracket-) # Value --> variable # Value --> integer # Block --> delimiter-{ StatementList delimiter-} # Expression --> Value # Expression --> Value mathop Expression # Sample program # -------------- # print " Welcome! " # mid = 3 # x = -4 # y = 10 # while ( x < y ) { # if ( x == mid ) { # print " mid point reached " # } # print " x is " # print x # x = x + 1 # }