1. Engineering
  2. Computer Science
  3. given the following grammar tiny gt program name...

Question: given the following grammar tiny gt program name...

Question details

Given the following grammar :

%%
Tiny       -> PROGRAM Name ':' Dclns Body Name '.'    => "program";
Dclns      -> VAR (Dcln ';')*               => "dclns"
           ->                             => "dclns";
Dcln       -> Name list ',' ':' Type           => "dcln";
Type       -> INTEGER                             => "integer"
           -> BOOLEAN                        => "boolean";
Body       -> BEGINX Statement list ';' END         => "block";
Statement -> Name ASSIGNMENT Expression             => "assign"
           -> OUTPUT '(' Expression ')'              => "output"
           -> IF Expression THEN Statement
                            ELSE Statement          => "if"
           -> WHILE Expression DO Statement         => "while"
           -> Body
       ->                                           => "<null>";

Expression -> Term                                   
       -> Term LTE Term               => "<=";

Term       -> Primary
       -> Primary '+' Term               => "+";

Primary    -> '-' Primary                               => "-"
       -> READ                                    => "read"
           -> Name
           -> INTEGER_NUM               => "<integer>"
           -> '(' Expression ')';

Name       -> IDENTIFIER               => "<identifier>";

Write a program that takes two positive numbers N and M
if N <= M print the product of all numbers between N and M i.e N*(N+1)*(N+2)*...*M
else if N > M print the product of all numbers between M and N

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution