Tag. parsing

Notes (20)

Definition. Representable Grammars representable-grammar

For any string 𝑀, we can define a representable grammar βŒˆπ‘€βŒ‰ which matches exactly the string 𝑀 and nothing else. The parse trees for a representable grammar are proofs that the string is exactly equal to 𝑀:

βŒˆπ‘€βŒ‰(𝑒)=(𝑒≑𝑀)

Cloudflare Parsing Error cloudflare-parsing-error

An error in the Cloudflare HTML parser would allow uninitialized memory to be dumped when there were imbalanced HTML tags.

This is indeed a case where a verified parser would have alleviated the issue.

Definition. First Set first-set

The first set (π–₯π—‚π—‹π—Œπ—(β‹…)) of a grammar 𝐴 are all the characters that may appear at the beginning of a word in the language of 𝐴.

π–₯π—‚π—‹π—Œπ—(𝐴)={𝑐|βˆƒπ‘€.π‘π‘€βˆˆπΏ(𝐴)}

Definition. First Sets in Dependent Lambek Calculus first-set-in-dependent-lambek

The first set of a grammar 𝐴 may be captured in Lambek𝙳 via the following proposition:

π‘βˆ‰π–₯π—‚π—‹π—Œπ—(𝐴)≔𝐴&('𝑐'βŠ—βŠ€)⊒βŠ₯

Or perhaps with ones of the grammars

𝐴⇒¬('𝑐'βŠ—βŠ€),'𝑐'βŠ—βŠ€β‡’Β¬π΄

Definition. FollowLast Set followlast-set

The followlast set (π–₯π–«π–Ίπ—Œπ—(β‹…)) of a grammar 𝐴 are all the characters that may follow a word in the language of 𝐴 in a string that is in the language of 𝐴.

π–₯π–«π–Ίπ—Œπ—(𝐴)={𝑐|βˆƒπ‘€,𝑀𝐴.π‘€π΄βˆˆπΏ(𝐴)βˆ§π‘€π΄π‘π‘€βˆˆπΏ(𝐴)}

Definition. FollowLast Sets in Dependent Lambek Calculus followlast-set-in-dependent-lambek

The followlast set of a grammar 𝐴 may be captured in Lambek𝙳 via the following proposition:

π‘βˆ‰π–₯π–«π–Ίπ—Œπ—(𝐴)≔𝐴&(π΄βŠ—'𝑐'βŠ—βŠ€)⊒βŠ₯

Or perhaps with ones of the grammars

𝐴⇒¬(π΄βŠ—'𝑐'βŠ—βŠ€),π΄βŠ—'𝑐'βŠ—βŠ€β‡’Β¬π΄

Definition. LL(1) Condition ll1-condition

A context-free grammar satisfies the LL(1) condition if it satisfies the following three conditions:

  • All of its productions have pairwise disjoint first sets
  • If a concatenation of nonterminals π΄βŠ—π΅ appears in a production, then 𝐴 has a disjoint followlast set from the first set of 𝐡
  • At most one production is nullable

This is essentially the type system of [1], which characterizes the LL(1) condition for context-free expressions.

Intutively, an LL(1) grammar can be parsed unambiguously, and without backtracking, by a predictive parser that only needs one token of lookahead.

Definition. Nullability in Dependent Lambek Calculus nullability-in-dependent-lambek

The nullability (π–­π—Žπ—…π—…(β‹…)) of a grammar 𝐴 may be captured in Lambek𝙳 via the following proposition:

Β¬π–­π—Žπ—…π—…(𝐴)≔𝐴&πœ–βŠ’βŠ₯

Or perhaps with one of the grammars

π΄β‡’Β¬πœ€,πœ€β‡’Β¬π΄

Definition. Nullable Grammar nullable-grammar

A grammar 𝐴 is nullable if the empty string belongs to the language of 𝐴.

Definition. Sequential Unambiguity sequential-unambiguity

Grammars 𝐴 and 𝐡 are sequentially unambiguous if the followlast set of 𝐴 is disjoint from the first set of 𝐡.

π–₯π–«π–Ίπ—Œπ—(𝐴)∩π–₯π—‚π—‹π—Œπ—(𝐡)=βˆ…

We can understand this intuitively by characterizing the behavior of a left-to-right parser of π΄βŠ—π΅. First it searches for a parse of 𝐴, then upon finding a character that is not in π–₯π–«π–Ίπ—Œπ—(𝐴) it may begin trying search for 𝐡.

That is, there is a unique boundary between the 𝐴-parse and the 𝐡-parse.

Definition. The Quotient and its Right Adjoint in Day Convolution day-quotient

Let 𝐢 be a small monoidal category. Recall that for presheaves 𝐴,𝐡:𝐢opβ†’π’πžπ­, the Day convolution provides a closed monoidal structure:

(π΄βŠ—π΅)(𝑐)=βˆ«π‘’,𝑣𝐢[𝑐,π‘’βŠ—π‘£]×𝐴(𝑒)×𝐡(𝑣)
(𝐴⊸𝐡)(𝑐)=βˆ«π‘’π΄(𝑒)→𝐡(π‘’βŠ—π‘)

which forms an adjunction π΄βŠ—βˆ’βŠ£π΄βŠΈβˆ’.

For covariant functors 𝐴:πΆβ†’π’πžπ­ and presheaves 𝐡:𝐢opβ†’π’πžπ­, we can define the quotient and its right adjoint, each of which is a presheaf on 𝐢:

(𝐷𝐴𝐡)(𝑐)=βˆ«π‘’π΄(𝑒)×𝐡(π‘’βŠ—π‘)
(𝐡𝐴)(𝑐)=βˆ«π‘’,𝑣𝐢[π‘’βŠ—π‘£,𝑐]β†’(𝐴(𝑒)→𝐡(𝑣))

These form the adjunction π·π΄βŠ£βˆ’π΄.

Definition. Dependent Tensor of Grammars dependent-tensor

The tensor of grammars,

(π΄βŠ—π΅)(𝑀)=βˆ‘π‘€=𝑒𝑣𝐴(𝑒)×𝐡(𝑣)

is simply typed, so 𝐡 cannot see what 𝐴 matched.

Just as we have the generalization from the pair type 𝐴×𝐡 to the dependent pair Ξ£π‘Ž:π΄π΅π‘Ž, we can define a dependent tensor operation. It is a Ξ£-like generalization over the ordinary tensor, in which the second grammar depends on a parse tree of the first.

Write 𝖳𝗋𝖾𝖾(𝐴)=βˆ‘π‘€π΄(𝑀) for the type of parse trees of 𝐴, each paired with the string it parses.

For a grammar 𝐴 and a family of grammars 𝐡:𝖳𝗋𝖾𝖾(𝐴)→𝐆𝐫, the dependent tensor is:

(π΄βŠ—π–£π΅)(𝑀)=βˆ‘π‘€=π‘’π‘£βˆ‘π‘Ž:𝐴(𝑒)𝐡(𝑒,π‘Ž)(𝑣)

We may also write it as (π‘Žβˆˆπ΄)βŠ—π΅(π‘Ž).

When 𝐡 is a constant family, the dependent tensor reduces to the ordinary tensor π΄βŠ—π΅.

Dependence runs left to right here, which fits left-to-right parsing. The other handedness, in which the first grammar depends on a parse of the second, is also definable.

