導航:首頁 > 源碼編譯 > 編譯課程設計

編譯課程設計

發布時間:2022-01-22 12:54:02

A. 編譯原理課程設計在哪可以買

摘要 編譯理論和技術作為計算機科學研究和工程應用的基礎,受到了廣泛的重視。編譯原理也是大學計算機專業的必修課程。本書使用優秀的開源Java編譯器GJC作為編譯教學的基礎平台,通過分析一個真正實用的現代編譯系統,把編譯理論應用到實際的工程實踐中。全書不僅包括對編譯器源代碼的分析、對實例的講解,還在最後給出3個具體的課程設計實驗,介紹如何用書本上的編譯理論實現一個真正的編譯器。●使用優秀的開源編譯器作為教學平台,系統規模不大,且源程序有著很好的注釋。●通過詳盡的源代碼剖析和實例講解,循序漸進地啟發學生完成課程設計。●結合實際應用的要求,使課程設計既覆蓋知識點,又接近工程實踐需要。●是一本注重應用的實驗教程,因此可以和講授編譯理論的教材配合使用。編譯原理是大學計算機專業的必修課程。本書使用優秀的開源Java編譯器GJC作為編譯教學的基礎平台,通過分析一個真正實用的現代編譯系統,把編譯理論應用到實際的工程實踐中。全書不僅包括對編譯器源代碼的分析、對實例的講解,還在最後給出3個具體的課程設計實驗,介紹如何用書本上的編譯理論實現一個真正的編譯器。本書適合作為大專院校編譯原理課程設計的指導用書,相關的從業人員和研究人員也可以從中獲得有益的參考。

B. 編譯原理課程設計怎麼寫

摘要

C. 求編譯原理課程設計


語法規則及函數模塊如下所示:
int do_stat()
{
int es=0;
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
es=statement();
if (es>0) return(es);
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
if(strcmp(token,"while")==0)
{
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
if(strcmp(token,"(")) return(es=5);
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
es=expression();
if(es>0) return(es);
if(strcmp(token,")")) return(es=6);
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
}
else es=3;
return(es);
}
//<聲明語句> ::=int <變數>|<變數>;
//<declaration_stat>::=int ID,;
int declaration_stat()
{
int es=0;
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
if (strcmp(token,"ID")) return(es=3); //不是標識符
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
while(strcmp(token,",")==0 )
{
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
if (strcmp(token,"ID")) return(es=3); //不是標識符
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
};
if (strcmp(token,";") ) return(es=4);
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
return(es);
}
//<程序>::=
//program::=
int program()
{
int es=0;
fscanf(fp,"%s %s\n",token,token1);
printf("%s %s\n",token,token1);
if(strcmp(token,"main")==0)
{
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
if (strcmp(token,"(")) return(es=5); //少左括弧
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
if (strcmp(token,")")) return(es=6); //少右括弧
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
}
else
{
es=8;
return(es);
}
if(strcmp(token,"{"))//判斷是否'{'
{
es=1;
return(es);
}
fscanf(fp,"%s %s\n",&token,&token1);
printf("%s %s\n",token,token1);
es=declaration_list();
if (es>0) return(es);
es=statement_list();
if (es>0) return(es);
if(strcmp(token,"}"))//判斷是否'}'
{
es=2;
return(es);
}
return(es);
}
輸入如下:
main()
{int a,b,c;
read a;
read b;
c=0;
do{
c=a*b;
b=b+1;
a=a-1;
}while(b<=20)
write c;
}
輸出結果如下:
請輸入源程序文件名(包括路徑):main.txt
詞法分析成功!
main main
( (
) )
{ {
int int
ID a
, ,
ID b
, ,
ID c
; ;
read read
ID a
; ;
read read
ID b
; ;
ID c
= =
NUM 0
; ;
do do
{ {
ID c
= =
ID a
* *
ID b
; ;
ID b
= =
ID b
+ +
NUM 1
; ;
ID a
= =
ID a
- -
NUM 1
; ;
} }
while while
( (
ID b
<= <=
ID b
<= <=
NUM 20
) )
write write
ID c
; ;
ID c
; ;
} }
=====語法分析結果!======
語法分析成功!
程序分析成功!!!

別忘了加分啊,呵呵

D. 編譯原理期末課程設計

工大學生傷不起啊鐧懼害鍦板浘

本數據來源於網路地圖,最終結果以網路地圖最新數據為准。

E. 急求:幫忙做一下編譯原理課程設計(關於FIRST和FOLLOW集合的)

名稱:first和follow集合演算法設計辦
我知道更多

F. 編譯原理課程設計

