diff --git a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java index df55c5d..3362f4f 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java @@ -430,37 +430,83 @@ stream.next(); } else if (operator.equals(DOT)) { // json accessor - Expression exp = expressions.remove(0); - stream.next(); // DOT - if (stream.checkNext() == null) throw new WrongJsonExpression(stream.getLine()); - String literalOrLeftCurlyBracket = stream.next(); - Expression paramTerm = null; - if (literalOrLeftCurlyBracket.equals(LEFT_CURLY_BRACKET)) { - // parameter - paramTerm = parseTerm(stream, model); - String rightCurlyBracket = stream.next(); - if (rightCurlyBracket == null || !rightCurlyBracket.equals(RIGHT_CURLY_BRACKET)) throw new WrongJsonExpression(stream.getLine()); + while (operator.equals(DOT)) { + Expression exp = expressions.remove(0); + stream.next(); // DOT + if (stream.checkNext() == null) throw new WrongJsonExpression(stream.getLine()); + String literalOrLeftCurlyBracket = stream.next(); + Expression paramTerm = null; + if (literalOrLeftCurlyBracket.equals(LEFT_CURLY_BRACKET)) { + // parameter + paramTerm = parseTerm(stream, model); + String rightCurlyBracket = stream.next(); + if (rightCurlyBracket == null || !rightCurlyBracket.equals(RIGHT_CURLY_BRACKET)) throw new WrongJsonExpression(stream.getLine()); + } else { + // literal + paramTerm = new Constant(literalOrLeftCurlyBracket, DataTransferModel.typeString); + } + Type paramType = null; + if (paramTerm instanceof Variable) { + paramType = ((Variable) paramTerm).getType(); + } else if (paramTerm instanceof Term) { + paramType = ((Term) paramTerm).getType(); + } + Term term = null; + if (paramType != null && DataConstraintModel.typeInt.isAncestorOf(paramType)) { + term = new JsonAccessor(DataConstraintModel.dotParam); + } else { + term = new JsonAccessor(DataConstraintModel.dot); + } + term.addChild(exp); + term.addChild(paramTerm); + expressions.add(term); + operator = stream.checkNext(); + if (operator == null) break; + } + if (operator == null) { + break; + } else if (operator.equals(ADD)) { + operators.add(DataTransferModel.add); + stream.next(); + } else if (operator.equals(MUL)) { + operators.add(DataTransferModel.mul); + stream.next(); + } else if (operator.equals(SUB)) { + operators.add(DataTransferModel.sub); // not minus + stream.next(); + } else if (operator.equals(DIV)) { + operators.add(DataTransferModel.div); + stream.next(); + } else if (operator.equals(MOD)) { + operators.add(DataTransferModel.mod); + stream.next(); + } else if (operator.equals(EQ)) { + operators.add(DataTransferModel.eq); + stream.next(); + } else if (operator.equals(NEQ)) { + operators.add(DataTransferModel.neq); + stream.next(); + } else if (operator.equals(GT)) { + operators.add(DataTransferModel.gt); + stream.next(); + } else if (operator.equals(LT)) { + operators.add(DataTransferModel.lt); + stream.next(); + } else if (operator.equals(GE)) { + operators.add(DataTransferModel.ge); + stream.next(); + } else if (operator.equals(LE)) { + operators.add(DataTransferModel.le); + stream.next(); + } else if (operator.equals(AND)) { + operators.add(DataTransferModel.and); + stream.next(); + } else if (operator.equals(OR)) { + operators.add(DataTransferModel.or); + stream.next(); } else { - // literal - paramTerm = new Constant(literalOrLeftCurlyBracket, DataTransferModel.typeString); + break; } - Type paramType = null; - if (paramTerm instanceof Variable) { - paramType = ((Variable) paramTerm).getType(); - } else if (paramTerm instanceof Term) { - paramType = ((Term) paramTerm).getType(); - } - Term term = null; - if (paramType != null && DataConstraintModel.typeInt.isAncestorOf(paramType)) { - term = new JsonAccessor(DataConstraintModel.dotParam); - } else { - term = new JsonAccessor(DataConstraintModel.dot); - } - term.addChild(exp); - term.addChild(paramTerm); - expressions.add(term); - operator = stream.checkNext(); - if (operator == null || !operator.equals(DOT)) break; } else { break; } @@ -755,7 +801,7 @@ if (!fFirstToken) { newTokens.add(new Token(DOUBLE_QUOT, true)); } - if (token.length() > 0) { + if (!fFirstToken || token.length() > 0) { if (i % 2 == 0) { for (String t: token.split("[ \t]")) { newTokens.add(new Token(t)); @@ -767,6 +813,9 @@ } fFirstToken = false; } + if (line.endsWith(DOUBLE_QUOT)) { + newTokens.add(new Token(DOUBLE_QUOT, true)); + } return newTokens; }