Relation to Day Convolution

Just as the ordinary tensor is given by Day convolution, I think there is a similar dependent Day convolution for which this operation is an instance. My best guess is for any 𝑋 presheaf on a monoidal category π’žοΈ€ and π‘Œ a functor from the category of elements of 𝑋 into presheaves on π’žοΈ€,

(π‘‹βŠ—π–£π‘Œ)𝑐=βˆ«π‘’,π‘£π’žοΈ€[𝑐,π‘’βŠ—π‘£]Γ—βˆ«π‘₯:π‘‹π‘’π‘Œ(𝑒,π‘₯)𝑣

I’m not positive on this though, and I would hope to also extend this to enrichments that aren’t π’πžπ­ but I don’t see how that could make sense given that I have quantified over the element π‘₯:𝑋𝑒 in the coend rather than using the tensor of the enriching category.

Definition. Formal Grammar formal-grammar

For an alphabet Ξ£, let Ξ£βˆ— be the free monoid of strings over Ξ£. A formal grammar 𝐴 is a family of types indexed by strings:

𝐴:Ξ£βˆ—β†’π–³π—’π—‰π–Ύ

This definition views formal grammars directly as indexed families of types over strings (which equivalently form presheaves on the discrete category of strings). This view forms the central notion of the Dependent Lambek Calculus. For a given string 𝑀, the type 𝐴(𝑀) represents the type of all valid parse trees for 𝑀 according to the grammar 𝐴. If the grammar cannot parse 𝑀, then 𝐴(𝑀) is the empty type.

Definition. The Derivative of a Grammar grammar-derivative

When a grammar quotient 𝐷𝐴𝐡 is taken with respect to a representable grammar 𝐴=βŒˆπ‘€βŒ‰ (matching exactly the string 𝑀), it coincides with the residual 𝐴⊸𝐡, as established by the Quotient and Residual Coincidence.

This special case is known as the Brzozowski derivative of 𝐡 by the string 𝑀, often written as πœ•π‘€π΅. We have the following coincidence:

(βŒˆπ‘€βŒ‰βŠΈπ΅)(𝑣)≅𝐡(𝑀·𝑣)β‰…(π·βŒˆπ‘€βŒ‰π΅)(𝑣)

Definition. Later on Grammars grammar-later

Write π‘’βŠπ‘£ when 𝑒 is a proper suffix of 𝑣, that is, 𝑣=π‘₯++𝑒 with π‘₯β‰ πœ€. The later of a grammar 𝐴 is

(▷𝐴)𝑣=βˆπ‘’βŠπ‘£π΄π‘’.

A parse of ▷𝐴 over 𝑣 is a parse of 𝐴 over every proper suffix of 𝑣. In particular (▷𝐴)πœ€ is a singleton.

This is later on families for strings under the proper-suffix order. That order is well-founded because it strictly decreases length, so it is a thin direct category. There is at most one map 𝑒→𝑣, so the product over maps from the strict past has one factor per proper suffix. Guarded recursion is modelled by presheaves on πœ”, the topos of trees, and more generally by sheaves over a well-founded base [1]. Here the later acts on families, which is what grammars are, and there is no clock.

Later is the right adjoint of the proper-suffix derivative. Let 𝖭𝖀𝖲=⨁π‘₯β‰ πœ€βŒˆπ‘₯βŒ‰ be the grammar of non-empty strings. Then the derivative (πœ•π–­π–€π–²π΅)π‘’β‰…βˆ‘π‘₯β‰ πœ€π΅(π‘₯++𝑒) has the right adjoint

πΆπ–­π–€π–²π‘£β‰…βˆπ‘₯++𝑒=𝑣𝖭𝖀𝖲π‘₯→𝐢𝑒≅(▷𝐢)𝑣,

so πœ•π–­π–€π–²βˆ’βŠ£β–·. Splitting 𝖭𝖀𝖲 into its summands gives the form of β–· that the calculus can define:

▷𝐴≅&π‘€β‰ πœ€π΄βŒˆπ‘€βŒ‰,π΄βŒˆπ‘€βŒ‰β‰…(βŒˆπ‘€βŒ‰βŠ—βŠ€)β‡’(βŒˆπ‘€βŒ‰βŠ—π΄).

The component at 𝑀 says: if the string begins with 𝑀, then the rest parses as 𝐴.

The restriction to non-empty 𝑀 is what makes this a later. At 𝑀=πœ€ the component is π΄βŒˆπœ€βŒ‰β‰…π΄. Including it would give a projection β–·π΄βŠ’π΄, and LΓΆb would then prove every grammar. For the same reason the later is a product over suffixes. A sum such as β¨π‘βŒˆπ‘βŒ‰βŠΈπ΄ is empty at πœ€, and at 𝐴=βŠ₯ it is βŠ₯. The identity step βŠ₯⊒βŠ₯ would then give LΓΆb a proof of ⊀⊒βŠ₯.

In the Agda this is β–· in Grammar/Later/Base.agda, which is defined as the indexed conjunction of √l-string. The mirror image β–·r, over proper prefixes, is defined in the same way. See also the bilateral later and the later along an arbitrary well-founded order.

Theorem. LΓΆb Induction for Grammars grammar-lob

For every grammar 𝐴 and every term πœ‘:β–·π΄βŠ’π΄, where β–· is the later on grammars, there is a unique global parse π—…ΓΆπ–»πœ‘:⊀⊒𝐴 with

π—…ΓΆπ–»πœ‘=πœ‘βˆ˜π—‡π–Ύπ—‘π—(π—…ΓΆπ–»πœ‘).

Here 𝗇𝖾𝗑𝗍𝑑:βŠ€βŠ’β–·π΄ restricts a global parse 𝑑 to every proper suffix.

The proof is recursion on the length of the string. At 𝑣, the parses already built at the proper suffixes of 𝑣 form an element of (▷𝐴)𝑣, and πœ‘ turns it into a parse at 𝑣. Uniqueness is LΓΆb for families over the proper-suffix order. In the Agda, lob in Grammar/Later/Base.agda is this recursion, done by well-founded induction on length.

To prove an entailment 𝐡⊒𝐢 this way, apply LΓΆb to 𝐴=𝐡⇒𝐢. The hypothesis β–·(𝐡⇒𝐢) is the induction hypothesis at every proper suffix. It becomes usable once a non-nullable grammar has been consumed. If πœ€&𝐡⊒βŠ₯, then

(π΅βŠ—βŠ€)&β–·π΄βŠ’π΅βŠ—π΄

because a parse of π΅βŠ—βŠ€ over 𝑣 splits 𝑣=π‘₯++𝑒 with π‘₯ non-empty, so π‘’βŠπ‘£. This is β–·-app-NE in Grammar/Later/Properties.agda. Induction on a Kleene star is the standard use.

Theorem. Next on Grammars Is Presheaf Structure grammar-next-presheaf

For presheaves, 𝗇𝖾𝗑𝗍:𝑃→▷𝑃 restricts along the strict past, as in later on presheaves. A grammar is only a family over strings, so a map 𝗇𝖾𝗑𝗍:π΄βŠ’β–·π΄ into the later on grammars is extra data. It sends a parse over 𝑣 to parses over every proper suffix of 𝑣.

