rightarrow rightarrow a b z Single character ident
rightarrow + | * | () | rightarrow a | b | ... | z Single character identifiers are no longer allowed! Replace the current production with one or more different rules that will support the following kinds of NEW identifiers: Integer variable names start with $ followed by 1 or 2 additional characters, the first of which must be a lower case letter, the second of which can be a lower case letter or a digit, For example, $al and $2 are both valid integer variable names. Float variable names start with If followed by 1 or 2 additional characters, the first of which must be a lower case letter, the second of which can be a lower case letter or a digit, For example, #b and #x0 are both valid float variable names Modify the productions to also allow for the arithmetic operations - and/Give 3 examples of valid expressions in the new grammar, one of which is at least 6 characters long. For ONE of your valid expressions that is at least 6 characters long, show its derivation. Show its parse tree. Give 3 examples of invalid expressions in the new grammar. In EACH CASE, state in your own words WHY it is invalid. Write a lexical analyzer (scanner) for this new BNF in a programming language of your choice. Given an input expression, this scanner should output a list of lexemes and tokens, one per line. If something is \"wrong\" in the input stream, you must try to \"recover\" and push on as best you can through the scan.
Solution
Changed id rules to accept integers
id ---> $AB |
A --->a|b|...|z
B --->epsilon | 1|2|3|...|9
Id rules to accept float values
id ---> #AB |
A --->a|b|...|z
B --->epsilon | 1|2|3|...|9
E rules to accept - and / operators
E ---> <E> - <E> | <E> / <E> add these to productions to E productions given above.
Examples:
1) #a1 + $a2 + $b1 + $b2 * #a3 - $b3 / $a4
2) #a1 / $a2 - $b1 * $b2 - #a3 / $b3 * $a4
3) #a1 - $a2 * $b1 - $b2 / #a3 + $b3 + $a4
