首页 > 其他分享 >COMPILER simplified C programmin

COMPILER simplified C programmin

时间:2024-06-11 12:32:28浏览次数:24  
标签:statements CFG programmin syntax simplified EXPR line id COMPILER

COMPILER PROJECT 2024

The goal of the term-project is to implement a bottom-up syntax analyzer (a.k.a., parser) as we’velearned. More specifically, you will implement the syntax analyzer for a simplified C programminglanguage with the following context free grammar G;

CFG G:

01: CODE → VDECL CODE | FDECL CODE | ϵ

02: VDECL → vtype id semi | vtype ASSIGN semi

03: ASSIGN → id assign RHS

04: RHS → EXPR | literal | character | boolstr

05: EXPR → EXPR addsub EXPR | EXPR multdiv EXPR

06: EXPR → lparen EXPR rparen | id | num

07: FDECL → vtype id lparen ARG rparen lbrace BLOCK RETURN rbrace

08: ARG → vtype id MOREARGS | ϵ

09: MOREARGS → comma vtype id MOREARGS | ϵ

10: BLOCK → STMT BLOCK | ϵ

11: STMT → VDECL | ASSIGN semi

12: STMT → if lparen COND rparen lbrace BLOCK rbrace ELSE

13: STMT → while lparen COND rparen lbrace BLOCK rbrace

14: COND → COND comp COND | boolstr

15: ELSE → else lbrace BLOCK rbrace | ϵ

16: RETURN → return RHS semi

Terminals (21)

  1. vtype for the types of variables and functions
  2. num for signed integers
  3. character for a single character
  4. boolstr for Boolean strings
  5. literal for literal strings
  6. id for the identifiers of variables and functions
  7. if, else, while, and return for if, else, while, and return statements respectively8. class for class declarations
  8. addsub for + and - arithmetic operators
  9. multdiv for * and / arithmetic operators
  10. assign for assignment operators
  11. comp for comparison operators
  12. semi and comma for semicolons and commas respectively
  13. lparen, rparen, lbrace, and rbrace for (, ), {, and } respectively

Non-terminals (13) CODE, VDECL, ASSIGN, RHS, EXPR, FDECL, ARG, MOREARGS, BLOCK, STMT, COND, ELSE,RETURN

Start symbol: CODE

Descriptions

✓ The given CFG G is non-left recursive, but ambiguous.

✓ Codes include zero or more declarations of functions and variables (CFG line 1)

✓ Variables are declared with or without initialization (CFG line 2 ~ 3)

✓ The right hand side of assignment operations can be classified into four types; 1) arithmeticoperations (expressions), 2) literal strings, 3) a single character, and 4) Boolean strings (CFG4)

✓ Arithmetic operations are the combinations of +, -, *, / operators (CFG line 5 ~ 6)

✓ Functions can have zero or more input arguments (CFG line 7 ~ 9)

✓ Function blocks include zero or more statements (CFG line 10)

✓ There are four types of statements: 1) variable declarations, 2) assignment operations, 3) iflse statements, and 4) while statements (CFG line 11 ~ 13)

✓ if and while statements include a conditional operation which consists of Boolean stringsand condition operators (CFG line 12 ~ 14)✓ if statements can be used with or without an else statement (CFG line 12 & 15)

✓ return statements return 1) the computation result of arithmetic operations, 2) literal strings,

  1. 3) a single character, or 4) Boolean strings (CFG line 16)

✓ This is not a CFG for C. This is for simplified C. So, you don’t need to consider grammarsand structures not mentioned in this specification.Based on thiCFG, you should implement a bottom-up parser as follows:

✓ Discard an ambiguity in the CFG

✓ Construct a SLR parsing table for the non-ambiguous CFG through the following website:http://jsmachines.sourceforge.net/machines/slr.html

✓ Implement a SLR parsing program for the simplified Java programming language by using theconstructed table.For the implementation, please use C, C++, or Python (If you want to use . Your syntax analyzermust run on Linux or Unix-like OS without any error.

Your syntax analyzer should work as follows:

The execution flow of your syntax analyzer: yntax_analyzer <input file>

Input: A sequence of tokens (terminals) written in the input filee.g., vtype id semi vtype id lparen rparen lbrace if lparen boolstr comp boolstr rparen lbracerbrace

Output

◼ (If a parsing decision output is “accept”) please construct a parse tree (not abstract syntax tree) for the input sequence

◆ You can design the data structure to represent the tree as you want.

◼ (If an output is “reject”) please make an error report which explains why and where the error occurred (e.g., line number)

Term-project schedule and submission

Deadline: 6/9, 23:59 (through an e-class system)

◼ For a delayed submission, you will lose 0.1 * your original project score per eachdelayed day

✓ Submission file: team_<your_team_number>.zip or .tar.gz

◼ The compressed file should contain

◆ The source code of your syntax analyzer with detailed comments

◆ The executable binary file of your syntax analyzer (if you implemented using

a complied language)

◆ Documentation (the most important thing!)

⚫ It must include 1) your non-ambiguous CFG G and 2) your SLR parsing table