%{

/* FILENAME: C.Y */

%}
#define YYDEBUG_LEXER_TEXT (yylval) /* our lexer loads this up each time */
#define YYDEBUG 1 /* get the pretty debugging code to compile*/
#define YYSTYPE char * /* interface with flex: should be in header file */
/* Define terminal tokens */
/* keywords */
%token AUTO DOUBLE INT STRUCT
%token BREAK ELSE LONG SWITCH
%token CASE ENUM REGISTER TYPEDEF
%token CHAR EXTERN RETURN UNION
%token CONST FLOAT SHORT UNSIGNED
%token CONTINUE FOR SIGNED VOID
%token DEFAULT GOTO SIZEOF VOLATILE
%token DO IF STATIC WHILE
/* ANSI Grammar suggestions */
%token IDENTIFIER STRINGliteral
%token FLOATINGconstant INTEGERconstant CHARACTERconstant
%token OCTALconstant HEXconstant
/* New Lexical element, whereas ANSI suggested non-terminal */
%token TYPEDEFname /* Lexer will tell the difference between this and
an identifier! An identifier that is CURRENTLY in scope as a
typedef name is provided to the parser as a TYPEDEFname.*/
/* Multi-Character operators */
%token ARROW /* -> */
%token ICR DECR /* ++ -- */
%token LS RS /* << >> */
%token LE GE EQ NE /* <= >= == != */
%token ANDAND OROR /* && || */
%token ELLIPSIS /* ... */
/* modifying assignment operators */
%token MULTassign DIVassign MODassign /* *= /= %= */
%token PLUSassign MINUSassign /* += -= */
%token LSassign RSassign /* <<= >>= */
%token ANDassign ERassign ORassign /* &= ^= |= */
%start translation_unit
%%
/* CONSTANTS */
constant:
INTEGERconstant
| FLOATINGconstant
/* We are not including ENUMERATIONconstant here because we
are treating it like a variable with a type of "enumeration
constant". */
| OCTALconstant
| HEXconstant
| CHARACTERconstant
;

string_literal_list:
STRINGliteral
| string_literal_list STRINGliteral
;
/************************* EXPRESSIONS ********************************/
primary_expression:
IDENTIFIER /* We cannot use a typedef name as a variable */
| constant
| string_literal_list
| '(' comma_expression ')'
;
postfix_expression:
primary_expression
| postfix_expression '[' comma_expression ']'
| postfix_expression '(' ')'
| postfix_expression '(' argument_expression_list ')'
| postfix_expression {} '.' member_name
| postfix_expression {} ARROW member_name
| postfix_expression ICR
| postfix_expression DECR
;
member_name:
IDENTIFIER
| TYPEDEFname
;
argument_expression_list:
assignment_expression
| argument_expression_list ',' assignment_expression
;
unary_expression:
postfix_expression
| ICR unary_expression
| DECR unary_expression
| unary_operator cast_expression
| SIZEOF unary_expression
| SIZEOF '(' type_name ')'
;
unary_operator:
'&'
| '*'
| '+'
| '-'
| '~'
| '!'
;
cast_expression:
unary_expression
| '(' type_name ')' cast_expression
;
multiplicative_expression:
cast_expression
| multiplicative_expression '*' cast_expression
| multiplicative_expression '/' cast_expression
| multiplicative_expression '%' cast_expression
;
additive_expression:
multiplicative_expression
| additive_expression '+' multiplicative_expression
| additive_expression '-' multiplicative_expression
;
shift_expression:
additive_expression
| shift_expression LS additive_expression
| shift_expression RS additive_expression
;
relational_expression:
shift_expression
| relational_expression '<' shift_expression
| relational_expression '>' shift_expression
| relational_expression LE shift_expression
| relational_expression GE shift_expression
;
equality_expression:
relational_expression
| equality_expression EQ relational_expression
| equality_expression NE relational_expression
;
AND_expression:
equality_expression
| AND_expression '&' equality_expression
;
exclusive_OR_expression:
AND_expression
| exclusive_OR_expression '^' AND_expression
;
inclusive_OR_expression:
exclusive_OR_expression
| inclusive_OR_expression '|' exclusive_OR_expression
;
logical_AND_expression:
inclusive_OR_expression
| logical_AND_expression ANDAND inclusive_OR_expression
;
logical_OR_expression:
logical_AND_expression
| logical_OR_expression OROR logical_AND_expression
;
conditional_expression:
logical_OR_expression
| logical_OR_expression '?' comma_expression ':'
conditional_expression
;
assignment_expression:
conditional_expression
| unary_expression assignment_operator assignment_expression
;
assignment_operator:
'='
| MULTassign
| DIVassign
| MODassign
| PLUSassign
| MINUSassign
| LSassign
| RSassign
| ANDassign
| ERassign
| ORassign
;
comma_expression:
assignment_expression
| comma_expression ',' assignment_expression
;
constant_expression:
conditional_expression
;
/* The following was used for clarity */
comma_expression_opt:
/* Nothing */
| comma_expression
;
/******************************* DECLARATIONS *********************************/
/* The following is different from the ANSI C specified grammar.
The changes were made to disambiguate typedef's presence in
declaration_specifiers (vs. in the declarator for redefinition);
to allow struct/union/enum tag declarations without declarators,
and to better reflect the parsing of declarations (declarators
must be combined with declaration_specifiers ASAP so that they
are visible in scope).
Example of typedef use as either a declaration_specifier or a
declarator:
typedef int T;
struct S { T T;}; /* redefinition of T as member name * /
Example of legal and illegal statements detected by this grammar:
int; /* syntax error: vacuous declaration * /
struct S; /* no error: tag is defined or elaborated * /
Example of result of proper declaration binding:
int a=sizeof(a); /* note that "a" is declared with a type in
the name space BEFORE parsing the initializer * /
int b, c[sizeof(b)]; /* Note that the first declarator "b" is
declared with a type BEFORE the second declarator is
parsed * /
*/
declaration:
sue_declaration_specifier ';'
| sue_type_specifier ';'
| declaring_list ';'
| default_declaring_list ';'
;
/* Note that if a typedef were redeclared, then a declaration
specifier must be supplied */
default_declaring_list: /* Can't redeclare typedef names */
declaration_qualifier_list identifier_declarator {} initializer_opt
| type_qualifier_list identifier_declarator {} initializer_opt
| default_declaring_list ',' identifier_declarator {} initializer_opt
;

