Cin-browser interpreter · runs locally
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h> #include <string.h> struct Entry { string name; string type; int scope; }; struct Entry table[64]; int count = 0; int lookup(string name, int scope) { for (int i = count - 1; i >= 0; i--) { if (strcmp(table[i].name, name) == 0 && table[i].scope <= scope) { return i; } } return -1; } void insert(string name, string type, int scope) { table[count].name = name; table[count].type = type; table[count].scope = scope; count++; } int main() { insert("x", "int", 0); insert("total", "double", 0); insert("x", "char", 1); int i = lookup("x", 1); printf("x in scope 1 -> %s\n", table[i].type); int j = lookup("total", 0); printf("total in scope 0 -> %s\n", table[j].type); return 0; }
35 lines
Output
Write some code, then press Run. Stdout and errors appear here.