Compiler/AST interpreter: Difference between revisions

m
Fix C-like division: it always truncates towards 0.
m (made da_redim - use do while for macros, to avoid potential problems.)
m (Fix C-like division: it always truncates towards 0.)
Line 72:
Because of the simple nature of our tiny language, Semantic analysis is not needed.
 
Your interpreter should use C like division semantics, for both division and modulus. For division of positive operands, only the non-fractional portion of the result should be returned. In other words, the result should be truncated towards 0.
division of positive operands, only the non-fractional portion of the result should be
returned. In other words, the result should be truncated towards 0.
 
This means, for instance, that 3 / 2 should result in 1.
 
For division when one of the operands is negative, the result should be truncated awaytowards 0.
from 0.
 
This means, for instance, that 3 / -2 should result in -1.
155

edits