| Prototypes | Implicit | Do NOT write int getint(); or int printf(...);. |
| Memory / Size | Max 4MB Total (MARS Limit) | Scale Down Constants. 1e6 $\to$ 1e4. Total int elements < 500,000. |
| Preprocessor | BANNED (#include, #define, #ifdef) | Use const int for constants. Delete imports. |
| Types | int, void ONLY | No long long, float, double, char, bool. |
| Pointers | BANNED (int *p, &x, *ptr) | Pass arrays as int a[]. Use return values for scalar outputs (no void f(int *res)). |
| Arrays | 1D Arrays ONLY | Flatten int a[N][M] $\to$ int a[N*M]. No VLAs. |
| Loops | for loops ONLY. No declarations inside () | Move vars out: int i; for(i=0;...). No do-while. No while. turn while(1) into for(;;). |
| Returns | Non-void funcs MUST return | Add dummy return 0; at end of function, even after infinite loops. |
| Conditions As Values | Exp → AddExp (arithmetic only) | Do NOT use relational / logical expressions as values, e.g. return a < b; or x = (a < b);. Rewrite: if (a < b) return 1; return 0; or x = 0; if (a < b) x = 1;. |
| Input | int getint() ONLY | No scanf, cin, getchar. |
| Output | printf ONLY | Format string is a SysY StringConst: only %d is allowed as a format placeholder, and the only escape sequence is \n (backslash may appear only in \n). No other format specifiers/modifiers (e.g. %c, %s, %%, %05d) and no other escapes (e.g. \\, \", \t, \r, \0). Ensure the number of , Exp arguments equals the number of %d. |
| Parentheses | PrimaryExp → '(' Exp ')' and Exp → AddExp | (...) as an expression can wrap arithmetic only. Besides mandatory syntax like if (Cond) / for (...; Cond; ...), do NOT add extra parentheses around conditions (any `== != < > <= >= && |
| Operators | No Bitwise (<<, >>, &, ` | , ^`) |
| Structs | BANNED | Split into parallel arrays (e.g., x[N], y[N]). |
| Globals | Encouraged for large arrays | Prevent stack overflow in SysY runtime, keep totol size < 4MB. |
| Input Data | Strictly 1 Integer Per Line (in.txt) | No spaces (1 2). Must be 1\n2. Matches MIPS syscall. If testfile.txt uses a sentinel to stop reading (e.g., if (ch == 0) break;, while (x != 0), while (1) { x=getint(); if (x==0) break; }), then in.txt must explicitly include that sentinel value as the last integer. Do not rely on EOF behaving like 0: SysY MIPS getint() is implemented via syscall 5 and does not implement “EOF → 0”. |