Question: ) Give context - free grammars rules for the language in Assignment 2 . For each set of grammar rules ensure they can be used
Give contextfree grammars rules for the language in Assignment For each set of grammar rules ensure they can be used to construct a LL parser ie unambiguous grammar without leftrecursion and leftfactors. The language follows the following rules: a The program consist of function definitions andor 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 readwritereturnbreak 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 ore Operators with same precedence follow left associativity rule. All expressions conditional or mathematical have expressions, numbers andor 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 danglingelse 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 prepended 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
