資源簡介
語義分析程序的設計與實現
僅供參考。
語義分析 編譯原理 北郵 大三
實驗要求:編寫語義分析程序,實現對算術表達式的類型檢查和求值。要求所分析算術表達式由如下的文法產生。
實驗要求:用自底向上的語法制導翻譯技術實現對表達式的分析和翻譯。
(1) 寫出滿足要求的語法制導定義或翻譯方案。
(2) 編寫分析程序,實現對表達式的類型進行檢查和求值,并輸出:
① 分析過程中所有產生式。
② 識別出的表達式的類型。
③ 識別出的表達式的值。
(3) 實驗方法:可以選用以下兩種方法之一。
① 自己編寫分析程序。
② 利用YACC 自動生成工具。

代碼片段和文件信息
/*?A?Bison?parser?made?by?GNU?Bison?2.4.1.??*/
/*?Skeleton?implementation?for?Bison‘s?Yacc-like?parsers?in?C
???
??????Copyright?(C)?1984?1989?1990?2000?2001?2002?2003?2004?2005?2006
???Free?Software?Foundation?Inc.
???
???This?program?is?free?software:?you?can?redistribute?it?and/or?modify
???it?under?the?terms?of?the?GNU?General?Public?License?as?published?by
???the?Free?Software?Foundation?either?version?3?of?the?License?or
???(at?your?option)?any?later?version.
???
???This?program?is?distributed?in?the?hope?that?it?will?be?useful
???but?WITHOUT?ANY?WARRANTY;?without?even?the?implied?warranty?of
???MERCHANTABILITY?or?FITNESS?FOR?A?PARTICULAR?PURPOSE.??See?the
???GNU?General?Public?License?for?more?details.
???
???You?should?have?received?a?copy?of?the?GNU?General?Public?License
???along?with?this?program.??If?not?see? .??*/
/*?As?a?special?exception?you?may?create?a?larger?work?that?contains
???part?or?all?of?the?Bison?parser?skeleton?and?distribute?that?work
???under?terms?of?your?choice?so?long?as?that?work?isn‘t?itself?a
???parser?generator?using?the?skeleton?or?a?modified?version?thereof
???as?a?parser?skeleton.??Alternatively?if?you?modify?or?redistribute
???the?parser?skeleton?itself?you?may?(at?your?option)?remove?this
???special?exception?which?will?cause?the?skeleton?and?the?resulting
???Bison?output?files?to?be?licensed?under?the?GNU?General?Public
???License?without?this?special?exception.
???
???This?special?exception?was?added?by?the?Free?Software?Foundation?in
???version?2.2?of?Bison.??*/
/*?C?LALR(1)?parser?skeleton?written?by?Richard?Stallman?by
???simplifying?the?original?so-called?“semantic“?parser.??*/
/*?All?symbols?defined?below?should?begin?with?yy?or?YY?to?avoid
???infringing?on?user?name?space.??This?should?be?done?even?for?local
???variables?as?they?might?otherwise?be?expanded?by?user?macros.
???There?are?some?unavoidable?exceptions?within?include?files?to
???define?necessary?library?symbols;?they?are?noted?“INFRINGES?ON
???USER?NAME?SPACE“?below.??*/
/*?Identify?Bison?output.??*/
#define?YYBISON?1
/*?Bison?version.??*/
#define?YYBISON_VERSION?“2.4.1“
/*?Skeleton?name.??*/
#define?YYSKELETON_NAME?“yacc.c“
/*?Pure?parsers.??*/
#define?YYPURE?0
/*?Push?parsers.??*/
#define?YYPUSH?0
/*?Pull?parsers.??*/
#define?YYPULL?1
/*?Using?locations.??*/
#define?YYLSP_NEEDED?0
/*?Copy?the?first?part?of?user?declarations.??*/
/*?Line?189?of?yacc.c??*/
#line?1?“first.y“
#include?
#include?
#include?
#include?
#include?
struct?exp{
double?value;
int?type;
};
int?length;
#define?YYSTYPE?struct?exp
int?yylex(void);
void?yyerror(char?*?s);
int?yywrap(void);
/*?Line?189?of?yacc.c??*/
#line?93?“first.tab.c“
/*?Enabling?traces.??*/
#ifndef?YYDEBUG
#?define?YYDEBUG?0
#endif
/*?Enabling?verbose?error?messages.??*/
#ifdef?YYER
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????167333??2017-12-04?21:11??語義分析\first.exe
?????文件????????449??2017-12-04?21:11??語義分析\first.l
?????文件??????46353??2017-12-04?21:11??語義分析\first.tab.c
?????文件???????2101??2017-12-04?21:11??語義分析\first.tab.h
?????文件???????2083??2017-12-04?21:11??語義分析\first.y
?????文件??????37734??2017-12-04?21:11??語義分析\lex.yy.c
?????文件?????437356??2017-12-04?21:11??語義分析\程序設計3?語義分析程序的設計與實現.pdf
?????目錄??????????0??2017-12-04?21:11??語義分析
-----------?---------??----------?-----??----
???????????????693409????????????????????8
- 上一篇:單片機MP3源碼c51版
- 下一篇:上海大學編譯原理試卷.
評論
共有 條評論