Question: A very simple toy language: statements separated with 's' empty statement between consecutive ;' is OK last statement can optionally followed by ';' at least
A very simple toy language: statements separated with 's' empty statement between consecutive ;' is OK last statement can optionally followed by ';' at least one space between all lexemes tab and newline char are ignored variables: var name (identifier) consists of lower letter only (no digits, spaces, punctuations) following words are reserved and can not be used as variable names: print, if, then examples of legal variables: x, y, apple, hello examples of illlegal variables: x4, Apple, hello_world expressions : sums of positive integers and declared variables a variable must be declared and initialized in prior set_statement before it can be used in an expression example of legal expressions : 6, x + y, 3 + 45 + alpha example of illegal expressions: 6 * 5, 3.2 . 7, 2 * x + y three kinds of statements: set_stmt: varname - exprn print_stmt: print exprn if_stmt: if exprn > exprn then set_stmt output of execution of a program: print statements produce integer (as a string) separated by one space the output should be trimmed so there is no leading and trailing spaces if the program contains an error, just return the string 'ERROR A very simple toy language: statements separated with 's' empty statement between consecutive ;' is OK last statement can optionally followed by ';' at least one space between all lexemes tab and newline char are ignored variables: var name (identifier) consists of lower letter only (no digits, spaces, punctuations) following words are reserved and can not be used as variable names: print, if, then examples of legal variables: x, y, apple, hello examples of illlegal variables: x4, Apple, hello_world expressions : sums of positive integers and declared variables a variable must be declared and initialized in prior set_statement before it can be used in an expression example of legal expressions : 6, x + y, 3 + 45 + alpha example of illegal expressions: 6 * 5, 3.2 . 7, 2 * x + y three kinds of statements: set_stmt: varname - exprn print_stmt: print exprn if_stmt: if exprn > exprn then set_stmt output of execution of a program: print statements produce integer (as a string) separated by one space the output should be trimmed so there is no leading and trailing spaces if the program contains an error, just return the string 'ERROR
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
