Skip to content

Commit

Permalink
Enabled parsing for division expressions
Browse files Browse the repository at this point in the history
However, true support is currently blocked on #19.
  • Loading branch information
Calvin-L committed Aug 22, 2018
1 parent eb6b656 commit 70c5032
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cozy/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
("PLUS", "+"),
("MINUS", "-"),
("TIMES", "*"),
("DIVIDE", "/"),
("QUESTION", "?"),
("COLON", ":"),
("SEMICOLON", ";"),
Expand Down Expand Up @@ -326,6 +327,7 @@ def p_exp(p):
| exp OP_MINUS exp
| OP_MINUS exp
| exp OP_TIMES exp
| exp OP_DIVIDE exp
| exp OP_QUESTION exp OP_COLON exp
| exp OP_DOT NUM
| exp OP_DOT WORD
Expand Down
9 changes: 9 additions & 0 deletions cozy/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ def visit_EBinOp(self, e):
else:
e.type = DEFAULT_TYPE
self.report_err(e, "cannot multiply {} and {}".format(pprint(e.e1.type), pprint(e.e2.type)))
elif e.op == "/":
e.type = FLOAT
if not (e.e1.type is DEFAULT_TYPE or e.e1.type == FLOAT):
self.report_err(e, "division is only legal on floats; left-hand side {} has type {}".format(pprint(e.e1), pprint(e.e1.type)))
if not (e.e2.type is DEFAULT_TYPE or e.e2.type == FLOAT):
self.report_err(e, "division is only legal on floats; right-hand side {} has type {}".format(pprint(e.e2), pprint(e.e2.type)))
self.report_err(e,
"Division is currently unsupported since it is a partial function (x/0 is undefined)."
+ " See https://github.com/CozySynthesizer/cozy/issues/19 for more information.")
else:
raise NotImplementedError(e.op)

Expand Down

0 comments on commit 70c5032

Please sign in to comment.