1. Homepage
  2. Programming
  3. CAU COMPILER PROJECT 2024: Syntax analyzer

CAU COMPILER PROJECT 2024: Syntax analyzer

Engage in a Conversation
CAUCOMPILER PROJECTCSyntax AnalyzerC++CFGSLR

COMPILER PROJECT 2024 CourseNana.COM

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

CFG G: CourseNana.COM

  1. 01:  CODE → VDECL CODE | FDECL CODE | ε CourseNana.COM

  2. 02:  VDECL → vtype id semi | vtype ASSIGN semi CourseNana.COM

  3. 03:  ASSIGN → id assign RHS CourseNana.COM

  4. 04:  RHS → EXPR | literal | character | boolstr CourseNana.COM

  5. 05:  EXPR → EXPR addsub EXPR | EXPR multdiv EXPR CourseNana.COM

  6. 06:  EXPR → lparen EXPR rparen | id | num CourseNana.COM

  7. 07:  FDECL → vtype id lparen ARG rparen lbrace BLOCK RETURN rbrace CourseNana.COM

  8. 08:  ARG → vtype id MOREARGS | ε CourseNana.COM

  9. 09:  MOREARGS → comma vtype id MOREARGS | ε CourseNana.COM

  10. 10:  BLOCK → STMT BLOCK | ε CourseNana.COM

  11. 11:  STMT → VDECL | ASSIGN semi CourseNana.COM

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

  13. 13:  STMT → while lparen COND rparen lbrace BLOCK rbrace CourseNana.COM

  14. 14:  COND → COND comp COND | boolstr CourseNana.COM

  15. 15:  ELSE → else lbrace BLOCK rbrace | ε CourseNana.COM

  16. 16:  RETURN → return RHS semi CourseNana.COM

Terminals (21) CourseNana.COM

  1. vtype for the types of variables and functions CourseNana.COM

  2. num for signed integers CourseNana.COM

  3. character for a single character CourseNana.COM

  4. boolstr for Boolean strings CourseNana.COM

  5. literal for literal strings CourseNana.COM

  6. id for the identifiers of variables and functions CourseNana.COM

  7. if, else, while, and return for if, else, while, and return statements respectively CourseNana.COM

  1. class for class declarations CourseNana.COM

  2. addsub for + and - arithmetic operators CourseNana.COM

  3. multdiv for * and / arithmetic operators CourseNana.COM

  4. assign for assignment operators CourseNana.COM

  5. comp for comparison operators CourseNana.COM

  6. semi and comma for semicolons and commas respectively CourseNana.COM

  7. lparen, rparen, lbrace, and rbrace for (, ), {, and } respectively CourseNana.COM

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

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

  • ✓  Variables are declared with or without initialization (CFG line 2 ~ 3) CourseNana.COM

  • ✓  The right hand side of assignment operations can be classified into four types; 1) arithmetic CourseNana.COM

    operations (expressions), 2) literal strings, 3) a single character, and 4) Boolean strings (CFG CourseNana.COM

    4) CourseNana.COM

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

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

  • ✓  Function blocks include zero or more statements (CFG line 10) CourseNana.COM

  • ✓  There are four types of statements: 1) variable declarations, 2) assignment operations, 3) if- CourseNana.COM

    else statements, and 4) while statements (CFG line 11 ~ 13) CourseNana.COM

  • ✓  if and while statements include a conditional operation which consists of Boolean strings CourseNana.COM

    and condition operators (CFG line 12 ~ 14) CourseNana.COM

  • ✓  if statements can be used with or without an else statement (CFG line 12 & 15) CourseNana.COM

  • ✓  return statements return 1) the computation result of arithmetic operations, 2) literal strings, CourseNana.COM

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

  • ✓  This is not a CFG for C. This is for simplified C. So, you don’t need to consider grammars CourseNana.COM

    and structures not mentioned in this specification. CourseNana.COM

Based on this CFG, 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: CourseNana.COM

http://jsmachines.sourceforge.net/machines/slr.html CourseNana.COM

Implement a SLR parsing program for the simplified Java programming language by using the constructed table. CourseNana.COM

For the implementation, please use C, C++, or Python (If you want to use . Your syntax analyzer must run on Linux or Unix-like OS without any error.
Your syntax analyzer should work as follows: CourseNana.COM

The execution flow of your syntax analyzer: syntax_analyzer <input file> CourseNana.COM

Input: A sequence of tokens (terminals) written in the input file
e.g., vtype id semi vtype id lparen rparen lbrace if lparen boolstr comp boolstr rparen lbrace rbrace
CourseNana.COM

Output
(If a parsing decision output is “accept”) please construct a parse tree (not abstract CourseNana.COM

syntax tree) for the input sequence CourseNana.COM

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 CourseNana.COM

CourseNana.COM

error occurred (e.g., line number) CourseNana.COM

Term-project schedule and submission CourseNana.COM

Deadline: 6/9, 23:59 (through an e-class system)
For a delayed submission, you will lose 0.1 * your original project score per each CourseNana.COM

delayed day
Submission file: team_<your_team_number>.zip or .tar.gz CourseNana.COM

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 CourseNana.COM

a complied language) CourseNana.COM

Documentation (the most important thing!) CourseNana.COM

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

  • ⚫  It must also include any change in the CFG G and all about how your syntax CourseNana.COM

    analyzer works for validating token sequences (for example, overall procedures, implementation details like algorithms and data structures, working examples, and so on) CourseNana.COM

    Test input files and outputs which you used in this project
    The test input files are not given. You should make the test files, by yourself, CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
CAU代写,COMPILER PROJECT代写,C代写,Syntax Analyzer代写,C++代写,CFG代写,SLR代写,CAU代编,COMPILER PROJECT代编,C代编,Syntax Analyzer代编,C++代编,CFG代编,SLR代编,CAU代考,COMPILER PROJECT代考,C代考,Syntax Analyzer代考,C++代考,CFG代考,SLR代考,CAUhelp,COMPILER PROJECThelp,Chelp,Syntax Analyzerhelp,C++help,CFGhelp,SLRhelp,CAU作业代写,COMPILER PROJECT作业代写,C作业代写,Syntax Analyzer作业代写,C++作业代写,CFG作业代写,SLR作业代写,CAU编程代写,COMPILER PROJECT编程代写,C编程代写,Syntax Analyzer编程代写,C++编程代写,CFG编程代写,SLR编程代写,CAUprogramming help,COMPILER PROJECTprogramming help,Cprogramming help,Syntax Analyzerprogramming help,C++programming help,CFGprogramming help,SLRprogramming help,CAUassignment help,COMPILER PROJECTassignment help,Cassignment help,Syntax Analyzerassignment help,C++assignment help,CFGassignment help,SLRassignment help,CAUsolution,COMPILER PROJECTsolution,Csolution,Syntax Analyzersolution,C++solution,CFGsolution,SLRsolution,