Let ░𝐴=𝐴&▷𝐴, so that (░𝐴)π‘£β‰…βˆπ‘’βŠ‘π‘£π΄π‘’. This is the comonad π‘ˆβˆ˜Cofree for the suffix order, and presheaves are comonadic over families. The counit law forces the first component of a coalgebra π΄βŠ’β–‘π΄ to be the identity. Hence:

  • a presheaf on strings under the suffix order is the same as a grammar 𝐴 with a map 𝗇𝖾𝗑𝗍:π΄βŠ’β–·π΄ that satisfies coassociativity. Restricting to 𝑒′ and then to π‘’βŠπ‘’β€² must agree with restricting to 𝑒 directly;
  • for a proposition-valued grammar (a language), coassociativity is automatic, and 𝗇𝖾𝗑𝗍 exists exactly when the language is closed under suffixes. For example, ⊀ has one, but βŒˆπ‘ŽβŒ‰ does not, since (β–·βŒˆπ‘ŽβŒ‰)π‘Žβ‰…βŒˆπ‘ŽβŒ‰πœ€ is empty.

LΓΆb does not need 𝗇𝖾𝗑𝗍 on 𝐴. The fixed-point equation only restricts a global parse ⊀⊒𝐴, and a global parse can always be restricted. In the Agda, the grammar-level IsCoalgebra record, with only the field next, is in Grammar/Later/Coalgebra.agda on the guarded branch.

On presheaves the strict downset of 𝑐++𝑑 is represented by 𝑑, because every proper suffix of 𝑐++𝑑 is a suffix of 𝑑. So predecessors simplify later to (▷𝑃)(𝑐++𝑑)≅𝑃𝑑. On grammars there is no such simplification, since the factors at different suffixes are unrelated.

Definition. Grammar Quotients grammar-quotients

For formal grammars 𝐴 and 𝐡, the quotient of 𝐡 by 𝐴 is the grammar of what is left of 𝐡 once an 𝐴 has been read off the front:

(𝐷𝐴𝐡)(𝑣)=Σ𝑒𝐴(𝑒)×𝐡(𝑒·𝑣)

A parse of the quotient consists of an 𝐴-parses at prefix 𝑒 and a 𝐡-parse of the full string 𝑒·𝑣.

This operation has a right adjoint:

(𝐢𝐴)(𝑀)=Π𝑒,𝑣(𝑒·𝑣=𝑀)→𝐴(𝑒)→𝐢(𝑣)

Intuitively, 𝐢𝐴 parses 𝑀 if: for all splittings of 𝑀 into a prefix and suffix, if the prefix matches 𝐴 then the suffix must match 𝐢.

Together, these form the adjunction:

𝐷𝐴𝐡⊒𝐢⟺𝐡⊒𝐢𝐴

This is an instance of the Day quotient over the discrete monoidal category of strings.

Definition. Grammar Residuals grammar-residual

For formal grammars 𝐴 and 𝐡, the residual 𝐴⊸𝐡 (sometimes called the lollipop or linear implication) is the right adjoint to the grammar tensor π΄βŠ—π΅. It describes strings that, when prefixed by a string matching 𝐴, will match 𝐡.

Formally, it is defined as:

(𝐴⊸𝐡)(𝑣)=Π𝑒𝐴(𝑒)→𝐡(𝑒·𝑣)

Intuitively, a parse of 𝐴⊸𝐡 at a string 𝑣 is a function that takes any prefix string 𝑒 and a parse of 𝑒 in 𝐴, and produces a parse of the full concatenated string 𝑒·𝑣 in 𝐡.

Definition. Tensor of Grammars grammar-tensor

For formal grammars 𝐴 and 𝐡, their tensor π΄βŠ—π΅ represents the concatenation of the languages they describe. A parse for π΄βŠ—π΅ at a string 𝑀 consists of a splitting of 𝑀 into a prefix 𝑒 and suffix 𝑣, along with a parse of 𝑒 in 𝐴 and a parse of 𝑣 in 𝐡.

Formally, it is defined as:

(π΄βŠ—π΅)(𝑀)=βˆ‘π‘€=𝑒𝑣𝐴(𝑒)×𝐡(𝑣)

This operation is exactly the Day convolution of 𝐴 and 𝐡, where we view formal grammars as presheaves over the monoid of strings.

Talks and videos (2)

Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus pldi-2025-talk

We present Dependent Lambek Calculus, a domain-specific dependent type theory for verified parsing and formal grammar theory. In Dependent Lambek Calculus, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.

We present a denotational semantics of our type theory that interprets the types as a mathematical notion of formal grammars. Based on this denotational semantics, we have made a prototype implementation of Dependent Lambek Calculus using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.

Event Β· Slides Β· Video

Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus mwpls-2024-talk

We present Dependent Lambek Calculus, a domain-specific dependent type theory for verified parsing and formal grammar theory. In Dependent Lambek Calculus, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.

We present a denotational semantics of our type theory that interprets the types as a mathematical notion of formal grammars. Based on this denotational semantics, we have made a prototype implementation of Dependent Lambek Calculus using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.

Event Β· Slides

References (56)

Syntactic Completions with Material Obligations moon-2025-syntactic

Code editors provide essential services that help developers understand, navigate, and modify programs. However, these services often fail in the presence of syntax errors. Existing syntax error recovery techniques, like panic mode and multi-option repairs, are either too coarse, e.g. in deleting large swathes of code, or lead to a proliferation of possible completions. This paper introduces tall tylr , an error-handling parser and editor generator that completes malformed code with syntactic obligations that abstract over many possible completions. These obligations generalize the familiar notion of holes in structure editors to cover missing operands, operators, delimiters, and sort transitions. tall tylr is backed by a novel theory of tile-based parsing, conceptually organized around a molder that turns tokens into tiles and a melder that completes and parses tiles into terms using an error-handling generalization of operator-precedence parsing. We formalize melding as a parsing calculus, meldr, that completes input tiles with additional obligations such that it can be parsed into a well-formed term, with success guaranteed over all inputs. We further describe how tall tylr implements molding and completionranking using the principle of minimizing obligations . Obligations offer a useful way to scaffold internal program representations, but in tall tylr we go further to investigate the potential of materializing these obligations visually to the programmer. We conduct a user study to evaluate the extent to which an editor like tall tylr that materializes syntactic obligations might be usable and useful, finding both points of positivity and interesting new avenues for future work.
PDF Β· DOI Β· arXiv Β· pldb

Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus intrinsic-verification-of-parsers

We present Dependent Lambek Calculus (Lambek𝙳), a domain-specific dependent type theory for verified parsing and formal grammar theory. In Lambek𝙳, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.

We present a denotational semantics of our type theory that interprets the linear types as functions from strings to sets of abstract parse trees and terms as parse transformers. Based on this denotational semantics, we have made a prototype implementation of Lambek𝙳 using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.

PDF Β· DOI Β· arXiv (extended version) Β· Source code Β· pldb

The categorical contours of the Chomsky-SchΓΌtzenberger representation theorem mellies-2025-the

