一个简单的语法制导翻译器
- 翻译非终结符号的过程
#include <iostream>
using namespace std;
int main(){
cout<<"Anycodes, Hello World of C++!"<<endl;
return 0;
}
void expr()
{
term();
rest();
}
void rest()
{
if (lookahead == '+')
{
match('+');
trerm();
print('+');
rest();
}
else if(lookahead == '-')
{
match('-');
term();
print('-');
rest();
}
else'
{
}
}
void term()
{
if (lookahead 是一个数字)
{
t = lookahead;
match(lookahead);
print(t);
}
else
{
report("语法错误!");
}
}
void rest()
{
while(TRUE)
{
if (lookahead == '+')
{
match('+');
term();
print('+');
continue;
}
else if (lookahead == '-')
{
match('-');
term();
print('-');
continue;
}
break;
}
}