declaring_list:
declaration_specifier declarator {} initializer_opt
| type_specifier declarator {} initializer_opt
| declaring_list ',' declarator {} initializer_opt
;

declaration_specifier:
basic_declaration_specifier /* Arithmetic or void */
| sue_declaration_specifier /* struct/union/enum */
| typedef_declaration_specifier /* typedef*/
;

type_specifier:
basic_type_specifier /* Arithmetic or void */
| sue_type_specifier /* Struct/Union/Enum */
| typedef_type_specifier /* Typedef */
;

declaration_qualifier_list: /* const/volatile, AND storage class */
storage_class
| type_qualifier_list storage_class
| declaration_qualifier_list declaration_qualifier
;

type_qualifier_list:
type_qualifier
| type_qualifier_list type_qualifier
;

declaration_qualifier:
storage_class
| type_qualifier /* const or volatile */
;

type_qualifier:
CONST
| VOLATILE
;

basic_declaration_specifier: /*Storage Class+Arithmetic or void*/
declaration_qualifier_list basic_type_name
| basic_type_specifier storage_class
| basic_declaration_specifier declaration_qualifier
| basic_declaration_specifier basic_type_name
;

basic_type_specifier:
basic_type_name /* Arithmetic or void */
| type_qualifier_list basic_type_name
| basic_type_specifier type_qualifier
| basic_type_specifier basic_type_name
;

sue_declaration_specifier: /* Storage Class + struct/union/enum */
declaration_qualifier_list elaborated_type_name
| sue_type_specifier storage_class
| sue_declaration_specifier declaration_qualifier
;

sue_type_specifier:
elaborated_type_name /* struct/union/enum */
| type_qualifier_list elaborated_type_name
| sue_type_specifier type_qualifier
;

typedef_declaration_specifier: /*Storage Class + typedef types */
typedef_type_specifier storage_class
| declaration_qualifier_list TYPEDEFname
| typedef_declaration_specifier declaration_qualifier
;

typedef_type_specifier: /* typedef types */
TYPEDEFname
| type_qualifier_list TYPEDEFname
| typedef_type_specifier type_qualifier
;

storage_class:
TYPEDEF
| EXTERN
| STATIC
| AUTO
| REGISTER
;

basic_type_name:
INT
| CHAR
| SHORT
| LONG
| FLOAT
| DOUBLE
| SIGNED
| UNSIGNED
| VOID
;

elaborated_type_name:
aggregate_name
| enum_name
;

aggregate_name:
aggregate_key '{' member_declaration_list '}'
| aggregate_key identifier_or_typedef_name
'{' member_declaration_list '}'
| aggregate_key identifier_or_typedef_name
;

G. 編譯原理課程設計-詞法分析器設計(C語言)

#include"stdio.h"/*定義I/O庫所用的某些宏和變數*/

#include"string.h"/*定義字元串庫函數*/

#include"conio.h"/*提供有關屏幕窗口操作函數*/

#include"ctype.h"/*分類函數*/

charprog[80]={''},

token[8];/*存放構成單詞符號的字元串*/