We develop fibrational perspectives on context-free grammars and on nondeterministic finite-state automata over categories and operads. A generalized CFG is a functor from a free colored operad (aka multicategory) generated by a pointed finite species into an arbitrary base operad: this encompasses classical CFGs by taking the base to be a certain operad constructed from a free monoid, as an instance of a more general construction of an operad of spliced arrows π’²οΈ€π’žοΈ€ for any category π’žοΈ€. A generalized NFA is a functor from an arbitrary bipointed category or pointed operad satisfying the unique lifting of factorizations and finite fiber properties: this encompasses classical word automata and tree automata without πœ–-transitions, but also automata over non-free categories and operads. We show that generalized context-free and regular languages satisfy suitable generalizations of many of the usual closure properties, and in particular we give a simple conceptual proof that context-free languages are closed under intersection with regular languages. Finally, we observe that the splicing functor 𝒲︀:Catβ†’Oper admits a left adjoint π’žοΈ€:Operβ†’Cat, which we call the contour category construction since the arrows of π’žοΈ€π’ͺοΈ€ have a geometric interpretation as oriented contours of operations of π’ͺοΈ€. A direct consequence of the contour / splicing adjunction is that every pointed finite species induces a universal CFG generating a language of tree contour words. This leads us to a generalization of the Chomsky-SchΓΌtzenberger Representation Theorem, establishing that a subset of a homset πΏβŠ†π’žοΈ€(𝐴,𝐡) is a CFL of arrows if and only if it is a functorial image of the intersection of a π’žοΈ€-chromatic tree contour language with a regular language.
DOI Β· arXiv

ACGtk: A toolkit for developing and running abstract categorial grammars Guillaume2024

Abstract categorial grammars (ACGs) is an expressive grammatical framework whose formal properties have been extensively studied. While it can provide its own account, as a grammar, of linguistic phenomena, it is known to encode several grammatical formalisms, including context-free grammars, but also mildly context-sensitive formalisms such as tree-adjoining grammars or m-linear context-free rewriting systems for which parsing is polynomial. The ACG toolkit we present provides a compiler, acgc, that checks and turns ACGs into representations that are suitable for testing and parsing, used in the acg interpreter. We illustrate these functionalities and discuss implementation features, in particular the Datalog reduction on which parsing is based, and the magic set rewriting techniques that can further be applied.
DOI

Curbing the Vulnerable Parser: Graded Modal Guardrails for Secure Input Handling bond-2023-curbing

DOI

Saggitarius: A DSL for Specifying Grammatical Domains miltner-2023-saggitarius

Common data types like dates, addresses, phone numbers and tables can have multiple textual representations, and many heavily-used languages, such as SQL, come in several dialects. These variations can cause data to be misinterpreted, leading to silent data corruption, failure of data processing systems, or even security vulnerabilities. Saggitarius is a new language and system designed to help programmers reason about the format of data, by describing grammatical domainsβ€”that is, sets of context-free grammars that describe the many possible representations of a datatype. We describe the design of Saggitarius via example and provide a relational semantics. We show how Saggitarius may be used to analyze a data set: given example data, it uses an algorithm based on semi-ring parsing and MaxSAT to infer which grammar in a given domain best matches that data. We evaluate the effectiveness of the algorithm on a benchmark suite of 110 example problems, and we demonstrate that our system typically returns a satisfying grammar within a few seconds with only a small number of examples. We also delve deeper into a more extensive case study on using Saggitarius for CSV dialect detection. Despite being general-purpose, we find that Saggitarius offers comparable results to hand-tuned, specialized tools; in the case of CSV, it infers grammars for 84% of benchmarks within 60 seconds, and has comparable accuracy to custom-built dialect detection tools.
PDF Β· DOI Β· arXiv Β· pldb

Coqlex: Generating formally verified lexers Ouedraogo_2023

A compiler consists of a sequence of phases going from lexical analysis to code generation. Ideally, the formal verification of a compiler should include the formal verification of each component of the tool-chain. An example is the CompCert project, a formally verified C compiler, that comes with associated tools and proofs that allow to formally verify most of those components.

However, some components, in particular the lexer, remain unverified. In fact, the lexer of Compcert is generated using OCamllex, a lex-like OCaml lexer generator that produces lexers from a set of regular expressions with associated semantic actions. Even though there exist various approaches, like CakeML or Verbatim++, to write verified lexers, they all have only limited practical applicability.

In order to contribute to the end-to-end verification of compilers, we implemented a generator of verified lexers whose usage is similar to OCamllex. Our software, called Coqlex, reads a lexer specification and generates a lexer equipped with a Coq proof of its correctness. It provides a formally verified implementation of most features of standard, unverified lexer generators.

The conclusions of our work are two-fold: Firstly, verified lexers gain to follow a user experience similar to lex/flex or OCamllex, with a domain-specific syntax to write lexers comfortably. This introduces a small gap between the written artifact and the verified lexer, but our design minimizes this gap and makes it practical to review the generated lexer. The user remains able to prove further properties of their lexer. Secondly, it is possible to combine simplicity and decent performance. Our implementation approach that uses Brzozowski derivatives is noticeably simpler than the previous work in Verbatim++ that tries to generate a deterministic finite automaton (DFA) ahead of time, and it is also noticeably faster thanks to careful design choices.

We wrote several example lexers that suggest that the convenience of using Coqlex is close to that of standard verified generators, in particular, OCamllex. We used Coqlex in an industrial project to implement a verified lexer of Ada. This lexer is part of a tool to optimize safety-critical programs, some of which are very large. This experience confirmed that Coqlex is usable in practice, and in particular that its performance is good enough. Finally, we performed detailed performance comparisons between Coqlex, OCamllex, and Verbatim++. Verbatim++ is the state-of-the-art tool for verified lexers in Coq, and the performance of its lexer was carefully optimized in previous work by Egolf and al. (2022). Our results suggest that Coqlex is two orders of magnitude slower than OCamllex, but two orders of magnitude faster than Verbatim++.

Verified compilers and other language-processing tools are becoming important tools for safety-critical or security-critical applications. They provide trust and replace more costly approaches to certification, such as manually reading the generated code. Verified lexers are a missing piece in several Coq-based verified compilers today. Coqlex comes with safety guarantees, and thus shows that it is possible to build formally verified front-ends.

DOI

flap: A Deterministic Parser with Fused Lexing yallop-2023-flap

Lexers and parsers are typically defined separately and connected by a token stream. This separate definition is important for modularity and reduces the potential for parsing ambiguity. However, materializing tokens as data structures and case-switching on tokens comes with a cost. We show how to fuse separately-defined lexers and parsers, drastically improving performance without compromising modularity or increasing ambiguity. We propose a deterministic variant of Greibach Normal Form that ensures deterministic parsing with a single token of lookahead and makes fusion strikingly simple, and prove that normalizing context free expressions into the deterministic normal form is semantics-preserving. Our staged parser combinator library, flap, provides a standard interface, but generates specialized token-free code that runs two to six times faster than ocamlyacc on a range of benchmarks.
PDF Β· DOI Β· arXiv Β· pldb

Interval Parsing Grammars for File Format Parsing zhangIntervalParsingGrammars2023

