Workshop #2 Creating production rules

Workshop #2

Creating production rules 

1. Objective

Deepen theoretical knowledge and prepare for laboratory work related to the building Parser.

2. Self-study guidelines

When preparing for the class, you should use the lecture materials and sources of information from official Internet resources dedicated to Parser.

3.  Procedure to performing the work

3.1 Depending on the sequence (ordinal)  number of your surname in the list of your group (or according to item 21), choose the individual task (item 4).

3.2 Build production rules.

3.3 Check the production rules of grammar for having mistaken on the example of an input string with and without errors.

3.4 Check the grammar for having non-generating symbols.

3.5 Check grammar for having unreachable.

3.6 Implement a software model for checking grammar for having useless (non-generating and unreachable)  symbols.

3.7 Make a report on laboratory work. The report must contain the description: of formal grammar (G ={VT, VA, I Î VA, R } ), software model on Python language in Google COLAB and screen with program results.

4. Individual task

1. Variable Declaration and Initialization (C++):

Example:  int k=10, m = 13, z=7; float d = 6.358;

2. Declaring an Array (C++):

· Example: int c[12]; int n[10]={0}; float k[] = {1.1, 2.2, 3.3}; int b[][] = {{1,2},{3,4}};

3. Loop operator  for (C++):

Example:

· for(int i=0, float j=1.1; i < 10; j < 10.1; i++; j++)

4. Loop operator  while (C++):

Example:

· while(i!=10 && k!=6 && z!=5) {i++; k+=2; z-=4;}

5. Loop operator   do… wile(C++):

Example:

· do {i++; k+=2.2; z-=4.8;}while(i!=10 && k!=6.2 && z!=5);

6. Operator if (C++):

Example:

· if((k>6 && m!=3) || z==6 ) {k++; x+=6;}

7. Operator  switch  (C++):

Example:

· switch(grade) {case ‘A’: case ‘a’: ++count; break; case ‘B’: ++bcount; break; default: break;}

8. Arithmetic Operators, which includes identifiers, operations: “+”, “-“ ,”*”,”\”, ”(”, ”)”and parentheses (C++):

Example:

· result = a*(b+c*(x+c)); res_= a/b+x;

9.  Arithmetic Operators, which includes  increment and decrement operations (C++):

Example:

· result = ++i*(a+=5)+c--;

10. Array of Pointers (C++):

Example:

· char cha_r*[10]; int *  x[2];

11.  Arithmetic Operators, which includes identifiers, operations: “+”, “-“ ,”*”,”\”, and parentheses (C++):

Example:

• a= a-b+c/x+c;  b= a-b+x;  c=a*a*a*a;

12. Description of variables and arrays of real type (C++):

Example:

• float b[][] = {{1.1,2.2},{3.3,4.4}}; double k = 1000.01; float c[]={3.5};13. 13. Description of collection. (Python).

Example:

baseline = {'music': 'bach', 'art': 'rembrandt'}

adjustments = {'art': 'van gogh', 'opera': 'carmen'}

14. Description of constants (C++):

Example:

• const double pi(3.14159); const double float(6.0221413e23); const double gravity(9.8);

15. Description of tuple. (Python).

Example:

• my_tuple = 1, 2, 3

• my_tuple = 1, "Hello", 3.4

16. C++ Function Prototype and Definition

Example:

• void print(int k, char z, float d); int sum(int a, double b);

17. Input/Output Operator in C++

Example:

• cin >> a>>b>>c; cout << a; cout << c << b << a;

18. Java class description

Examples:

•public class Person {

  // fields

  String name;

   // methods

  void printName() {

      System.out.println(name);

  }

}

19. Description of list. (Python).

Examples:

•# list with elements of different data types

list1 = [1, "Hello", 3.4]

•# list with duplicate elements

list1 = [1, "Hello", 3.4, "Hello", 1]

•# empty list

 list3 = []

20. Declaration and Definition of Class in C++

Example:

•class Car

{

public: int a;

void engine()

{

body

21 and more.

· Variable Declaration and Initialization (in basic languages up to you).

· Declaration and Definition of Class (in basic languages up to you).

· Loop operators (in basic languages up to you).

· Logical operators (in basic languages up to you).

3 Example of  building  production rules

Example 1.

Problem statement.

Create a production rules for the language L, the terminal dictionary of which  Vm = {*, |}, and the strings of the language have the following limitations:

• each string begins with the symbol * and ends with two symbol **.

• between the beginning and the end of the strings there can be either a non-empty sequence of sticks or several such sequences separated by symbol *.

1. First, let's build several strings of the given language, which can be presented in the following form:

* |||**,

                                                  * |*|*|**,

                                                  * ||*||||*|||||** ,

                                                  * |||*|*||*||||||** .


发表评论

电子邮件地址不会被公开。 必填项已用*标注