Answered step by step
Verified Expert Solution
Question
1 Approved Answer
G++ Language Syntax Analyzer: Given the description of the G++ language (G++Syntax.pdf) you are asked to implement a syntax analyzer that accepts or rejects a
G++ Language Syntax Analyzer: Given the description of the G++ language (G++Syntax.pdf) you are asked to implement a syntax analyzer that accepts or rejects a given program in G++. Syntax analysis rules of G++ is explained in the document in G++Syntax.pdf. You are asked to implement the syntax analysis in two different ways: 1. There are tools to implement syntax analysis given the rules in a meta-grammar such as CFGs. One such tool is "Yacc" that lets you generate C code to do the syntax analysis. 2. For this course, you will be implementing a syntax analysis algorithm for G++ in Lisp as well. For this you are not expected to use a meta-grammar to define the lexical syntax of your language. Both analyses tool should start the interpreter. It will read one line at a time from the user and check if the input syntax is correct while generating the parse tree for later processing. You are also expected to implement code for expressions as well as if statements. G++ Language Interpreter using Flex and Yacc ( 35 points): Implement your interpreter using Yacc. For this you will also need your lexer from the previous homework. Hand in your "gpp_interpreter.y" file for this part of the homework. You are also expected to submit the corresponding C file generated by your lexer and syntax analyzer along with any other .h or .c file that is needed to compile "gpp_interpreter.c" using GCC on Ubuntu (16 or later). Full score would require the lexer code to implement the CFG for expressions and if statements. This also means that you need to have the proper things for some basic data types. 20 points will be taken away for those not implementing a proper CFG. G++ is a language being developed for teaching - Starting G++ without an input file... - Keywords: and, or, not, eq, gt, nil, set, defvar, purposes at Technical University. This language has the following "vision": $g++ deffun, while, if, load, disp, true, false - Lisp like syntax - Operators: +/(), - Interpreted - Starting G++ with an input file... - Comment: Line or part of the line starting with ;; - Imperative, non-object oriented - Static scope, static binding, strongly typed, ... - Terminals: - A few built-in types to promote exact arithmetic - Keywords for various domains such as computational \$g+t myhelloward.g++ - Operators - Literals: There is only predefined type in this language. geometry G++- Concrete Syntax G++- Concrete Syntax KW WIIL, DEFV, DEFF, KW WHILE, KW IF, KWEXIT, - Non-terminals: - \$START \$INPUT KWLOAD,KWDISP,KWTRUE, KW_FALSE - SSTART, SINPUT, SEXPLIST, SEXP,... - \$INPUT > \$FUNCTION | \$EXP | \$EXPLIST OP_PLUS, OP_MINUS, OP_DIV, OP_MULT, OP, CP, OP_SET OPCOMMA,OPAND,OPOR,OPNOT1OPEQ,OPGT COMMENT VALUEF 10 G++- Concrete Syntax G++-Syntax G++-Syntax - An expression always returns a fraction - An expression list returns the value of the last expression - Expressions: - \$EXP OP_OP OP_PLUS \$EXP \$EXP OP_CP I OP_OP OP_MINUS \$EXP \$EXP OP_CP I OP_OP OP_MULT \$EXP \$EXP OP_CP I OP_OP OP_DIV \$EXP \$EXP OP_CP | - Functions: ID | VALUEF | \$FCALL | \$ASG - Assignment: - Definition: - \$ASG OP OP_SET ID \$EXP CP SFUNCTION OP DEFF ID OFII ID | ID ID | ID ID ID CP - Imperative, therefore \$EXP will be evaluated first... - Call: OP \$EXPUST CP SFCALL OP ID ( \$EXP| \$EXP \$EXP \$EXP \$EXP SEXP ) CP - Parameter passing by value (only up to 3 parameters allowed) - Returning the value of the last expression - \$EXPLIST OP_OP \$EXPLIST \$EXP OP_CP - Note that function definition is an expression always returning of 1 - Control Statements: - \$EXP (if \$EXPB \$EXPUSTI \$EXPUSTI) - \$EXP - (while \$EXPB \$EXPLISTI) G++ - Variables - Binary values and expressions - \$EXP -> OP DEFV ID \$EXP CP /dduring a arrashy $EXPB( eq $EXP$EXP) : returns true if equal - \$EXPB (gt \$EXP \$EXP) : returns true if greater - SEXP OP KW_SET ID SEXP CP // setting a veribble - \$EXPB KW_TRUE KW_FALSE - Scope: $ EXPB (and \$EXPB \$EXPB) - Static, lexical scope (shadowing) - \$EXPB (or \$EXPB \$EXPB) - Binding: - Static binding $ EXPB not $ EXPB ) - Typing: - Strong typing
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started