Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lfa:2022:lab10-cfl_2 [2022/12/12 00:45]
mihai.udubasa [10.2. Lexer Spec] fix solution for 1st string
lfa:2022:lab10-cfl_2 [2022/12/29 00:59] (current)
alexandra.udrescu01
Line 8: Line 8:
   - run the PDA on the given inputs \\   - run the PDA on the given inputs \\
   - is the grammar ambiguous? If yes, write a non ambiguous grammar that generates the same language \\   - is the grammar ambiguous? If yes, write a non ambiguous grammar that generates the same language \\
 +
 **10.1.1** input: aaaabb \\ **10.1.1** input: aaaabb \\
 $ S \leftarrow aS | aSb | \epsilon $ \\ $ S \leftarrow aS | aSb | \epsilon $ \\
 +
 +
 +
 <hidden Solution>​ <hidden Solution>​
 The start symbol of the PDA is S. \\ The PDA will only have one state q and it will accept via empty stack. \\ The start symbol of the PDA is S. \\ The PDA will only have one state q and it will accept via empty stack. \\
Line 29: Line 33:
 Repaired grammar: \\ $ S \leftarrow aS | A \\ A \leftarrow aAb | \epsilon $ Repaired grammar: \\ $ S \leftarrow aS | A \\ A \leftarrow aAb | \epsilon $
 </​hidden>​ </​hidden>​
 +
 +
 +
  
 **10.1.2** input: xayxcayatabcazz \\ **10.1.2** input: xayxcayatabcazz \\
 +
 +
 +
 $ S \leftarrow a | xAz | SbS | cS  \\ A \leftarrow SyS | SyStS $ $ S \leftarrow a | xAz | SbS | cS  \\ A \leftarrow SyS | SyStS $
 +
 +
 +
 <hidden Solution>​ <hidden Solution>​
 The  PDA has the following transitions looping on state q: The  PDA has the following transitions looping on state q:
Line 60: Line 73:
 $ S \leftarrow TbS | T  \\ T \leftarrow cT | xAz | a \\ A \leftarrow SyS | SyStS $ \\ $ S \leftarrow TbS | T  \\ T \leftarrow cT | xAz | a \\ A \leftarrow SyS | SyStS $ \\
 </​hidden>​ </​hidden>​
 +
 +
 +
  
 **10.1.3** input: aaabbbbbccc \\ **10.1.3** input: aaabbbbbccc \\
 +
 $ S \leftarrow ABC \\ A \leftarrow aA | \epsilon \\ B \leftarrow bbB | b \\ C \leftarrow cC | c $  $ S \leftarrow ABC \\ A \leftarrow aA | \epsilon \\ B \leftarrow bbB | b \\ C \leftarrow cC | c $ 
 +
 +
 +
 +
 <hidden Solution>​ <hidden Solution>​
 The  PDA has the following transitions looping on state q: The  PDA has the following transitions looping on state q:
Line 85: Line 106:
 The accepted language is $ L(G) = \{a^{m}b^{2n + 1}c^{p+1} | m,n,p \ge 0\} $ \\ The accepted language is $ L(G) = \{a^{m}b^{2n + 1}c^{p+1} | m,n,p \ge 0\} $ \\
 </​hidden>​ </​hidden>​
 +
 +
  
 ===== 10.2. Lexer Spec ===== ===== 10.2. Lexer Spec =====
Line 93: Line 116:
 Separate the following input strings into lexemes: Separate the following input strings into lexemes:
   * 010101   * 010101
 +
 +
 +
 <​hidden> ​ <​hidden> ​
 Although the entire string is matched by PAIRS and NO_CONSEC_ONE,​ PAIRS is defined first, thus it will be the first picked. \\ Although the entire string is matched by PAIRS and NO_CONSEC_ONE,​ PAIRS is defined first, thus it will be the first picked. \\
 PAIRS "​010101"​ PAIRS "​010101"​
 +
 +
 </​hidden>​ </​hidden>​
 +
 +
   * 1010101011   * 1010101011
 +
 +
 <​hidden> ​ <​hidden> ​
 First we have a maximal match on "​101010101"​ for regex NO_CONSEC_ONE. The remaining string, "​1",​ is matched by both ONES and NO_CONSEC_ONE,​ but ONES  is defined first. \\ First we have a maximal match on "​101010101"​ for regex NO_CONSEC_ONE. The remaining string, "​1",​ is matched by both ONES and NO_CONSEC_ONE,​ but ONES  is defined first. \\
 NO_CONSEC_ONE "​101010101"​ \\ ONES "​1"​ NO_CONSEC_ONE "​101010101"​ \\ ONES "​1"​
 </​hidden>​ </​hidden>​
 +
 +
   * 01110101001   * 01110101001
 +
 +
 +<​hidden>​
 +PAIRS "​01"​ \\
 +ONES "​11"​ \\
 +NO_CONSEC_ONES "​0101001"​
 +</​hidden>​
 +
 +
   * 01010111111001010   * 01010111111001010
 +
 +
 +<​hidden>​
 +PAIRS "​010101"​ \\
 +ONES "​11111"​ \\
 +NO_CONSEC_ONES "​001010"​
 +</​hidden> ​
 +
 +
   * 1101101001111100001010011001   * 1101101001111100001010011001
 +
 +
 +<​hidden>​
 +ONES "​11"​
 +PAIRS "​01101001"​ \\
 +ONES "​1111"​ \\
 +NO_CONSEC_ONES "​0000101001"​ \\
 +PAIRS "​1001"​
 +</​hidden>​