# Training Exams for PL

# Exam: Parsing RegExps

AST Explorer (opens new window) supports various regexp parsers. Feel free to play with them and have a look at the shapes of the ASTs.

Watch this video

and this other from minute 30:30:

# Exam: Parsing JSON

See also another exam example in section Translator from Egg AST to AST Term of the TFA. The task there is to build a JSON Parser and translate a JSON containing the AST of an Egg parser onto the term notation.

# Parsing JSON

# Question

# Examples of Solutions

# Translator from Egg AST to AST Term

# Question

Example of a second part for the exam:

Assume the input JSON contains an Egg AST and translate it to AST Term notation.

Here is an example. Given the input program:

➜  evm2term git:(master) cat examples/property.egg 
x["sub", 1]("length") # 3
1
2

Whose JSON looks like:

➜  evm2term git:(master) head -n 4 examples/property.json 
{
  "type": "apply",
  "operator": {
    "type": "property",
1
2
3
4
5

The output of the evm2term translator will be:

➜  evm2term git:(master) evm2term examples/property.json 
apply(op:property(op:word{x}, args:[value{sub},value{1}]), args:[value{length}])
1
2

Possible Improvements if you decide it to present as TFA:

  • Add pretty printing of the term
  • Give support to JS Esprima ASTs
  • Make it generic so that any compiler AST can be added via some configuration

# Example of Solution

Comments#

Last Updated: a month ago