Differences

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

Link to this comparison view

Both sides previous revision Previous revision
lfa:lab [2018/10/02 11:10]
pdmatei
lfa:lab [2018/10/02 11:20] (current)
pdmatei
Line 149: Line 149:
  
 ==== Application - parsing lists ==== ==== Application - parsing lists ====
 +
 +Consider the following BNF grammar which describes lists:
 +<​code>​
 +<​integer>​ ::= [0-9]+
 +<op> ::= "​++"​ | ":"​
 +<​element>​ ::= <​integer>​ | <op> | <​list>​
 +<​sequence>​ ::= <​element>​ | <​element>​ " " <​sequence> ​
 +<​list>​ ::= | "​()"​ | "​("​ <​sequence>​ "​)"​
 +</​code>​
 +
 +The following are examples of lists:
 +<​code>​
 +(1 2 3)
 +(1 (2 3) 4 ())
 +(1 (++ (: 2 (3)) (4 5)) 6)
 +</​code>​
 +
 +Your task is to:
 +  * correctly parse such lists:
 +    * write a JFlex file to implement the lexer:
 +      * Since the language describing lists is Context Free, in order to parse a list, you need to keep track of the opened/​closed parenthesis. ​
 +      * Start by write a PDA (on paper) which accepts correctly-formed lists. Treat each regular expression you defined (for numbers and operators) as a single symbol;
 +      * Implement the PDA (strategy) in the lexer file;
 +  * given a correctly-defined list, write a procedure which evaluates lists operations (in the standard way); For instance, ''​(1 (++ (: 2 (3)) (4 5)) 6)''​ evaluates to ''​(1 (2 3 4 5) 6)''​
 +  * write a procedure which checks if a list is **semantically valid**. What type of checks do you need to implement?