package lrgrep

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Kernel.InfoSource

Grammar information interface

This module exports data structures and operations for handling grammar information. It provides indexed representations of grammars with type-level cardinalities for type-safe access.

Main components:

  • The Load_grammar functor takes Menhir's grammar representation and computes all index structures for the grammar.
  • Types for grammar elements with their indices:
  • terminal, nonterminal, symbol, production, item
  • lr0, lr1: LR(0) and LR(1) states
  • goto_transition, shift_transition, transition: Transitions
  • reduction: Reductions
  • Module interfaces for each grammar element:
  • Terminal, Nonterminal, Symbol, Production, Item
  • Lr0, Lr1, Transition, Reduction

Each module provides:

  • cardinal: The size of the index set
  • of_int: Construct an index from an integer
  • Type-specific functions for accessing properties
Sourcemodule type GRAMMAR = MenhirSdk.Cmly_api.GRAMMAR
Sourcetype 'g grammar
Sourcemodule Load_grammar (G : MenhirSdk.Cmly_api.GRAMMAR) : sig ... end
Sourcetype 'g terminal
Sourcetype 'g nonterminal
Sourcetype 'g production
Sourcetype 'g item
Sourcetype 'g lr0
Sourcetype 'g lr1
Sourcetype 'g goto_transition
Sourcetype 'g shift_transition
Sourcetype 'g reduction
Sourcemodule type INDEXED = sig ... end
Sourcemodule Terminal : sig ... end
Sourcemodule Nonterminal : sig ... end
Sourcemodule Symbol : sig ... end
Sourcemodule Production : sig ... end
Sourcemodule Item : sig ... end

Explicit representation of LR(0) items. An item is a production with a dot position: A -> α . β. Items are indexed globally across all productions for efficient set operations. The dot position ranges from 0 (before all RHS symbols) to length (after all).

Sourcemodule Lr0 : sig ... end

LR(0) state information. LR(0) states represent the "core" of LR(1) states, ignoring lookahead information.

Sourcemodule Lr1 : sig ... end

LR(1) state information. LR(1) states extend LR(0) cores with lookahead information, determining when reductions should be performed.

Sourcemodule Transition : sig ... end
Sourcemodule Reduction : sig ... end

Reduction information. A reduction represents a (state, production, lookahead set) triple, meaning that in the given state, when the lookahead terminal is in the set, the parser should reduce by the given production.

Sourceval raw : _ grammar -> (module MenhirSdk.Cmly_api.GRAMMAR)