added symbolTableCreator

parent 40f76601
...@@ -2,14 +2,17 @@ package de.monticore.lang.monticar; ...@@ -2,14 +2,17 @@ package de.monticore.lang.monticar;
grammar CNNArch extends de.monticore.common.Common { grammar CNNArch extends de.monticore.common.Common {
CNNArchCompilationUnit = Architecture;
symbol scope Architecture = "architecture" symbol scope Architecture = "architecture"
name:Name& "(" Name& "{"
inputPort:Name& ")" "{"
(MainLayer)+ (MainLayer)+
outputPort:Name& "="
OutputLayer OutputLayer
"}"; "}";
//InputPort = Name "-->";
//OutputPort = "-->" Name;
interface Layer; interface Layer;
ast Layer = method ASTMethod getMethod(){}; ast Layer = method ASTMethod getMethod(){};
interface Method; interface Method;
...@@ -18,13 +21,13 @@ grammar CNNArch extends de.monticore.common.Common { ...@@ -18,13 +21,13 @@ grammar CNNArch extends de.monticore.common.Common {
interface ArgumentAssignment; interface ArgumentAssignment;
ast ArgumentAssignment = method public Enum getLhs(){} ast ArgumentAssignment = method public Enum getLhs(){}
method public ASTRhs getRhs(){}; method public ASTArgumentRhs getRhs(){};
Rhs = stringVal:String ArgumentRhs = stringVal:String
| intVal:Num_Int | intVal:Num_Int
| doubleVal:Num_Double | doubleVal:Num_Double
| intTuple:IntTuple | intTuple:IntTuple
| refOrBool:Name; | refOrBool:Name;
IntTuple = "(" values:Num_Int "," values:(Num_Int || ",")+ ")"; IntTuple = "(" values:Num_Int "," values:(Num_Int || ",")+ ")";
...@@ -35,7 +38,7 @@ grammar CNNArch extends de.monticore.common.Common { ...@@ -35,7 +38,7 @@ grammar CNNArch extends de.monticore.common.Common {
ConvolutionMethod implements MainLayerMethod = name:"Convolution" "(" arguments:(ConvolutionArgumentAssignment || ",")* ")"; ConvolutionMethod implements MainLayerMethod = name:"Convolution" "(" arguments:(ConvolutionArgumentAssignment || ",")* ")";
ConvolutionArgumentAssignment implements ArgumentAssignment = lhs:ConvolutionArgument "=" rhs:Rhs; ConvolutionArgumentAssignment implements ArgumentAssignment = lhs:ConvolutionArgument "=" rhs:ArgumentRhs;
enum ConvolutionArgument = KERNEL:"kernel" //required enum ConvolutionArgument = KERNEL:"kernel" //required
| NUMFILTER:"num_filter" //required | NUMFILTER:"num_filter" //required
| STRIDE:"stride" | STRIDE:"stride"
...@@ -43,16 +46,16 @@ grammar CNNArch extends de.monticore.common.Common { ...@@ -43,16 +46,16 @@ grammar CNNArch extends de.monticore.common.Common {
| NOBIAS:"no_bias"; | NOBIAS:"no_bias";
FullyConnectedMethod implements MainLayerMethod = name:"FullyConnected" "(" arguments:(FullyConnectedArgumentAssignment || ",")* ")"; FullyConnectedMethod implements MainLayerMethod = name:"FullyConnected" "(" arguments:(FullyConnectedArgumentAssignment || ",")* ")";
FullyConnectedArgumentAssignment implements ArgumentAssignment = lhs:FullyConnectedArgument "=" rhs:Rhs; FullyConnectedArgumentAssignment implements ArgumentAssignment = lhs:FullyConnectedArgument "=" rhs:ArgumentRhs;
enum FullyConnectedArgument = NUMHIDDEN:"num_hidden" //required enum FullyConnectedArgument = NUMHIDDEN:"num_hidden" //required
| NOBIAS:"no_bias"; | NOBIAS:"no_bias";
ActivationMethod implements MainLayerMethod = name:"Activation" "(" arguments:(ActivationArgumentAssignment || ",")* ")"; ActivationMethod implements MainLayerMethod = name:"Activation" "(" arguments:(ActivationArgumentAssignment || ",")* ")";
ActivationArgumentAssignment implements ArgumentAssignment = lhs:ActivationArgument "=" rhs:Rhs; ActivationArgumentAssignment implements ArgumentAssignment = lhs:ActivationArgument "=" rhs:ArgumentRhs;
enum ActivationArgument = ACTTYPE:"act_type"; //required enum ActivationArgument = ACTTYPE:"act_type"; //required
PoolingMethod implements MainLayerMethod = name:"Pooling" "(" arguments:(PoolingArgumentAssignment || ",")* ")"; PoolingMethod implements MainLayerMethod = name:"Pooling" "(" arguments:(PoolingArgumentAssignment || ",")* ")";
PoolingArgumentAssignment implements ArgumentAssignment = lhs:PoolingArgument "=" rhs:Rhs; PoolingArgumentAssignment implements ArgumentAssignment = lhs:PoolingArgument "=" rhs:ArgumentRhs;
enum PoolingArgument = KERNEL:"kernel" //required enum PoolingArgument = KERNEL:"kernel" //required
| POOLTYPE:"pool_type" //required | POOLTYPE:"pool_type" //required
| POOLINGCONVENTION:"pooling_convention" | POOLINGCONVENTION:"pooling_convention"
...@@ -60,12 +63,12 @@ grammar CNNArch extends de.monticore.common.Common { ...@@ -60,12 +63,12 @@ grammar CNNArch extends de.monticore.common.Common {
| PAD:"pad"; | PAD:"pad";
DropoutMethod implements MainLayerMethod = name:"Dropout" "(" arguments:(DropoutArgumentAssignment || ",")* ")"; DropoutMethod implements MainLayerMethod = name:"Dropout" "(" arguments:(DropoutArgumentAssignment || ",")* ")";
DropoutArgumentAssignment implements ArgumentAssignment = lhs:DropoutArgument "=" rhs:Rhs; DropoutArgumentAssignment implements ArgumentAssignment = lhs:DropoutArgument "=" rhs:ArgumentRhs;
enum DropoutArgument = P:"p" enum DropoutArgument = P:"p"
| MODE:"mode"; | MODE:"mode";
LRNMethod implements MainLayerMethod = name:"LRN" "(" arguments:(LRNArgumentAssignment || ",")* ")"; LRNMethod implements MainLayerMethod = name:"LRN" "(" arguments:(LRNArgumentAssignment || ",")* ")";
LRNArgumentAssignment implements ArgumentAssignment = lhs:LRNArgument "=" rhs:Rhs; LRNArgumentAssignment implements ArgumentAssignment = lhs:LRNArgument "=" rhs:ArgumentRhs;
enum LRNArgument = ALPHA:"alpha" enum LRNArgument = ALPHA:"alpha"
| BETA:"beta" | BETA:"beta"
| KNORM:"knorm" | KNORM:"knorm"
...@@ -84,13 +87,13 @@ grammar CNNArch extends de.monticore.common.Common { ...@@ -84,13 +87,13 @@ grammar CNNArch extends de.monticore.common.Common {
ast StandardOutputLayerMethod = method public String getName(){ ast StandardOutputLayerMethod = method public String getName(){
return optName.get(); return optName.get();
}; };
StandardOutputArgumentAssignment implements ArgumentAssignment = lhs:StandardOutputArgument "=" rhs:Rhs; StandardOutputArgumentAssignment implements ArgumentAssignment = lhs:StandardOutputArgument "=" rhs:ArgumentRhs;
enum StandardOutputArgument = GRADSCALE:"grad_scale"; enum StandardOutputArgument = GRADSCALE:"grad_scale";
SVMOutputLayerMethod implements OutputLayerMethod = name:"SVMOutput" "(" SVMOutputLayerMethod implements OutputLayerMethod = name:"SVMOutput" "("
arguments:(SVMOutputArgumentAssignment || ",")* ")"; arguments:(SVMOutputArgumentAssignment || ",")* ")";
SVMOutputArgumentAssignment implements ArgumentAssignment = lhs:SVMOutputArgument "=" rhs:Rhs; SVMOutputArgumentAssignment implements ArgumentAssignment = lhs:SVMOutputArgument "=" rhs:ArgumentRhs;
enum SVMOutputArgument = MARGIN:"margin" enum SVMOutputArgument = MARGIN:"margin"
| REGULARIZATIONCOEFFICIENT:"regularization_coefficient" | REGULARIZATIONCOEFFICIENT:"regularization_coefficient"
| USELINEAR:"use_linear"; | USELINEAR:"use_linear";
......
...@@ -22,14 +22,14 @@ package de.monticore.lang.monticar.cnnarch._ast; ...@@ -22,14 +22,14 @@ package de.monticore.lang.monticar.cnnarch._ast;
import java.util.Optional; import java.util.Optional;
public class ASTRhs extends ASTRhsTOP{ public class ASTArgumentRhs extends ASTArgumentRhsTOP{
private boolean containsBoolean; private boolean containsBoolean;
public ASTRhs() { public ASTArgumentRhs() {
} }
public ASTRhs(String stringVal, String intVal, String doubleVal, ASTIntTuple intTuple, String refOrBool) { public ASTArgumentRhs(String stringVal, String intVal, String doubleVal, ASTIntTuple intTuple, String refOrBool) {
super(stringVal, intVal, doubleVal, intTuple, refOrBool); super(stringVal, intVal, doubleVal, intTuple, refOrBool);
} }
......
...@@ -32,8 +32,8 @@ public interface ASTMethod extends ASTMethodTOP { ...@@ -32,8 +32,8 @@ public interface ASTMethod extends ASTMethodTOP {
return new LinkedList<>(); return new LinkedList<>();
} }
default ASTRhs get(String lhsName) { default ASTArgumentRhs get(String lhsName) {
ASTRhs rhs = null; ASTArgumentRhs rhs = null;
lhsName = lhsName.replace("_", ""); lhsName = lhsName.replace("_", "");
for (ASTArgumentAssignment assignment : getAssignments()) { for (ASTArgumentAssignment assignment : getAssignments()) {
String assignmentLhs = assignment.getLhs().name(); String assignmentLhs = assignment.getLhs().name();
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.lang.monticar.cnnarch._ast.ASTArchitecture;
import de.monticore.lang.monticar.cnnarch._ast.ASTCNNArchCompilationUnit;
import de.monticore.symboltable.ArtifactScope;
import de.monticore.symboltable.ImportStatement;
import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.ResolvingConfiguration;
import de.se_rwth.commons.logging.Log;
import java.util.*;
public class CNNArchSymbolTableCreator extends CNNArchSymbolTableCreatorTOP {
private String compilationUnitPackage = "";
public CNNArchSymbolTableCreator(final ResolvingConfiguration resolvingConfig,
final MutableScope enclosingScope) {
super(resolvingConfig, enclosingScope);
}
public CNNArchSymbolTableCreator(final ResolvingConfiguration resolvingConfig,
final Deque<MutableScope> scopeStack) {
super(resolvingConfig, scopeStack);
}
@Override
public void visit(final ASTCNNArchCompilationUnit compilationUnit) {
Log.debug("Building Symboltable for Script: " + compilationUnit.getArchitecture().getName(),
CNNArchSymbolTableCreator.class.getSimpleName());
List<ImportStatement> imports = new ArrayList<>();
ArtifactScope artifactScope = new ArtifactScope(
Optional.empty(),
compilationUnitPackage,
imports);
putOnStack(artifactScope);
}
public void visit(final ASTArchitecture architecture) {
ArchitectureSymbol architectureSymbol = new ArchitectureSymbol(
architecture.getName()
);
addToScopeAndLinkWithNode(architectureSymbol, architecture);
}
public void endVisit(final ASTArchitecture architecture) {
removeCurrentScope();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment