CNNArch.mc4 3.19 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

5 6 7 8 9 10
    symbol scope CNNArchCompilationUnit = "architecture"
                                          name:Name&
                                          ( "(" (ArchitectureParameter || ",")* ")" )? "{"
                                          ioDeclarations:IODeclaration*
                                          Architecture
                                          "}";
11

12 13
    Architecture = methodDeclaration:MethodDeclaration*
                   body:ArchBody;
14

15
    interface ArchitectureElement;
16 17
    interface Variable;
    ast Variable = method String getName(){};
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
18

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

25
    ArchType = ElementType "^" Shape;
26

27
    Shape = "{" dimensions:(ArchSimpleExpression || ",")* "}";
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
28

29
    ArchitectureParameter implements Variable = Name& ("=" default:ArchSimpleExpression)?;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
30

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

36
    MethodParameter implements Variable = Name& ("=" default:ArchSimpleExpression)?;
37

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

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

42 43 44 45 46
    MethodLayer implements ArchitectureElement = Name& "(" arguments:(ArchArgument || ",")* ")";

    interface ArchArgument;
    ast ArchArgument = method String getName(){}
                       method ASTArchExpression getRhs(){};
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
47

48
    ArchParameterArgument implements ArchArgument = Name "=" rhs:ArchExpression;
49

50 51
    ArchSpecialArgument implements ArchArgument = (serial:"->" | parallel:"|" | conditional:"?") "="
                                                  rhs:ArchExpression;
52
    ast ArchSpecialArgument = method public String getName(){return "";};
53

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

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

58

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

61
    interface ArchValueSequence;
62 63

    ArchParallelSequence implements ArchValueSequence = "[" parallelValues:(ArchSerialSequence || "|")* "]";
64 65 66

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

67
    ArchValueRange implements ArchValueSequence = start:ArchSimpleExpression
68
                                                  (serial:"->" | parallel:"|")
69 70 71
                                                  ".."
                                                  (serial2:"->" | parallel2:"|")
                                                  end:ArchSimpleExpression;
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
72 73


74 75
    ArchSimpleExpression = (arithmeticExpression:MathArithmeticExpression
                         | booleanExpression:MathBooleanExpression
76 77
                         | tupleExpression:TupleExpression
                         | string:StringLiteral);
Thomas Michael Timmermanns's avatar
Thomas Michael Timmermanns committed
78

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

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