File formats specify how data is encoded for persistent storage. They cannot be formalized as context-free grammars since their specifications include context-sensitive patterns such as the random access pattern and the type-length-value pattern. We propose a new grammar mechanism called Interval Parsing Grammars IPGs) for file format specifications. An IPG attaches to every nonterminal/terminal an interval, which specifies the range of input the nonterminal/terminal consumes. By connecting intervals and attributes, the context-sensitive patterns in file formats can be well handled. In this paper, we formalize IPGs’ syntax as well as its semantics, and its semantics naturally leads to a parser generator that generates a recursive-descent parser from an IPG. In general, IPGs are declarative, modular, and enable termination checking. We have used IPGs to specify a number of file formats including ZIP, ELF, GIF, PE, and part of PDF; we have also evaluated the performance of the generated parsers.
PDF Β· DOI Β· pldb

Verified ALL(*) Parsing with Semantic Actions and Dynamic Input Validation lasserCoStar2023

Follow up to CoStar.

DOI

Verbatim++: verified, optimized, and semantically rich lexing with derivatives egolf-2022-verbatim

PDF Β· DOI Β· pldb

Parsing as a lifting problem and the Chomsky-SchΓΌtzenberger representation theorem mellis_zeilberger_2022

We begin by explaining how any context-free grammar encodes a functor of operads from a freely generated operad into a certain β€œoperad of spliced words”. This motivates a more general notion of CFG over any category 𝐢, defined as a finite species 𝑆 equipped with a color denoting the start symbol and a functor of operads 𝑝:πΉπ‘Ÿπ‘’π‘’[𝑆]β†’π‘Š[𝐢] into the operad of spliced arrows in 𝐢. We show that many standard properties of CFGs can be formulated within this framework, and that usual closure properties of CF languages generalize to CF languages of arrows. We also discuss a dual fibrational perspective on the functor 𝑝 via the notion of β€œdisplayed” operad, corresponding to a lax functor of operads π‘Š[𝐢]β†’π‘†π‘π‘Žπ‘›(𝑆𝑒𝑑).

We then turn to the Chomsky-SchΓΌtzenberger Representation Theorem. We describe how a non-deterministic finite state automaton can be seen as a category 𝑄 equipped with a pair of objects denoting initial and accepting states and a functor of categories 𝑄→𝐢 satisfying the unique lifting of factorizations property and the finite fiber property. Then, we explain how to extend this notion of automaton to functors of operads, which generalize tree automata, allowing us to lift an automaton over a category to an automaton over its operad of spliced arrows. We show that every CFG over a category can be pulled back along a ND finite state automaton over the same category, and hence that CF languages are closed under intersection with regular languages. The last important ingredient is the identification of a left adjoint 𝐢[βˆ’]:π‘‚π‘π‘’π‘Ÿπ‘Žπ‘‘β†’πΆπ‘Žπ‘‘ to the operad of spliced arrows functor, building the β€œcontour category” of an operad. Using this, we generalize the C-S representation theorem, proving that any context-free language of arrows over a category 𝐢 is the functorial image of the intersection of a 𝐢-chromatic tree contour language and a regular language.

DOI Β· arXiv

Technical Report: Match-reference regular expressions and lenses musca-2022-technical

A lens is a single program that specifies two data transformations at once: one transformation converts data from source format to target format and a second transformation inverts the process. Over the past decade, researchers have developed many different kinds of lenses with different properties. One class of such languages operate over regular languages. In other words, these lenses convert strings drawn from one regular language to strings drawn from another regular language (and back again). In this paper, we define a more powerful language of lenses, which we call match-reference lenses, that is capable of translating between non-regular formats that contain repeated substrings, which is a primitive form of dependency. To define the non-regular formats themselves, we develop a new language, match-reference regular expressions, which are regular expressions that can bind variables to substrings and use those substrings repeatedly. These match-reference regular expressions are closely related to the familiar β€œback-referencesβ€œ that can be found in traditional regular expression packages, but are redesigned to adhere to conventional programming language lexical scoping conventions and to interact smoothly with lens language infrastructure. We define the semantics of match-reference regular expressions and match-reference lenses. We also define a new kind of automaton, the match-reference regex automaton system (MRRAS), for deciding string membership in the language match-reference regular expressions. We illustrate our definitions with a variety of examples.
DOI Β· arXiv

Symbolic and automatic differentiation of languages elliottSymbolicAutomaticDifferentiation2021

Formal languages are usually defined in terms of set theory. Choosing type theory instead gives us languages as type-level predicates over strings. Applying a language to a string yields a type whose elements are language membership proofs describing how a string parses in the language. The usual building blocks of languages (including union, concatenation, and Kleene closure) have precise and compelling specifications uncomplicated by operational strategies and are easily generalized to a few general domain-transforming and codomain-transforming operations on predicates. A simple characterization of languages (and indeed functions from lists to any type) captures the essential idea behind language ``differentiationβ€™β€˜ as used for recognizing languages, leading to a collection of lemmas about type-level predicates. These lemmas are the heart of two dual parsing implementationsβ€”using (inductive) regular expressions and (coinductive) triesβ€”each containing the same code but in dual arrangements (with representation and primitive operations trading places). The regular expression version corresponds to symbolic differentiation, while the trie version corresponds to automatic differentiation. The relatively easy-to-prove properties of type-level languages transfer almost effortlessly to the decidable implementations. In particular, despite the inductive and coinductive nature of regular expressions and tries respectively, we need neither inductive nor coinductive/bisimulation arguments to prove algebraic properties.
PDF Β· DOI Β· pldb

CoStar: A verified ALL(*) parser lasserCoStarVerifiedALL2021

Parsers are security-critical components of many software systems, and verified parsing therefore has a key role to play in secure software design. However, existing verified parsers for context-free grammars are limited in their expressiveness, termination properties, or performance characteristics. They are only compatible with a restricted class of grammars, they are not guaranteed to terminate on all inputs, or they are not designed to be performant on grammars for real-world programming languages and data formats. In this work, we present CoStar, a verified parser that addresses these limitations. The parser is implemented with the Coq Proof Assistant and is based on the ALL(*) parsing algorithm. CoStar is sound and complete for all non-left-recursive grammars; it produces a correct parse tree for its input whenever such a tree exists, and it correctly detects ambiguous inputs. CoStar also provides strong termination guarantees; it terminates without error on all inputs when applied to a non-left-recursive grammar. Finally, CoStar achieves linear-time performance on a range of unambiguous grammars for commonly used languages and data formats.
PDF Β· DOI Β· pldb

Verbatim: A verified lexer generator egolfVerbatim

Lexers and parsers are often used as front ends to connect input from the outside world with the internals of a larger software system. These front ends are natural targets for attackers who wish to compromise the larger system. A formally verified tool that performs mechanized lexical analysis would render attacks on these front ends less effective. In this paper we present Verbatim, an executable lexer that is implemented and verified with the Coq Proof Assistant. We prove that Verbatim is correct with respect to a standard lexer specification. We also analyze its theoretical complexity and give results of an empirical performance evaluation. All correctness proofs have been mechanized in Coq.
DOI

Zippy LL(1) parsing with derivatives EdelmannZippy2020

In this paper, we present an efficient, functional, and formally verified parsing algorithm for LL(1) context-free expressions based on the concept of derivatives of formal languages. Parsing with derivatives is an elegant parsing technique, which, in the general case, suffers from cubic worst-case time complexity and slow performance in practice. We specialise the parsing with derivatives algorithm to LL(1) context-free expressions, where alternatives can be chosen given a single token of lookahead. We formalise the notion of LL(1) expressions and show how to efficiently check the LL(1) property. Next, we present a novel linear-time parsing with derivatives algorithm for LL(1) expressions operating on a zipper-inspired data structure. We prove the algorithm correct in Coq and present an implementation as a part of Scallion, a parser combinators framework in Scala with enumeration and pretty printing capabilities.
DOI Β· pldb

