pg

package module
v0.0.0-...-ef17ad3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2020 License: BSD-3-Clause Imports: 0 Imported by: 0

README

pg CI GoDoc Go Report Card

pg - toy parser generator.

Installation

% go get github.com/davidrjenni/pg/pg

Documentation

Overview

Package pg provides packages to lex, parse and pretty-print context-free grammars. Furthermore it provides a package for generating SLR(1) parsers. The command pg implements a parser generator using these packages. Package example contains example programs which use the command pg.

A grammar is specified using BNF, which is a set of derivation rules (productions). The following grammar specifies BNF (represented itself in BNF); any input must satisfy this grammar:

Production -> "PRODUCTION_NAME" "->" Expression "." .
Expression -> Expression "|" Alternative | Alternative .
Alternative -> Alternative Terminal | Terminal .
Terminal -> "PRODUCTION_NAME" | "TOKEN" | "e" .

Production names and tokens are symbols of the grammar. The name of the first production of the grammar is the start symbol. A production name is an identifier, a token is a string. The arrow "->" is interchangeable with the UTF-8 character U+2192 "→". The symbol "e" indicates the empty symbol (epsilon). "e" is interchangeable with the UTF-8 character U+03B5 "ε".

The arrow means that the symbol on the left must be replaced with the expression on the right. An expression consists of one or more sequences of symbols. More sequences are separated by a vertical bar, indicating a choice. Multiple lines are allowed. A production is terminated by a dot. The arrow means that the symbol on the left must be replaced with the expression on the right.

Directories

Path Synopsis
Package ast declares the types used to represent syntax trees for pg.
Package ast declares the types used to represent syntax trees for pg.
example
calc
Command calc implements a calculator using pg.
Command calc implements a calculator using pg.
Package generator implements a parser generator.
Package generator implements a parser generator.
Package parser implements a parser for pg.
Package parser implements a parser for pg.
pg is tool for managing context-free grammars.
pg is tool for managing context-free grammars.
Package printer implements pretty-printing of AST nodes.
Package printer implements pretty-printing of AST nodes.
Package scanner implements a scanner for pg.
Package scanner implements a scanner for pg.
Package token defines constants representing the lexical tokens for pg.
Package token defines constants representing the lexical tokens for pg.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL