實驗?zāi)康模河胏語言對一個簡單語言的子集編制一個一遍掃描的編譯程序,以加深對編譯原理的理解,掌握編譯程序的實現(xiàn)方法和技術(shù)。
c.1詞法分析
c.1.1實驗?zāi)康?
設(shè)計、編制并調(diào)試一個詞法分析程序,加深對詞法分析原理的理解。
c.1.2實驗要求
c.1.2.1待分析的簡單語言的詞法
(1) 關(guān)鍵字:
begin if then while do end
--------有實驗報告+.cpp+分析
#include <iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
if(n%2==1)
cout<<(n*n-1)/4<<endl;
else if (n%4==0)
cout <<(n*n)/4-1<<endl;
else{
if(n==2)
cout<<1<<endl;
else{
long long k=n/2-1;
cout <<k*k+2*k-3<<endl;
}
}
}
return 0;
}