A typed, algebraic approach to parsing krishnaswami_typed_2019

In this paper, we recall the definition of the context-free expressions (or Β΅-regular expressions), an algebraic presentation of the context-free languages. Then, we define a core type system for the context-free expressions which gives a compositional criterion for identifying those context-free expressions which can be parsed unambiguously by predictive algorithms in the style of recursive descent or LL(1). Next, we show how these typed grammar expressions can be used to derive a parser combinator library which both guarantees linear-time parsing with no backtracking and single-token lookahead, and which respects the natural denotational semantics of context-free expressions. Finally, we show how to exploit the type information to write a staged version of this library, which produces dramatic increases in performance, even outperforming code generated by the standard parser generator tool ocamlyacc.
DOI Β· pldb

Self-certifying Railroad Diagrams: Or: How to Teach Nondeterministic Finite Automata hinze-2019-self

DOI

A Verified LL(1) Parser Generator lasserLL1_2019

An LL(1) parser is a recursive descent algorithm that uses a single token of lookahead to build a grammatical derivation for an input sequence. We present an LL(1) parser generator that, when applied to grammar G, produces an LL(1) parser for G if such a parser exists. We use the Coq Proof Assistant to verify that the generator and the parsers that it produces are sound and complete, and that they terminate on all inputs without using fuel parameters. As a case study, we extract the tool’s source code and use it to generate a JSON parser. The generated parser runs in linear time; it is two to four times slower than an unverified parser for the same grammar.

Predecessor to CoStar and CoStar++.

DOI

Reasonably programmable literal notation omar-2018-reasonably

General-purpose programming languages typically define literal notation for only a small number of common data structures, like lists. This is unsatisfying because there are many other data structures for which literal notation might be useful, e.g. finite maps, regular expressions, HTML elements, SQL queries, syntax trees for various languages and chemical structures. There may also be different implementations of each of these data structures behind a common interface that could all benefit from common literal notation. This paper introduces typed literal macros (TLMs) , which allow library providers to define new literal notation of nearly arbitrary design at any specified type or parameterized family of types. Compared to existing approaches, TLMs are uniquely reasonable . TLM clients can reason abstractly, i.e. without examining grammars or generated expansions, about types and binding. The system only needs to convey to clients, via secondary notation, the inferred segmentation of each literal body, which gives the locations and types of spliced subterms. TLM providers can reason modularly about syntactic ambiguity and expansion correctness according to clear criteria. This paper incorporates TLMs into Reason, an emerging alternative front-end for OCaml, and demonstrates, through several non-trivial case studies, how TLMs integrate with the advanced features of OCaml, including pattern matching and the module system. We also discuss optional integration with MetaOCaml, which allows TLM providers to be more confident about type correctness. Finally, we establish these abstract reasoning principles formally with a detailed type-theoretic account of expression and pattern TLMs for β€œcore ML”.
PDF Β· DOI Β· pldb

agdarsec β€” total parser combinators allais_2018

Web

Certified Normalization of Context-Free Grammars firsovCertifiedNormalizationContextFree2015

Every context-free grammar can be transformed into an equivalent one in the Chomsky normal form by a sequence of four transformations. In this work on formalization of language theory, we prove formally in the Agda dependently typed programming language that each of these transformations is correct in the sense of making progress toward normality and preserving the language of the given grammar. Also, we show that the right sequence of these transformations leads to a grammar in the Chomsky normal form (since each next transformation preserves the normality properties established by the previous ones) that accepts the same language as the given grammar. As we work in a constructive setting, soundness and completeness proofs are functions converting between parse trees in the normalized and original grammars.
PDF Β· DOI Β· pldb

Adaptive LL(*) parsing: the power of dynamic analysis parr-2014-adaptive

PDF Β· DOI Β· pldb

Algebra-coalgebra duality in brzozowski’s minimization algorithm bonchi-2014-algebra

We give a new presentation of Brzozowski’s algorithm to minimize finite automata using elementary facts from universal algebra and coalgebra and building on earlier work by Arbib and Manes on a categorical presentation of Kalman duality between reachability and observability. This leads to a simple proof of its correctness and opens the door to further generalizations. Notably, we derive algorithms to obtain minimal language equivalent automata from Moore nondeterministic and weighted automata.
DOI

Safely Composable Type-Specific Languages omar-2014-safely

DOI Β· pldb

Infinitary Axiomatization of the Equational Theory of Context-Free Languages grathwohl_infinitary_2013

We give a natural complete infinitary axiomatization of the equational theory of the context-free languages, answering a question of Lei\\textbackslashss\ (1992).
DOI

The semantics of parsing with semantic actions atkey_2012

The recovery of structure from flat sequences of input data is a problem that almost all programs need to solve. Computer Science has developed a wide array of declarative languages for describing the structure of languages, usually based on the context-free grammar formalism, and there exist parser generators that produce efficient parsers for these descriptions. However, when faced with a problem involving parsing, most programmers opt for ad-hoc hand-coded solutions, or use parser combinator libraries to construct parsing functions. This paper develops a hybrid approach, treating grammars as collections of active right-hand sides, indexed by a set of non-terminals. Active right-hand sides are built using the standard monadic parser combinators and allow the consumed input to affect the language being parsed, thus allowing for the precise description of the realistic languages that arise in programming. We carefully investigate the semantics of grammars with active right-hand sides, not just from the point of view of language acceptance but also in terms of the generation of parse results. Ambiguous grammars may generate exponentially, or even infinitely, many parse results and these must be efficiently represented using Shared Packed Parse Forests (SPPFs). A particular feature of our approach is the use of Reynolds-style parametricity to ensure that the language that grammars describe cannot be affected by the representation of parse results.
Web

Brzozowski’s Algorithm (Co)Algebraically bonchi-2012-brzozowski

DOI

Validating LR(1) Parsers jourdanValidatingLRParsers2012

An LR(1) parser is a finite-state automaton, equipped with a stack, which uses a combination of its current state and one lookahead symbol in order to determine which action to perform next. We present a validator which, when applied to a context-free grammar G and an automaton A, checks that A and G agree. Validating the parser provides the correctness guarantees required by verified compilers and other high-assurance software that involves parsing. The validation process is independent of which technique was used to construct A. The validator is implemented and proved correct using the Coq proof assistant. As an application, we build a formally-verified parser for the C99 language.
PDF Β· DOI Β· pldb

Parsing with derivatives: A functional pearl mightParsingDerivativesFunctional2011

We present a functional approach to parsing unrestricted context-free grammars based on Brzozowski’s derivative of regular expressions. If we consider context-free grammars as recursive regular expressions, Brzozowski’s equational theory extends without modification to context-free grammars (and it generalizes to parser combinators). The supporting actors in this story are three concepts familiar to functional programmers - laziness, memoization and fixed points; these allow Brzozowski’s original equations to be transliterated into purely functional code in about 30 lines spread over three functions.

