Question
Write lexer and parser specifications for micro-Icon so Exercise 11.8 above could be solved using concrete syntax. Exercise 11.8: The micro-Icon expression 2 * (1
Write lexer and parser specifications for micro-Icon so Exercise 11.8 above could be solved using concrete syntax.
Exercise 11.8:
The micro-Icon expression 2 * (1 to 4) succeeds four times, with the values 2468. This can be shown by evaluating
open Icon;;
run (Every(Write(Prim(\"*\", CstI 2, FromTo(1, 4)))));;
using the interpreter in Icon.fs and using abstract syntax instead of the concrete syntax (2 * (1 to 4)). We must use abstract syntax because we have not written lexer and parser specification for micro-Icon. A number of examples in abstract syntax are given at the end of the Icon.fs source file.
(i) Write an expression that produces and prints the values 3579. Write an expression that produces and prints the values 21 22 31 32 41 42.
(ii) The micro-Icon language (like real Icon) has no Boolean values. Instead, failure is used to mean false, and success means true. For instance, the lessthan comparison operator (
(iii) Extend the abstract syntax with unary (one-argument) primitive functions, like this: Extend the interpreter eval to handle such unary primitives, and define two such primitives: (a) define a primitive sqr that computes the square x x of its argument x; (b) define a primitive even that fails if its argument is odd, and succeeds if it is even (producing the argument as result). For instance, square(3 to 6) should succeed four times, with the results 9, 16, 25, 36, and even(1 to 7) should succeed three times with the results 2, 4, 6.
(iv) Define a unary primitive multiples that succeeds infinitely many times, producing all multiples of its argument. For instance, multiples(3) should produce 3, 6, 9, . . . . Note that multiples(3 to 4) would produce multiples of 3 forever, and would never backtrack to the subexpression (3 to 4) to begin producing multiples of 4.
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