编译原理实验求助

来源:百度知道 编辑:UC知道 时间:2024/05/13 20:09:00
实验一 词法分析实验(6学时)

[实验目的]
1、了解词法分析的主要任务。
[实验内容]
1、对形如下列的常量说明进行处理。
Const i=10;
j=100;
r=1.23;
c=’good’;
t=true;
[实验要求]
1、从键盘上输入常量说明,最后以问号(或其它符号)作结束标志;
2、处理各常量说明,计算各个常量的值和类型;
3、输出个常量名、常量的值和类型。

程序框架如下,高分请高手帮我写下main函数,要能编译通过

#include <stdio.h>
#include "LJL_Scanner.h"
#include "string.h"

/* 解释执行时使用的栈的最大尺寸。 */
#define stacksize 500

int main()
{

} //main()

int getsym()
{
int i,j,k;

while(cCurChar==' '||cCurChar==10||cCurChar==9) /* 忽略空格、换行和TAB */
{
getchdo;
}

if(cCurChar>='a'&&cCurChar<='z')
{ /* 名字或保留字以a..z开头 */
k=0;
do
{
if(k<al)
{
sTemp[k]=cCurChar;
k++;
}
getchdo;
}
while(cCurChar>='a'&&cCurChar<=

//.呵呵.C++版.
#include <iostream>
#include <fstream>
#include <stack>
#include <map>
#include <string>

using namespace std;

#define zhengshu 1 //int
#define IF 2 //if
#define ELSE 3 //else
#define shishu 4 //float
#define PRINT 5 //print
#define ID 6 //identify
#define CONSTANT 7 //constant
#define op_fuzhi 8 //=
#define op_add 9 //+
#define op_mul 10 //*
#define op_2star 11 //**
#define div_fenhao 12 //;
#define syl_ls 13 //(
#define syl_rs 14 //)
#define syl_lb 15 //{
#define syl_rb 16 //}
#define sbl_lm 17 //[
#define sbl_rm 18 //]
#define op_sub 19 //-
#define op_div 20 // /
#define div_douhao 21 //,
#define rop_yu 22 //&&
#define op_or 23 //||
#define rop_fei 24 //!
#define rop_equal 25 //==
#define rop_dayu 26 //>
#define rop_xiaoyu 27 //<