Yet, this almost impossibly brief implementation has a drawback: its performance is sour - in both theory and practice. The culprit? Each derivative can double the size of a grammar, and with it, the cost of the next derivative.

Fortunately, much of the new structure inflicted by the derivative is either dead on arrival, or it dies after the very next derivative. To eliminate it, we once again exploit laziness and memoization to transliterate an equational theory that prunes such debris into working code. Thanks to this compaction, parsing times become reasonable in practice.

We equip the functional programmer with two equational theories that, when combined, make for an abbreviated understanding and implementation of a system for parsing context-free languages.

PDF Β· DOI Β· pldb

LL(*): the foundation of the ANTLR parser generator parr-2011-ll

PDF Β· DOI Β· pldb

Regular expression containment: Coinductive axiomatization and computational interpretation henglein_regular_2011

We present a new sound and complete axiomatization of regular expression containment. It consists of the conventional axiomatization of concatenation, alternation, empty set and (the singleton set containing) the empty string as an idempotent semiring, the fixed- point rule E* = 1 + E Γ— E* for Kleene-star, and a general coinduction rule as the only additional rule. Our axiomatization gives rise to a natural computational interpretation of regular expressions as simple types that represent parse trees, and of containment proofs as coercions. This gives the axiom- atization a Curry-Howard-style constructive interpretation: Containment proofs do not only certify a language-theoretic contain- ment, but, under our computational interpretation, constructively transform a membership proof of a string in one regular expression into a membership proof of the same string in another regular expression. We show how to encode regular expression equivalence proofs in Salomaa’s, Kozen’s and Grabmayer’s axiomatizations into our containment system, which equips their axiomatizations with a computational interpretation and implies completeness of our axiomatization. To ensure its soundness, we require that the computational interpretation of the coinduction rule be a hereditarily total function. Hereditary totality can be considered the mother of syn- tactic side conditions: it β€œexplains” their soundness, yet cannot be used as a conventional side condition in its own right since it turns out to be undecidable. We discuss application of regular expressions as types to bit coding of strings and hint at other applications to the wide-spread use of regular expressions for substring matching, where classical automata-theoretic techniques are a priori inapplicable. Neither regular expressions as types nor subtyping interpreted coercively are novel per se. Somewhat surprisingly, this seems to be the first investigation of a general proof-theoretic framework for the latter in the context of the former, however.
PDF Β· DOI Β· pldb

Grammatical framework: Programming with multilingual grammars ranta-2011

Grammatical Framework is a programming language designed for writing grammars, which has the capability of addressing several languages in parallel. This thorough introduction demonstrates how to write grammars in Grammatical Framework and use them in applications such as tourist phrasebooks, spoken dialogue systems, and natural language interfaces. The examples and exercises presented here address several languages, and the readers are shown how to look at their own languages from the computational perspective.
Web

Context-Free Languages, Coalgebraically winterCFL

We give a coalgebraic account of context-free languages using the functor D(X) = 2 Γ— XA for deterministic automata over an alphabet A, in three different but equivalent ways: (i) by viewing context-free grammars as D-coalgebras; (ii) by defining a format for behavioural differential equations (w.r.t. D) for which the unique solutions are precisely the context-free languages; and (iii) as the D-coalgebra of generalized regular expressions in which the Kleene star is replaced by a unique fixed point operator. In all cases, semantics is defined by the unique homomorphism into the final coalgebra of all languages, paving the way for coinductive proofs of context-free language equivalence. Furthermore, the three characterizations can serve as the basis for the definition of a general coalgebraic notion of context-freeness, which we see as the ultimate long-term goal of the present study.
DOI

Total parser combinators danielssonTotalParserCombinators2010

A monadic parser combinator library which guarantees termination of parsing, while still allowing many forms of left recursion, is described. The library’s interface is similar to those of many other parser combinator libraries, with two important differences: one is that the interface clearly specifies which parts of the constructed parsers may be infinite, and which parts have to be finite, using dependent types and a combination of induction and coinduction; and the other is that the parser type is unusually informative.

The library comes with a formal semantics, using which it is proved that the parser combinators are as expressive as possible. The implementation is supported by a machine-checked correctness proof.

PDF Β· DOI Β· pldb

Regular-expression derivatives re-examined owensRegularexpressionDerivativesReexamined2009

Abstract Regular-expression derivatives are an old, but elegant, technique for compiling regular expressions to deterministic finite-state machines. It easily supports extending the regular-expression operators with boolean operations, such as intersection and complement. Unfortunately, this technique has been lost in the sands of time and few computer scientists are aware of it. In this paper, we reexamine regular-expression derivatives and report on our experiences in the context of two different functional-language implementations. The basic implementation is simple and we show how to extend it to handle large character sets (e.g., Unicode). We also show that the derivatives approach leads to smaller state machines than the traditional algorithm given by McNaughton and Yamada.
PDF Β· DOI Β· pldb

From dirt to shovels: fully automatic tool generation from ad hoc data fisher-2008-from

PDF Β· DOI Β· pldb

The next 700 data description languages fisher-2006-the

PDF Β· DOI Β· pldb

PADS: a domain-specific language for processing ad hoc data fisher-2005-pads

PDF Β· DOI Β· pldb

Greedy regular expression matching frischCardelli

This paper studies the problem of matching sequences against regular expressions in order to produce structured values.
DOI

A formal proof of strong equivalence for a grammar conversion from LTAG to HPSG-style yoshinaga2002formal

This paper presents a sketch of a formal proof of strong equivalence, where both grammars generate equivalent parse results, between any LTAG (Lexicalized Tree Adjoining Grammar: Schabes, Abeille and Joshi (1988)) G and an HPSG (Head-Driven Phrase Structure Grammar: Pollard and Sag (1994))-style grammar converted from G by a grammar conversion (Yoshinaga and Miyao, 2001). Our proof theoretically justifies some applications of the grammar conversion that exploit the nature of strong equivalence (Yoshinaga et al., 2001b; Yoshinaga et al., 2001a), applications which contribute much to the developments of the two formalisms
Web

Logics for context-free languages lautemann_logics_1995

We define matchings, and show that they capture the essence of context-freeness. More precisely, we show that the class of context-free languages coincides with the class of those sets of strings which can be defined by sentences of the form βˆƒ bΟ•, where Ο• is first order, b is a binary predicate symbol, and the range of the second order quantifier is restricted to the class of matchings. Several variations and extensions are discussed.
DOI

Deterministic regular languages bruggemannkleinwood

The ISO standard for Standard Generalized Markup Language (SGML) provides a syntactic meta-language for the definition of textual markup systems. In the standard the right hand sides of productions are called content models and they are based on regular expressions. The allowable regular expressions are those that are β€œunambiguous” as defined by the standard. Unfortunately, the standard’s use of the term β€œunambiguous” does not correspond to the two well known notions, since not all regular languages are denoted by β€œunambiguous” expressions. Furthermore, the standard’s definition of β€œunambiguous” is somewhat vague. Therefore, we provide a precise definition of β€œunambiguous expressions” and rename them deterministic regular expressions to avoid any confusion. A regular expression E is deterministic if the canonical πœ€-free finite automaton 𝑀𝐸 recognizing L(E) is deterministic. A regular language is deterministic if there is a deterministic expression that denotes it. We give a Kleene-like theorem for deterministic regular languages and we characterize them in terms of the structural properties of the minimal deterministic automata recognizing them. The latter result enables us to decide if a given regular expression denotes a deterministic regular language and, if so, to construct an equivalent deterministic expression.
DOI

