void codegen_setint(Item* item, Type* type, long long val);
void codegen_setreal(Item* item, double val);
void codegen_setstr(Item* item, char* val);
+
void codegen_not(Item* item);
+void codegen_add(Item* a, Item* b);
+void codegen_sub(Item* a, Item* b);
void codegen_mul(Item* a, Item* b);
+void codegen_div(Item* a, Item* b);
+void codegen_mod(Item* a, Item* b);
/* Option Parsing
*****************************************************************************/
}
}
+void codegen_add(Item* a, Item* b)
+{
+ (void)a, (void)b;
+ assert(!"not implemented");
+}
+
+void codegen_sub(Item* a, Item* b)
+{
+ (void)a, (void)b;
+ assert(!"not implemented");
+}
+
void codegen_imul(Item* a, Item* b)
{
if ((b->mode == ITEM_CONST) && (b->mode == ITEM_CONST))
codegen_imul(a,b);
}
}
+
+void codegen_div(Item* a, Item* b)
+{
+ (void)a, (void)b;
+ assert(!"not implemented");
+}
+
+void codegen_mod(Item* a, Item* b)
+{
+ (void)a, (void)b;
+ assert(!"not implemented");
+}
['('] = 6, [')'] = 6, ['['] = 6, [']'] = 6, ['{'] = 6,
['}'] = 6, [','] = 6, [':'] = 6, [';'] = 6,
['^'] = 6, ['+'] = 6, ['-'] = 6, ['*'] = 6, ['/'] = 6,
- ['|'] = 6,
+ ['|'] = 6, ['%'] = 6,
/* number digits */
['0'] = 7, ['1'] = 7, ['2'] = 7, ['3'] = 7, ['4'] = 7,
// term = factor {MulOperator factor}.
// MulOperator = "*" | "/" | "and".
factor(p, item);
- while (matches_oneof(p, (int[]){'*', '/', AND, 0}))
+ while (matches_oneof(p, (int[]){'*', '/', '%', AND, 0}))
{
Item right = { 0 };
int op = consume(p);
factor(p, &right);
switch(op)
{
- case '/':
+ case '*':
check_num2(p, item, &right);
-// codegen_div(item, &right);
- assert(!"not implemented");
+ codegen_mul(item, &right);
break;
- case '*':
+ case '/':
check_num2(p, item, &right);
- codegen_mul(item, &right);
+ codegen_div(item, &right);
+ break;
+
+ case '%':
+ check_int2(p, item, &right);
+ codegen_mod(item, &right);
break;
case AND:
"import A, B = ModB, C;");
}
- TEST(Should parse constant declarations)
+ TEST(Should parse constant declarations and expressions)
{
parse_rule(const_decl, 0,
"FOO = 123");
parse_rule(const_decl, 0,
"FOO = -1");
parse_rule(const_decl, 0,
- "FOO = 1 + 2 + 3");
+ "FOO = +1.0");
+ parse_rule(const_decl, 0,
+ "FOO = -1.0");
+ parse_rule(const_decl, 0,
+ "FOO = 1 + 2");
+ parse_rule(const_decl, 0,
+ "FOO = 1.0 + 2.0");
+ parse_rule(const_decl, 0,
+ "FOO = 1 - 2");
+ parse_rule(const_decl, 0,
+ "FOO = 1.0 - 2.0");
+ parse_rule(const_decl, 0,
+ "FOO = 1 * 2");
+ parse_rule(const_decl, 0,
+ "FOO = 1.0 * 2.0");
+ parse_rule(const_decl, 0,
+ "FOO = 1 / 2");
+ parse_rule(const_decl, 0,
+ "FOO = 1.0 / 2.0");
parse_rule(const_decl, 0,
- "FOO = 1 + 2 * 4");
+ "FOO = 1 % 2");
}
}
#endif