Generating Software from Specifications WS 2013/14 - File Calendar.fw
@=~ ~p maximum_input_line_length = infinity This file contains the specification of a calendar processor. It reads a sequence of appointments, represents them by a tree structure, and outputs the tree. The following file contains some input for the processor ~O~<cal.ok~>~{~- 1.11. 20:00 "Theater" Thu 14:15 "GSS lecture" Weekday 12:05 "Dinner in Palmengarten" Mon, Thu "Dean's office" 31.12. 23:59 "Jahresende" 12/31 23:59 "End of year" ~} TASK 1: Generate the processor and test it systematically. Make sure that you test for every construct of the language at least one correct and one erroneous example. Use several input files for the erroneous examples to avoid cluttered output. ~O~<cal.err~>~{~- ~} The following file specifies the concrete syntax: ~O~<Calendar.con~>~{ Calendar: Entry+. Entry: Date Event. Date: DayNum '.' MonNum '.' / MonNum '/' DayNum / DayNames / GeneralPattern. DayNum: Integer. MonNum: Integer. DayNames: DayName / DayNames ',' DayName. DayName: Day. GeneralPattern: SimplePattern / SimplePattern Modifier. SimplePattern: 'Weekday' / 'Weekend'. Modifier: '+' DayNames / '-' DayNames. Event: When Description / Description. When: Time / Time '-' Time. ~} TASK 2: Check the meaning of the following token specifications. Extend the input language by comments. What kind of comments do you think fits best to the style of this language? Specify it and test the processor. ~O~<Calendar.gla~>~{ Description: C_STRING_LIT Integer: PASCAL_INTEGER Day: $Mon|Tue|Wed|Thu|Fri|Sat|Sun [mkDay] Time: $(([0-9]|1[0-9]|2[0-3]):[0-5][0-9]) [mkTime] ~} TASK 3: The C module below implements the two token coding functions mkDay and mkTime. Understand what they compute. Then extend your language by a facility to write abbreviated names of months, too, e.g. May 1 "Labour Day" Which specification types do you need to change? You can make the extensions according to the way the names of Days are specified. TASK 4: Change the specification of the token Time. (Keep the current specification, in order to undo this change after this experiment.) Make time to be a nonterminal which derives the hours and minutes separated by a colon. Any checks, whether the time is correct may be deferred to the semantic analysis phase. Check carefully how the notation of Time now differs from the previous version. Which one do you prefer? ~O~<Calendar.head~>==~{ #include "csm.h" #include "Calendar.h" ~} ~O~<Calendar.h~>==~{ extern void mkDay (char *, int, int *, int*); extern void mkTime (char *, int, int *, int*); ~} ~O~<Calendar.c~>==~{ #include <string.h> #include "Calendar.h" void mkDay (char *d, int l, int *c, int *i) { switch (d[0]) { case 'F': *i = 5; break; case 'M': *i = 1; break; case 'W': *i = 3; break; case 'S': *i = (d[1] == 'a'? 6 : 7); break; case 'T': *i = (d[1] == 'u' ? 2 : 4); break; } } void mkTime (char *t, int l, int *c, int *i) { char *colon = strchr (t, ':'); int hours, mins; *colon = '\0'; hours = atoi (t); mins = atoi (colon + 1); *colon = ':'; *i = hours*60 + mins; } ~}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 30.10.2013