Skip to content

Commit

Permalink
period constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaRB committed Dec 15, 2023
1 parent 6051392 commit 2ea4f99
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/antlr/grammar/crml.g4
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ if_exp : 'if' if_e=exp 'then' then_e=exp ('else' else_e=exp);

constructor : 'new' type exp;

period_op : ('['| ']') exp ',' exp ('['| ']') ;
period_op : lb=('['| ']') exp ',' exp rb=('['| ']') ;

op : builtin_op|user_keyword
;
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/crml/compiler/crmlVisitorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ else if (ctx.uninstantiated_def()!=null)
if(ctx.sub_exp()!=null)
return visit(ctx.sub_exp().exp());


if(ctx.period_op()!=null){
return visit(ctx.period_op());
}

// expression is a tick
if(ctx.tick() != null) {
Expand Down Expand Up @@ -530,10 +532,32 @@ private UserOperatorCall reconstructUserOperator(ExpContext ctx, String string,
}

@Override
public Value visitSet_def(crmlParser.Set_defContext cxt) {
public Value visitSet_def(crmlParser.Set_defContext ctx) {
return new Value ("Set", "{}", true);
}

@Override
public Value visitPeriod_op(crmlParser.Period_opContext ctx) {

//String periodType = types_mapping.get("Period");

//TODO add typechecking

Value left = visit(ctx.exp(0));
Value right = visit(ctx.exp(0));

Boolean lborder = (ctx.lb.getText().equals("["));
Boolean rborder = (ctx.rb.getText().equals("]"));

String code =
"CRMLtoModelica.Types.CRMLPeriod(left=" + left.contents +
", right=" + right.contents +
",lb=" +lborder.toString() +
",rb=" +rborder.toString()+");";

return new Value (code, "Period", false);
}

@Override
public Value visitId(crmlParser.IdContext ctx){
VariableData.VariableType v_type = variableTable.getVariableInfo(ctx.getText());
Expand Down

0 comments on commit 2ea4f99

Please sign in to comment.