ylyxa / Conjunctive-GLR

GLR interpreter generator for Okhotin conjunctive grammars

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Interpreter generation

Installation

  1. Clone the repository: git clone https://github.com/ylyxa/Conjunctive-GLR.git
  2. Install pygraphviz
  3. Install other packages: pip install -r requirements.txt

Using premade examples

  1. Navigate to /examples/ and then to the example's folder
  2. Run generate_and_run.sh inside the folder

Generating custom interpreters

Defining the grammar

Grammar syntax:

Grammar → ((Rule ∨ TermRule)\n)+

Rule → Nterm ::= (ConjRHS ∨ DisjRHS);Semantic

ConjRHS → (Str & Str ∨ (Str & ConjRHS));Semantic

DisjRHS → (Str ∨ (Str | DisjRHS));Semantic

Str → (Nterm ∨ Term ∨ _)+

TermRule → Regex

Semantic → FunctionName

Nterm → [A-Z][a-zA-Z0-9]*

Term → [a-z][a-zA-Z0-9]*

Here Regex means a python regular expression, FunctionName - name of a function from semantic.py

Defining semantic actions

Semantic functions are defined as Python functions that accept one argument (a list of lower-level semantic results) and return a single value (which is then passed up the graph). Note: there must be a function pass_through defined like this:

def pass_through(x):
return x[0]

Note: Semantic results are undetermined if the grammar is ambiguous or contains conjunctive rules. File must be named semantic.py

Defining reconfiguration

Must be defined as a function reconfigure in reconfigure.py. Function accepts one argument (semantic result for the graph root) and returns a string (to be used in the next step of the interpretation loop)

Running

  1. Generate the interpreter: place semantic.py and reconfigure.py in the same directory as generator.py and run generator.py grammar
  2. Run the interpreter: navigate to /generated/ generated by the program and run main.py grammar input where grammar is the generated grammar and input is the file with the input string

About

GLR interpreter generator for Okhotin conjunctive grammars

License:GNU General Public License v3.0


Languages

Language:Python 100.0%