Please use the code given to include Lua along with the code. This project consi
ID: 3719839 • Letter: P
Question
Please use the code given to include Lua along with the code. This project consists of developing an interpreter for a minimal form (subset) of the Lua language. This minimal form of Lua has only 1 data type, integer, and the only identifiers are single letters. Lua is not case sensitive. The specification of the grammar is given below. The interpreter will process a Lua program and build some intermediate data structures. These data structures will then be interpreted to execute the program. All tokens in this language are separated by white space. The parsing algorithm should detect any syntactical or semantic error. The first such error discovered should cause an appropriate error message to be printed, and then the interpreter should terminate. Run-time errors should also be detected with appropriate error messages being printed. Grammar for the (subset of Lua) language Syntax Analyzer ? function id ( ) end ? | ? | | | | ? if then else end ? while do end -> id -> repeat until ? print ( ) ? ? le_operator | lt_operator | ge_operator | gt_operator | eq_operator | ne_operator ? | | ? add_operator | sub_operator | mul_operator | div_operator Lexical Analyzer id ? letter CS4308 Project 3 literal_integer ? digit literal_integer | digit assignment_operator ? = le_operator ? <= lt_operator ? < ge_operator ? >= gt_operator ? > eq_operator ? = = ne_operator ? ~= add_operator ? + sub_operator ? - mul_operator ? * div_operator ? / CODE GIVEN: import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; /** * Scan input date, interpret it * Convert from dd/MM/yyyy to dd-MMM-yyyy */ public class DateInterpreter { public static void main( String[] args ) throws ParseException { String input = scanInput(); System.out.println("Equivalent date in dd-MMM-yyyy is " + parseDate(input)); } /** * Use scanner to read input */ public static String scanInput() { System.out.print("Enter Input Date:"); Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); scanner.close(); return input; } static SimpleDateFormat inputformat = new SimpleDateFormat("dd/MM/yyyy"); static SimpleDateFormat outputformat = new SimpleDateFormat("dd-MMM-yyyy"); /** * Method to parse and interpret, and return the date in other format */ public static String parseDate( String date ) throws ParseException { Date input = inputformat.parse(date); return outputformat.format(input); } }
Explanation / Answer
This project consists of developing an interpreter for a minimal form (subset) of the Lua language. This minimal form of Lua has only 1 data type, integer, and the only identifiers are single letters. Lua is not case sensitive. The specification of the grammar is given below.
The interpreter will process a Lua program and build some intermediate data structures. These data structures will then be interpreted to execute the program. All tokens in this language are separated by white space. The parsing algorithm should detect any syntactical or semantic error. The first such error discovered should cause an appropriate error message to be printed, and then the interpreter should terminate. Run-time errors should also be detected with appropriate error messages being printed.
PROGRAM:-