charch;

intsyn,/*存放單詞字元的種別碼*/

n,

sum,/*存放整數型單詞*/

m,p;/*p是緩沖區prog的指針,m是token的指針*/

char*rwtab[6]={"begin","if","then","while","do","end"};

voidscaner(){

m=0;

sum=0;

for(n=0;n<8;n++)

token[n]='';

ch=prog[p++];

while(ch=='')

ch=prog[p++];

if(isalpha(ch))/*ch為字母字元*/{

while(isalpha(ch)||isdigit(ch))/*ch為字母字元或者數字字元*/{

token[m++]=ch;

ch=prog[p++];}

token[m++]='';

ch=prog[p--];

syn=10;

for(n=0;n<6;n++)

if(strcmp(token,rwtab[n])==0)/*字元串的比較*/{

syn=n+1;

break;}}

else

if(isdigit(ch))/*ch是數字字元*/{

while(isdigit(ch))/*ch是數字字元*/{

sum=sum*10+ch-'0';

ch=prog[p++];}

ch=prog[p--];

syn=11;}

else

switch(ch){

case'<':m=0;token[m++]=ch;ch=prog[p++];

if(ch=='>'){

syn=21;

token[m++]=ch;}

elseif(ch=='='){

syn=22;

token[m++]=ch;}

else{

syn=20;

ch=prog[p--];}

break;

case'>':m=0;token[m++]=ch;ch=prog[p++];

if(ch=='='){

syn=24;

token[m++]=ch;}

else{

syn=23;

ch=prog[p--];}

break;

case':':m=0;token[m++]=ch;ch=prog[p++];

if(ch=='='){

syn=18;

token[m++]=ch;}

else{

syn=17;

ch=prog[p--];}

break;

case'+':syn=13;token[0]=ch;break;

case'-':syn=14;token[0]=ch;break;

case'*':syn=15;token[0]=ch;break;

case'/':syn=16;token[0]=ch;break;

case'=':syn=25;token[0]=ch;break;

case';':syn=26;token[0]=ch;break;

case'(':syn=27;token[0]=ch;break;

case')':syn=28;token[0]=ch;break;

case'#':syn=0;token[0]=ch;break;

default:syn=-1;}}

main()

{

printf(" Thesignificanceofthefigures: "

"1.figures1to6saidKeyword "

"2. "

"3.figures13to28saidOperators ");

p=0;

printf(" pleaseinputstring: ");

do{

ch=getchar();

prog[p++]=ch;

}while(ch!='#');

p=0;

do{

scaner();

switch(syn){

case11:printf("(%d,%d) ",syn,sum);break;

case-1:printf(" ERROR; ");break;

default:printf("(%d,%s) ",syn,token);

}

}while(syn!=0);

getch();

}

程序測試結果

對源程序beginx:=9:ifx>9thenx:=2*x+1/3;end#的源文件,經過詞法分析後輸出如下圖5-1所示:

具體的你在修改修改吧

H. 編譯原理 課程設計

好大的題,要用到bison【如何使用,請下載bison源代碼分析--gcc源代碼分析語法分析部分的電子版】和flex工具吧。

I. 期末的編譯課程設計啊。。。不知道大俠們能不能幫我一下,自己不會寫……用C語言就行,pl0文法我給出來

參考答案: 不要試圖控制別人,不要要求別人理解你。

J. 一個編譯原理的課程設計,急急急

回答:alkaid_pku
學長
4月14日 06:31 1. 預處理
2. 編譯
3. 匯編
4. 查找庫函數
5. 連接

閱讀全文

與編譯課程設計相關的資料

熱點內容
h264編碼器源碼 瀏覽:664
有什麼辦法翻錄加密視頻 瀏覽:666
java數據結構與演算法面試題 瀏覽:977
解壓不了是什麼意思 瀏覽:359
紐西蘭編程師年薪 瀏覽:321
程序員為什麼大多生閨女 瀏覽:51
c編程用英文還是中文 瀏覽:723
一點都不解壓的游戲 瀏覽:203
解壓為什麼不能用中文文件夾 瀏覽:615
伺服器如何解除備份 瀏覽:144
安卓手機為什麼用一年就變卡 瀏覽:11
如何用風變編程自動回復 瀏覽:512
安卓閱讀幣怎麼樣 瀏覽:437
京東app怎麼切號 瀏覽:583
進入傳奇伺服器後如何修改 瀏覽:42
m0單片機的cycle怎麼知道 瀏覽:806
linux命令太長 瀏覽:782
壓縮機nb1111y是多少w 瀏覽:45
打賞視頻用什麼伺服器好 瀏覽:154
方舟好友伺服器怎麼加mod 瀏覽:982