Generating Software from Specifications WS 2013/14 - File StatementsPDL.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;
~}
For name analysis we use the module for basic Algol-like scope rules:
~O~<NameAnalysis.specs~>~{
$/Name/AlgScope.gnrc:inst
~}
Subtask-1:
Use the basic name analysis module to bind all identifier occurrences
to keys applying Algol-like scope rules.
Solution-1:
~O~<Test-1.ok~>~{~-
~}
~O~<Test-1.err~>~{~-
~}
~O~<NameAnalysis.lido~>~{
~}
Subtask-2:
At each defining occurrence output its line number;
at each using occurrence output its line number and the line number
of the defining occurrence.
Solution-2:
~O~<LineInformation.pdl~>~{
~}
~O~<LineInformation.lido~>~{
~}
Subtask-3:
Report a message if an entity is defined more than once.
Give that message at all offending definitions.
Solution-3:
~O~<Test-3.err~>~{~-
~}
~O~<Unique.pdl~>~{
~}
~O~<UniqueDefs.lido~>~{
~}
Subtask-4:
Report a message if a use occurs before its definition.
Solution-4:
~O~<Test-4.err~>~{~-
~}
~O~<DefBeforeUse.lido~>~{
~}
Subtask-5:
At at every occurrence of an identifier, except the first one, output the
line number of the previous occurrence. Definitions and uses are treated in
the same way; it is irrelevant which entities are referenced.
Solution-5:
~O~<Previous.lido~>~{~-
~}
Subtask-6:
Implement the "Do it once" pattern of slide GSS-4.5, and
apply it to uses and definitions of variables, such that for each variable
at most one occurrence of either kind is printed.
Solution-6:
~O~<DoItOnce.pdl~>~{~-
~}
~O~<DoItOnce.lido~>~{~-
~}
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: 24.11.2013


