Generating Software from Specifications WS 2013/14 - File Statements.fw
@=~ ~p maximum_input_line_length = infinity This file contains the specification of a processor for a little programming language with variable declarations, nested blocks, assignments, and some control-flow statements. The following file contains correct input for the processor: ~O~<Statements.ok~>~{~- { int i; i = 5; while (i) i = 0; { int x; x = 21; } int j; if (j) j = 1; { int k; k = i; { k = 42; } } { i = 42; } } ~} The following file contains erroneous input for the processor: ~O~<Statements.err~>~{ ~} The following file specifies the concrete syntax: ~O~<Statements.con~>~{ Program: Block. Block: '{' Constructs '}'. Constructs: Constructs Construct / Construct. Construct: Declaration. Construct: Statement. Declaration: 'int' VarNameDef ';'. VarNameDef: Identifier. Statement: VarNameUse '=' Expression ';' / 'while' '(' Expression ')' Statement / 'if' '(' Expression ')' Statement / Block. Expression: VarNameUse / Number . VarNameUse: Identifier. ~} The following file specifies the non-literal tokens: ~O~<Statements.gla~>~{ Identifier: C_IDENTIFIER Number: C_INTEGER C_COMMENT ~} The following file specifies the abstract sxntax. It is recommended not to add computations to these rule instances; rather copy rules to other lido fragments and add computations there. ~O~<Abstract.lido~>~{ RULE: Program ::= Block COMPUTE END; RULE: Block ::= '{' Constructs '}' COMPUTE END; RULE: Constructs ::= Constructs Construct COMPUTE END; RULE: Constructs ::= Construct COMPUTE END; RULE: Construct ::= Declaration COMPUTE END; RULE: Construct ::= Statement COMPUTE END; RULE: Declaration ::= 'int' VarNameDef ';' COMPUTE END; RULE: VarNameDef ::= Identifier COMPUTE END; RULE: Statement ::= VarNameUse '=' Expression ';' COMPUTE END; RULE: Statement ::= 'while' '(' Expression ')' Statement COMPUTE END; RULE: Statement ::= 'if' '(' Expression ')' Statement COMPUTE END; RULE: Statement ::= Block COMPUTE END; RULE: Expression ::= VarNameUse COMPUTE END; RULE: Expression ::= Number COMPUTE END; RULE: VarNameUse ::= Identifier COMPUTE END; ~} The solutions of subtasks are to be inserted into the following macros: Subtask-1: Unique numbers for statements in any order: ~O~<Subtask-1.lido~>~{ ~} Subtask-2: Deactivate the previous solution. Unique numbers for statements in left-to-right order computed by a CHAIN: ~O~<Subtask-2.lido~>~{ ~} Subtask-3: Deactivate the previous solution. Count occurrences of VarNameUse: ~O~<Subtask-3.lido~>~{ ~} Subtask-4: Compute nesting depth of blocks and output in the context of a defining occurrence of a variable the depth of the surrounding block: ~O~<Subtask-4.lido~>~{ ~} Subtask-5: Produce first output at all definig occurrences of variables, then at all applied occurrences: ~O~<Subtask-5.lido~>~{ ~} The following files makes a module available that defines the datatype CharPtr for strings and functions for string concatenation: ~O~<Post.specs~>~{ $/Tech/Strings.specs ~} The following three files implements some C functions which may be used in the generated processor: ~O~<Statements.HEAD.phi~>==~{ #include "Statements.h" ~} ~O~<Statements.h~>==~{ ~} ~O~<Statements.c~>==~{ #include <stdio.h> #include <string.h> #include "Statements.h" ~}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 13.11.2013