Commit ab58e090 authored by Thomas Michael Timmermanns's avatar Thomas Michael Timmermanns Committed by Thomas Michael Timmermanns

Added test, improved error message and ASTTupleExpression no longer implemements ASTMathExpression.

parent 31c40ca4
......@@ -190,8 +190,9 @@ Assuming the method `m(a, b, c)` exists, the line `m(a=[5->3], b=[3|4|2], c=2)->
However, the line `m(a=[5->3], b=[2|4->6], c=2)->` would throw an error because it is not possible to expand *a* such that it is the same size as *b*.
## Expressions
Currently, the working expression operators are the basic arithmetic operators "+", "-", "\*", "/", the logical operators "&&", "||" and for most cases the comparison operators "==", "!=", "<", ">", "<=", ">=".
The comparison operators do not work reliably for the comparison of tuple (they only compare the last element in the tuples).
This language supports the basic arithmetic operators "+", "-", "\*", "/", the logical operators "&&", "||" and the comparison operators "==", "!=", "<", ">", "<=", ">=".
At the moment, it is sometimes necessary to use parentheses around an expression to avoid a parsing error.
For example, the line `someMethod(booleanArg = (1!=1))` does not parse without the parentheses around `1!=1`.
## Advanced Example
This version of Alexnet, which uses method construction, argument sequences and special arguments, is identical to the one in the section Basic Structure.
......
......@@ -76,7 +76,7 @@ grammar CNNArch extends de.monticore.lang.math.Math {
| tupleExpression:TupleExpression
| string:StringLiteral);
TupleExpression implements MathExpression = "(" expressions:MathExpression "," expressions:(MathExpression || ",")* ")";
TupleExpression = "(" expressions:MathExpression "," expressions:(MathExpression || ",")* ")";
token NEWLINETOKEN =
('\r' '\n' |
......
......@@ -54,8 +54,8 @@ public class CNNArchCocos {
.addCoCo(new CheckMethodLayer())
.addCoCo(new CheckRangeOperators())
.addCoCo(new CheckVariableName())
.addCoCo(new CheckArgument())
.addCoCo(new CheckMethodName())
.addCoCo(new CheckArgument())
.addCoCo(new CheckMethodRecursion());
}
}
......@@ -33,7 +33,7 @@ public class CheckArgument implements CNNArchASTArchArgumentCoCo {
public void check(ASTArchArgument node) {
ArgumentSymbol argument = (ArgumentSymbol) node.getSymbol().get();
MethodDeclarationSymbol method = argument.getMethodLayer().getMethod();
if (argument.getParameter() == null){
if (method != null && argument.getParameter() == null){
Log.error("0"+ ErrorCodes.UNKNOWN_ARGUMENT + " Unknown Argument. " +
"Parameter with name '" + node.getName() + "' does not exist. " +
"Possible arguments are: " + Joiners.COMMA.join(method.getParameters())
......
......@@ -22,13 +22,16 @@ package de.monticore.lang.monticar.cnnarch._cocos;
import de.monticore.lang.monticar.cnnarch._ast.ASTArchArgument;
import de.monticore.lang.monticar.cnnarch._ast.ASTMethodLayer;
import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.MethodDeclarationSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.MethodLayerSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.VariableSymbol;
import de.monticore.lang.monticar.cnnarch.helper.ErrorCodes;
import de.se_rwth.commons.Joiners;
import de.se_rwth.commons.logging.Log;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class CheckMethodLayer implements CNNArchASTMethodLayerCoCo{
......@@ -50,8 +53,10 @@ public class CheckMethodLayer implements CNNArchASTMethodLayerCoCo{
MethodDeclarationSymbol method = ((MethodLayerSymbol) node.getSymbol().get()).getMethod();
if (method == null){
ArchitectureSymbol architecture = node.getSymbol().get().getEnclosingScope().<ArchitectureSymbol>resolve("", ArchitectureSymbol.KIND).get();
Log.error("0" + ErrorCodes.UNKNOWN_METHOD + " Unknown method error. " +
"Method with name '" + node.getName() + "' does not exist"
"Method with name '" + node.getName() + "' does not exist. " +
"Existing methods: " + Joiners.COMMA.join(architecture.getMethodDeclarations()) + "."
, node.get_SourcePositionStart());
}
else {
......
......@@ -24,11 +24,9 @@
package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.symboltable.CommonScopeSpanningSymbol;
import de.monticore.symboltable.Symbol;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
......@@ -69,6 +67,10 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
return ioDeclarations;
}
public Collection<MethodDeclarationSymbol> getMethodDeclarations(){
return getSpannedScope().resolveLocally(MethodDeclarationSymbol.KIND);
}
public void resolve(){
getBody().checkIfResolvable();
try{
......
......@@ -43,8 +43,10 @@ public class ArgumentSymbol extends CommonSymbol {
public VariableSymbol getParameter() {
if (parameter == null){
Optional<VariableSymbol> optParam = getMethodLayer().getMethod().getParameter(getName());
optParam.ifPresent(this::setParameter);
if (getMethodLayer().getMethod() != null){
Optional<VariableSymbol> optParam = getMethodLayer().getMethod().getParameter(getName());
optParam.ifPresent(this::setParameter);
}
}
return parameter;
}
......
......@@ -61,6 +61,10 @@ public class AllCoCoTest extends AbstractCoCoTest {
@Test
public void testInvalidPreResolveCocos(){
checkInvalid(new CNNArchCoCoChecker().addCoCo(new CheckMethodLayer()),
new CNNArchCoCoChecker(),
"invalid_tests", "UnknownMethod",
new ExpectedErrorInfo(1, ErrorCodes.UNKNOWN_METHOD));
checkInvalid(new CNNArchCoCoChecker().addCoCo(new CheckIOName()).addCoCo(new CheckVariableName()).addCoCo(new CheckMethodName()),
new CNNArchCoCoChecker(),
"invalid_tests", "DuplicatedNames",
......
architecture UnknownMethod(inputs=10, classes=2){
def input Q(-oo:+oo)^{inputs} in
def output Q(0:1)^{classes} out
in ->
FllyConnected(units=64, no_bias=true) ->
Tanh() ->
FullyConnected(units=classes, no_bias=true) ->
Softmax() ->
out
}
\ No newline at end of file
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