3.1 Example 1
Let us consider the following grammar for an integer. Let us define Σ = {0,1,2,3,4,5,6,7,8,9,+,-}, N = {S,D,I,J}. Let S
be the start symbol.
- S ::= JI
- J ::=
- J ::= "+"
- J ::= "-"
- D ::= "0"
- D ::= "1"
- D ::= "2"
- D ::= "3"
- D ::= "4"
- D ::= "5"
- D ::= "6"
- D ::= "7"
- D ::= "8"
- D ::= "9"
- I ::= D
- I ::= ID
Let us see how this works. Our first string is -562.
- J ::= "-": the minus symbol is now J.
- D ::= "5": the first digit is now D.
- I ::= D: the first digit is now I.
- D ::= "6": the second digit is now D.
- I ::= ID: the first and second digits are now I.
- D ::= "7": the last digit is now D.
- I ::= ID: all digits are now I.
- S ::= JI: the sign and all digits are now S.