CNNArch.mc4 3.03 KB
Newer Older
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
1
package de.monticore.lang.monticar;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
2

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
3
grammar CNNArch extends de.monticore.lang.math.Math {
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
4

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
5
    CNNArchCompilationUnit = Architecture;
6

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
7
8
    symbol scope Architecture = "architecture"
                                name:Name& "{"
9
                                declarations:ArchDeclaration*
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
10
                                body:ArchBody "}";
11

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
12
    interface ArchDeclaration;
13
    interface ArchitectureElement;
14
15
    interface Variable;
    ast Variable = method String getName(){};
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
16

17
18
19
20
21
    IODeclaration implements ArchDeclaration = "def"
                                               (in:"input" | out:"output")
                                               type:ArchType
                                               Name&
                                               (ArrayDeclaration)?;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
22

23
24
25
    ArchType implements Type = ElementType "^" Shape;

    Shape = "{" (Dimension || ",")+ "}";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
26

27
    Dimension = IOVariable | intLiteral:UnitNumberResolution;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
28

29
    IOVariable implements Variable = Name& ("=" intRhs:UnitNumberResolution)?;
30

31
    VariableAssignment implements Variable,ArchDeclaration = Name& "=" rhs:ArchSimpleExpression;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
32

33
34
35
36
    MethodDeclaration implements ArchDeclaration = "def"
                                                   Name& "("
                                                   parameters:(Parameter || ",")* ")" "{"
                                                   body:ArchBody "}";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
37

38
    Parameter implements Variable = Name& ("=" default:ArchSimpleExpression)?;
39

40
    scope ArchBody = elements:(ArchitectureElement || "->")*;
41

42
    IOLayer implements ArchitectureElement = Name& ("[" index:ArchSimpleExpression "]")?;
43

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
44
    MethodLayer implements ArchitectureElement = Name& "(" arguments:(Argument || ",")* ")";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
45

46
    Argument = Name "=" rhs:ArchExpression;
47

48
49
    PredefinedArgument extends Argument = (serial:"->" | parallel:"|") "=" rhs2:ArchExpression;

50
    ParallelLayer implements ArchitectureElement = "(" groups:ArchBody "|" groups:(ArchBody || "|")+ ")";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
51

52
    ArrayAccessLayer implements ArchitectureElement = "[" index:ArchSimpleExpression "]";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
53

54

55
    ArchExpression = (expression:ArchSimpleExpression | sequence:ArchValueSequence);
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
56

57
58
59
    interface ArchValueSequence;

    ArchParallelSequence implements ArchValueSequence = "[" parallelValues:(ArchSerialSequence || "|")* "]";
60
61
62

    ArchSerialSequence = serialValues:(ArchSimpleExpression || "->")+;

63
    ArchValueRange implements ArchValueSequence = start:ArchSimpleExpression
64
                                                  (serial:"->" | parallel:"|")
65
66
67
                                                  ".."
                                                  (serial2:"->" | parallel2:"|")
                                                  end:ArchSimpleExpression;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
68
69


70
71
72
    ArchSimpleExpression = (arithmeticExpression:MathArithmeticExpression
                         | booleanExpression:MathBooleanExpression
                         | tupleExpression:TupleExpression);
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
73

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
74
    TupleExpression implements MathExpression = "(" expressions:MathArithmeticExpression "," expressions:(MathArithmeticExpression || ",")* ")";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
75

Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
76
}