# Lunes 2022/05/09
# Extending the Egg Interpreter
- See lab Extending the Egg Interpreter
# Old Exam Example
# Parsing JSON
# Question
- Old exam sample: pdf file. Question: Parse the JSON Language
# Examples of Solutions
- Solution: JSON parser in nearley.js (opens new window)
- Task to do: Improve the solution by using your own lexical analyzer generator instead of the current moo lexer, removing the explicit use of white spaces (syntactic variable
_
like in the production rulepair -> key _ ":" _ value
) in the Nearley grammar
- Task to do: Improve the solution by using your own lexical analyzer generator instead of the current moo lexer, removing the explicit use of white spaces (syntactic variable
- Solution: JSON parser in yacc (opens new window)
- Solution: JSON parser in pegjs (opens new window)
# 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
2
Whose JSON looks like:
➜ evm2term git:(master) head -n 4 examples/property.json
{
"type": "apply",
"operator": {
"type": "property",
1
2
3
4
5
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
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
- See package evm2term (opens new window) and file crguezl/evm2term/index.js (opens new window) for a solution using
estraverse
# Programming the End of the Course
Initial plan:
- To do one more lab in which we will see the interpretation phase corresponding to the extensions introduced in the current lab Adding OOP to the Egg Parser. Estimated delivery time 12 of May.
- We will spend the last two weeks carrying out the TFA. Estimated delivery time 26th and 27th of May.
- Exams
- First exam Friday 03/06 09:00,
- Second exam Friday 10/06 09:00.
- In the regular classroom 1.3.
- Important: Review the class 2022-03-28
- Close of final assessments (Cierre de Actas): 20/06