⚫ It must also include any change in the CFG G and all about how your syntaxnalyzer works for validating token sequences (for example, overallprocedures, implementation details like algorithms and data structures,working examples, and so on)◆ Test input files and outputs which you used inthis project

⚫ The test input files are not given. You should make the test files, by yourself,which can examine all the syntax grammars.

✓ If there exist any error in the given CFG, please send an e-mail to [email protected]

标签:statements,CFG,programmin,syntax,simplified,EXPR,line,id,COMPILER
From: https://www.cnblogs.com/qq99515681/p/18240954

相关文章

  • JAVA stringcompiler动态编译
    packagecompiler.mydemo;importjavax.tools.Diagnostic;importjavax.tools.DiagnosticCollector;importjavax.tools.FileObject;importjavax.tools.ForwardingJavaFileManager;importjavax.tools.JavaCompiler;importjavax.tools.JavaFileManager;importjava......
  • SuntoryProgrammingContest2024(AtCoder Beginner Contest 357)
    A-SanitizeHands题意:给定一个序列和m,问m按顺序减去这个序列,m>=0情况下最多能减多少个数思路:前缀和+prev(upper_bound())总结:disinfectan(消毒ji),disinfect(消毒,杀毒),aliens(外星人),voidsolve(){ intn,m; cin>>n>>m; vector<int>a(n); for(inti=......
  • 操作系统入门系列-MIT6.828(操作系统工程)学习笔记(四)---- C语言与计算机架构(Programmin
    系列文章目录操作系统入门系列-MIT6.S081(操作系统)学习笔记(一)----操作系统介绍与接口示例操作系统入门系列-MIT6.828(操作系统工程)学习笔记(二)----课程实验环境搭建(wsl2+ubuntu+quem+xv6)操作系统入门系列-MIT6.828(操作系统工程)学习笔记(三)----xv6初探与实验一(Lab:Xv6and......
  • 2024 江苏省大学生程序设计大赛 2024 Jiangsu Collegiate Programming Contest(FGKI)
    题目来源:https://codeforces.com/gym/105161文章目录F-DownloadSpeedMonitor题意思路编程G-DownloadTimeMonitor题意思路编程K-NumberDeletionGame题意思路编程I-IntegerReaction题意思路编程写在前面:今天打的训练赛打的很水·····,我发现我们......
  • Error in system(paste(MAKE, p1(paste("-f", shQuote(makefiles))), "compilers"),
     001、R语言windows中安装R包出现如下报错Errorinsystem(paste(MAKE,p1(paste("-f",shQuote(makefiles))),"compilers"),:'make'notfound 002、确认是否安装Rtoolsinstall.packages("pkgbuild")pkgbuild::find_rtools(debug=TRU......
  • EBU4201 Introductory Java Programming 2023/24Mini Project(⼉童练习乘法表 下个文
    Task1[25marks]SuperHeroTTisasimpleGraphicalUserInterface(GUI)applicationforchildrenwheretheycanpractisetheirtimestables(seeFigure1).Whenlaunched,yourappshouldlooklikeFigure1-FirstlaunchofSuperHeroTT.Thedrop-downbo......
  • HITSC_Testing and Test-First Programming
    目标测试优先模块设计:等价划分、边界值分析覆盖度本节内容如下Softwaretesting测试是为了“破坏”好的测试?能发现错误不冗余有最佳特性别太复杂也别太简单测试等级回归测试包含三类单元、集成、系统,对应不同的级别一些概念静态和动态测试:静态只能发现一些......
  • Tokio Marine & Nichido Fire Insurance Programming Contest 2024(AtCoder Beginner C
    A-WhoAtetheCake?题意:有三个嫌疑犯(1,2,3(号码))现在有两个证人他们指出谁不是嫌疑犯,你可以找到确定的那个罪人吗?找到输出这个人的号码没找到输出-1思路:如果两人指出的人是一个人则输出-1不是则输出6-a-b,因为1+2+3=6(sum)减去a,b肯定可以到达......
  • The 2024 International Collegiate Programming Contest in Hubei Province, China
    Preface感觉好久没训练了,这周末又要出战西安,只好找个平时的晚上抽空训练一场这场题本身质量还是不错的,但由于徐神被模拟题关了一整场,我前期被一个分类讨论写的心态爆炸导致最后一个medium的计数题没做出来,然后一个medium~hard的D题转化和性质基本都挖掘完了,最后没想到暴力增量......
  • 2024 ICPC National Invitational Collegiate Programming Contest, Wuhan Site
    2024ICPCNationalInvitationalCollegiateProgrammingContest,WuhanSiteI.CyclicAppleStrings题意:给定一个01字符串,每次操作可以将这个字符串向左循环移动任意次数,求让这个字符串变成有序的需要最少几次操作思路:每次只能减少最右边的不和有边界相邻的一个1的长块,每次......