CNNArch.mc4 2.83 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;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
14
    interface Variable;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
15

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

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

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

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

28 29
    IOVariable implements Variable = Name&;

30
    Constant implements Variable = Name& "=" rhs:ArchSimpleExpression;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
31

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

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

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

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

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

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

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

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

51

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

54 55 56
    interface ArchValueSequence;

    ArchParallelSequence implements ArchValueSequence = "[" parallelValues:(ArchSerialSequence || "|")* "]";
57 58 59

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

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


67 68 69
    ArchSimpleExpression = (arithmeticExpression:MathArithmeticExpression
                         | booleanExpression:MathBooleanExpression
                         | tupleExpression:TupleExpression);
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
70

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

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