Towards Kleene Algebra with recursion leis_towards_1992

We extend Kozen’s theory KA of Kleene Algebra to axiomatize parts of the equational theory of context-free languages, using a least fixed-point operator ΞΌ instead of Kleene’s iteration operator*.
DOI

Definable operations in general algebras, and the theory of automata and flowcharts BekiΔ‡1984

We study the class of operations definable from the given operations of an algebra of sets by union, composition, and fixed points; we obtain two theorems on definable operations that give us as special case the regular-equals-recognisable theorem of generalised finite automata theory. Definable operations arise also as the operations computable by charts; by translating into predicate logic, we obtain Manna’s formulas for termination and correctness of flowcharts.
DOI

Yacc: Yet another compiler-compiler Johnsonyacc

Computer program input generally has some structure; in fact, every computer program that does input can be thought of as defining an β€œinput language” which it accepts. An input language may be as complex as a programming language, or as simple as a sequence of numbers. Unfortunately, usual input facilities are limited, difficult to use, and often are lax about checking their inputs for validity. Yacc provides a general tool for describing the input to a computer program. The Yacc user specifies the structures of his input, together with code to be invoked as each such structure is recognized. Yacc turns such a specification into a subroutine that handles the input process; frequently, it is convenient and appropriate to have most of the flow of control in the user’s application handled by this subroutine. The input subroutine produced by Yacc calls a user-supplied routine to return the next basic input item. Thus, the user can specify his input in terms of individual input characters, or in terms of higher level constructs such as names and numbers. The user-supplied routine may also handle idiomatic features such as comment and continuation conventions, which typically defy easy grammatical specification. Yacc is written in portable C. The class of specifications accepted is a very general one: LALR(1) grammars with disambiguating rules. In addition to compilers for C, APL, Pascal, RATFOR, etc., Yacc has also been used for less conventional languages, including a phototypesetter language, several desk calculator languages, a document retrieval system, and a Fortran debugging system.
Web

Properties of deterministic top-down grammars rosenkrantz_properties_1970

The class of context-free grammars that can be deterministically parsed in a top down manner with a fixed amount of look-ahead is investigated. These grammars, called LL(k) grammars where k is the amount of look-ahead are defined and a procedure is given for determining if a context-free grammar is LL(k) for a given value of k. A procedure is given for eliminating the Ξ΅-rules from an LL(k) grammar at the cost of increasing k by 1. There exist cases in which this increase is inevitable. A procedure is given for obtaining a deterministic push-down machine to recognize a given LL(k) grammar and it is shown that the equivalence problem is decidable for LL(k) grammars. Additional properties are also given.
DOI

An efficient context-free parsing algorithm Earley1970

A parsing algorithm which seems to be the most efficient general context-free algorithm known is described. It is similar to both Knuth’s LR(k) algorithm and the familiar top-down algorithm. It has a time bound proportional to n3 (where n is the length of the string being parsed) in general; it has an n2 bound for unambiguous grammars; and it runs in linear time on a large class of grammars, which seems to include most practical context-free programming language grammars. In an empirical comparison it appears to be superior to the top-down and bottom-up algorithms studied by Griffiths and Petrick.
DOI

Indexed grammarsβ€”an extension of context-free grammars AhoIndexed

A new type of grammar for generating formal languages, called an indexed grammar, is presented. An indexed grammar is an extension of a context-free grammar, and the class of languages generated by indexed grammars has closure properties and decidability results similar to those for context-free languages. The class of languages generated by indexed grammars properly includes all context-free languages and is a proper subset of the class of context-sensitive languages. Several subclasses of indexed grammars generate interesting classes of languages.
DOI

Programming Techniques: Regular expression search algorithm thompsonProgrammingTechniquesRegular1968

A method for locating specific character strings embedded in character text is described and an implementation of this method in the form of a compiler is discussed. The compiler accepts a regular expression as source language and produces an IBM 7094 program as object language. The object program then accepts the text to be searched as input and produces a signal every time an embedded string in the text matches the given regular expression. Examples, problems, and solutions are also presented.
DOI

On the translation of languages from left to right KNUTH1965607

There has been much recent interest in languages whose grammar is sufficiently simple that an efficient left-to-right parsing algorithm can be mechanically produced from the grammar. In this paper, we define LR(k) grammars, which are perhaps the most general ones of this type, and they provide the basis for understanding all of the special tricks which have been used in the construction of parsing algorithms for languages with simple structure, e.g. algebraic languages. We give algorithms for deciding if a given grammar satisfies the LR(k) condition, for given k, and also give methods for generating recognizes for LR(k) grammars. It is shown that the problem of whether or not a grammar is LR(k) for some k is undecidable, and the paper concludes by establishing various connections between LR(k) grammars and deterministic languages. In particular, the LR(k) condition is a natural analogue, for grammars, of the deterministic condition, for languages.
DOI

Derivatives of Regular Expressions brzozowskiDerivativesRegularExpressions1964

Kleene’s regular expressions, which can be used for describing sequential circuits, were defined using three operators (union, concatenation and iterate) on sets of sequences. Word descriptions of problems can be more easily put in the regular expression language if the language is enriched by the inclusion of other logical operations. However, in the problem of converting the regular expression description to a state diagram, the existing methods either cannot handle expressions with additional operators, or are made quite complicated by the presence of such operators.In this paper the notion of a derivative of a regular expression is introduced and the properties of derivatives are discussed. This leads, in a very natural way, to the construction of a state diagram from a regular expression containing any number of logical operators.
DOI

Formal properties of grammars chom1963

Web

Finite Automata and Their Decision Problems rabinFiniteAutomataTheir1959

Finite automata are considered in this paper as instruments for classifying finite tapes. Each onetape automaton defines a set of tapes, a two-tape automaton defines a set of pairs of tapes, et cetera. The structure of the defined sets is studied. Various generalizations of the notion of an automaton are introduced and their relation to the classical automata is determined. Some decision problems concerning automata are shown to be solvable by effective algorithms; others turn out to be unsolvable by algorithms.
DOI

Three models for the description of language chomThreeModels1956

We investigate several conceptions of linguistic structure to determine whether or not they can provide simple and β€œrevealing” grammars that generate all of the sentences of English and only these. We find that no finite-state Markov process that produces symbols with transition from state to state can serve as an English grammar. Furthermore, the particular subclass of such processes that produce n-order statistical approximations to English do not come closer, with increasing n, to matching the output of an English grammar. We formalize the notions of β€œphrase structure” and show that this gives us a method for describing language which is essentially more powerful, though still representable as a rather elementary type of finite-state process. Nevertheless, it is successful only when limited to a small subset of simple sentences. We study the formal properties of a set of grammatical transformations that carry sentences with phrase structure into new sentences with derived phrase structure, showing that transformational grammars are processes of the same elementary type as phrase-structure grammars; that the grammar of English is materially simplified if phrase structure description is limited to a kernel of simple sentences from which all other sentences are constructed by repeated transformations; and that this view of linguistic structure gives a certain insight into the use and understanding of language.
DOI
tag-parsing tag