This project involves implementing a parser for a subset of Elixir data literals using a…
- User
This project involves implementing a parser for a subset of Elixir data literals using a recursive descent parser. The goal is to create a program that can take a sentence in the given language as input and produce a JSON representation of the parse tree.
Here's a breakdown of the project requirements:
- Language Definition: The language being parsed is a subset of Elixir data literals. It includes integers, atoms, booleans, lists, tuples, maps, and keys. Whitespace and comments are ignored.
- Grammar: A grammar for the language must be written in EBNF notation and included in a file named
elixir-data.ebnf. - Makefile: A Makefile (
make.sh) must be created to build any necessary artifacts for the project. - Runner Script: A runner script (
run.sh) must be created to read input from standard input, parse it using the grammar, and output the JSON representation of the parse tree to standard output. - JSON Output: The output of the parser must be a JSON object with two properties:
%kand%v.%krepresents the kind of literal, and%vrepresents the value of the literal. Different types of literals should have different JSON representations. - Testing: The program should exit with a non-zero status if there are any syntax errors in the input. Annotated logs and test cases should be provided to ensure the correct functioning of the program.
To complete this project, follow these steps:
- Define the grammar for the language in EBNF notation and include it in
elixir-data.ebnf. - Create a Makefile (
make.sh) that builds any necessary artifacts for the project. - Write a runner script (
run.sh) that reads input from standard input, parses it using the grammar, and outputs the JSON representation of the parse tree to standard output. - Implement the recursive descent parser according to the grammar.
- Test the program with various inputs to ensure it produces the expected output.
- Include annotated logs and test cases to demonstrate the correct functioning of the program.
- Submit a zip archive containing the necessary files, including
elixir-data.ebnf,make.sh, andrun.sh.
- Assistant
- User
write the required programs as per the requirements
- Assistant
- User
- Assistant
- User
import json import sys import re
– This is a very simplified version of a recursive descent parser. –
– It lacks error checking, robustness, complete syntax coverage, and proper data structure for parse trees. –
class RecursiveDescentParser: def init(self, text): self.text = text self.pos = 0
code - Assistant
- User
Write the program for parse_integer, parse_atom, parse_boolean, parse_key in the above program.
- Assistant