Question: ) Give context - free grammars rules for the language in Assignment 2 . For each set of grammar rules ensure they can be used

) Give context-free grammars rules for the language in Assignment 2. For each set of grammar rules ensure they can be used to construct a LL(1) parser i.e., unambiguous grammar without left-recursion and left-factors. The language follows the following rules: (a) The program consist of function definitions and/or block statements. Each statement is terminated by a semicolon (;).(b) Block of statements can be a single statement or a sequence of statements. Each statement can be read/write/return/break statement or assignment statement. (c) In mathematical expressions power and remainder has highest precendence, followed by multiplication and division and the lowest precendence in addition and subtraction. (d) Conditional expression is comprised of mathematical expressions. Logical operators have higher precendence than relational operators. In logical operators, highest precendence is not, and followed by or.(e) Operators with same precedence follow left associativity rule. All expressions (conditional or mathematical) have expressions, numbers and/or identifiers as operands. For expressions anything enclosed in ((,)) have highest precedence than any operators. (f) While and If statements include the keywords while and if respectively, followed by conditional expression enclosed in within brackets ((,)) and followed by block of statements enclosed within curly brackets ({,}). If statements can have optional else following the closest if matching for dangling-else problem. (g) For other keywords: read can be applied to an identifier to input a value, write can write an expression as output, return can return expression and break is only followed by a semicolon. (h) An assignment statement include identifier, followed by = and followed by expression. (i) A function definition is pre-pended with the keyword function followed by an identifier for the function name, then followed by an argument list enclosed in Lbrac(() and RBrac()) and then followed by block of statements enclosed within curly brackets ({,}). The argument list can be empty or a sequence of identifier separated by comma (,). Function call statement include the function name followed by argument list and terminated by semicolon.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!