#SDNU1655. The C Interpreter
The C Interpreter
Description
lzw is a crazy c/c++ fan, he looks down on the other computer language like python, java, c#, and so on, which use the virtual machine to parsing their code. But wzl disagree him, wzl think that use virtual machine can help human to code more helpful code, on an additional abstraction layer. To convince lzw, wzl decide to achieve a c language interpreter. But different with lzw, wzl's code ability is so low, so he decides to ask you for help, please achieve a c language interpreter to help wzl.
Format
Input
guarantee the code can compile and run normally under c99 standard, and original code would never tle
At the same time, this code has the following constraints :
except for the head file, there are no other compile pretreatment, like : #if,#ifdef,#ifndef,#else,#elif,#endif,#define,#undef,#error,#pragma,#_Pragma,#line
the keyword only exits return, int and void, the void can only exist ahead of function, constant only exits int value
there is no global variable
the operator only exits +, -, *, /, %, =
there is no array and pointer
there are none / and //
{} can only exits when pakage the function's body, () can only exits when call function or define function
Only main function will call other functions, when call other functions, parms can only be constant value, f(1, 2, 3) exist, f(a, b, 3) or f(g(), h(1, b), 3) not exist
Will not split a sentence of code into two lines.
the only thing using in the file outside is printf, only use formate like :
printf("%d\n", [expr])
[expr] means an expression
Output
output what the input code's output
guarantee there is no int overflow
Samples
#include<stdio.h>
#include<string.h>
int g(int a, int b) {
return a + b * 3;
}
int test(int asdf, int p) {
return asdf / p + 4;
}
int main() {
int p = 0;
p = p + 2;
p = test(34, 2);
printf("%d\n", p + g(1, 2));
return 0;
}
28