Difference between revisions of "PLC Laboratory 3"
(Created blank page) |
|||
Line 1: | Line 1: | ||
+ | == Computing sets FIRST and FOLLOW == | ||
+ | On the input, there is a context free grammar. For this grammar compute sets FIRST (for each right side of given rules) and FOLLOW (for each nonterminal). | ||
+ | |||
+ | To simplify the solution, you can use prepared grammar readers (they are prepared for Java and C#). They both read a context grammar from the input and represents it as an object. | ||
+ | |||
+ | == Input specification == | ||
+ | |||
+ | The first line of the input contains a number <code>N</code>. It defines the number of expressions your program should evaluate. These expressions are on next <code>N</code> lines. Each line contains exactly one expression. | ||
+ | |||
+ | == Output specification == | ||
+ | |||
+ | For each expression write one line containing the result – the computed value of the expression. If there is any error in the input, write text <code>ERROR</code> instead. | ||
+ | |||
+ | == Example == | ||
+ | * Input | ||
+ | <syntaxhighlight lang="haskell" > | ||
+ | {Input grammar} | ||
+ | A : b C | B d; | ||
+ | B : C C | b A; | ||
+ | C : c C | {e}; | ||
+ | </syntaxhighlight > | ||
+ | |||
+ | * Output | ||
+ | ''Your output can be different, based on your representation of epsilon and the'' '''end of input''' ''character.'' | ||
+ | <syntaxhighlight lang="haskell" > | ||
+ | first[1] = b | ||
+ | first[2] = b c d | ||
+ | first[3] = c {e} | ||
+ | first[4] = b | ||
+ | first[5] = c | ||
+ | first[6] = {e} | ||
+ | follow[A] = d $ | ||
+ | follow[B] = d | ||
+ | follow[C] = c d $ | ||
+ | </syntaxhighlight > |
Revision as of 09:19, 26 January 2022
Computing sets FIRST and FOLLOW
On the input, there is a context free grammar. For this grammar compute sets FIRST (for each right side of given rules) and FOLLOW (for each nonterminal).
To simplify the solution, you can use prepared grammar readers (they are prepared for Java and C#). They both read a context grammar from the input and represents it as an object.
Input specification
The first line of the input contains a number N
. It defines the number of expressions your program should evaluate. These expressions are on next N
lines. Each line contains exactly one expression.
Output specification
For each expression write one line containing the result – the computed value of the expression. If there is any error in the input, write text ERROR
instead.
Example
- Input
{Input grammar}
A : b C | B d;
B : C C | b A;
C : c C | {e};
- Output
Your output can be different, based on your representation of epsilon and the end of input character.
first[1] = b
first[2] = b c d
first[3] = c {e}
first[4] = b
first[5] = c
first[6] = {e}
follow[A] = d $
follow[B] = d
follow[C] = c d $