Generate FIRST/FOLLOW/PREDICT Set from BNF.

Generate FIRST/FOLLOW/PREDICT Set from BNF.

We can use it to study parser theory.

Feature

  • FirstSet generate. Output pretty.
  • FollowSet generate. Output pretty.
  • LL(1) Predicate Parsing Table. Output pretty.

Usage

You can use demo input to generate FirstSet/FollowSet/PredictTable

cd cmd
go run main.go
Output to the terminal default
FirstSet:
FIRST(D) = {g ε f}
FIRST(E) = {g ε}
FIRST(F) = {f ε}
FIRST(S) = {a}
FIRST(B) = {c}
FIRST(C) = {b ε}

FollowSet:
FOLLOW(F) = {h}
FOLLOW(S) = {$}
FOLLOW(B) = {g h f}
FOLLOW(C) = {g h f}
FOLLOW(D) = {h}
FOLLOW(E) = {f h}

PredictTable:
+---+----------------+------------+------------+------------+------------+------------+---+
| # | a              | b          | c          | f          | g          | h          | $ |
+---+----------------+------------+------------+------------+------------+------------+---+
| S | S -> {a B D h} |            |            |            |            |            |   |
+---+----------------+------------+------------+------------+------------+------------+---+
| B |                |            | B -> {c C} |            |            |            |   |
+---+----------------+------------+------------+------------+------------+------------+---+
| C |                | C -> {b C} |            | C -> {ε}   | C -> {ε}   | C -> {ε}   |   |
+---+----------------+------------+------------+------------+------------+------------+---+
| D |                |            |            | D -> {E F} | D -> {E F} | D -> {E F} |   |
+---+----------------+------------+------------+------------+------------+------------+---+
| E |                |            |            | E -> {ε}   | E -> {g}   | E -> {ε}   |   |
+---+----------------+------------+------------+------------+------------+------------+---+
| F |                |            |            | F -> {f}   |            | F -> {ε}   |   |
+---+----------------+------------+------------+------------+------------+------------+---+

Or use your own bnf grammar.

cd cmd
go run main.go -grammar your_own_grammar_file

Note

  1. use ε indicate EPSILON (unicode is '\u03B5')
  2. use $ indicate input right end marker.
  3. use UpperCase letter indicate Nonterminal
  4. use lowerCase letter indicate Terminal
  5. BNF format with | support alternate.
  6. use -> distinguish LHS and RHS

More demo see the cmd/demo.bnf, or testdata

Ref

Similar Resources

Automatically generate Go test boilerplate from your source code.

Automatically generate Go test boilerplate from your source code.

gotests gotests makes writing Go tests easy. It's a Golang commandline tool that generates table driven tests based on its target source files' functi

Jan 3, 2023

generate fake data in go

Faker for Go Usage package main import ( "github.com/manveru/faker" ) func main() { fake, err := faker.New("en") if err != nil { panic(err

Sep 29, 2022

:runner:runs go generate recursively on a specified path or environment variable and can filter by regex

Package generate Package generate runs go generate recursively on a specified path or environment variable like $GOPATH and can filter by regex Why wo

Sep 27, 2022

A command line tool to generate sequence diagrams

A command line tool to generate sequence diagrams

goseq - text based sequence diagrams A small command line utility used to generate UML sequence diagrams from a text-base definition file. Inspired by

Dec 22, 2022

generate my_github status using GitHub Actions

generate my_github status using GitHub Actions

generate my_github status using GitHub Actions

Sep 21, 2022

Generate spreadsheets based on GitHub contributions

pullsheet generates a CSV (comma separated values) & HTML output about GitHub activity across a series of repositories.

Oct 17, 2022

Generate type-safe Go converters by simply defining an interface

goverter a "type-safe Go converter" generator goverter is a tool for creating type-safe converters. All you have to do is create an interface and exec

Jan 4, 2023

Generate random, pronounceable, sometimes even memorable, "superhero like" codenames - just like Docker does with container names.

Codename an RFC1178 implementation to generate pronounceable, sometimes even memorable, "superheroe like" codenames, consisting of a random combinatio

Dec 11, 2022

An application that is developed to generate application by API specification

GO boilerplate is an application that is developed to generate application by API specification and Database schema with the collaboration with opn-generator.

Oct 14, 2021
Code snippets by first time open source contributors

Introduction Golang code snippets by first time open source contributors Rules How to contribute Add a folder and create your desired code snippet fil

Oct 6, 2021
Golang SSR-first Frontend Library
Golang SSR-first Frontend Library

kyoto Library that brings frontend-like components experience to the server side with native html/template on steroids. Supports any serving basis (ne

Nov 25, 2022
CapMonsterTool is a set of Go tools designed to simply make requests to the CapMonster Cloud API.

✨ CapMonsterTool ✨ About this module What is ✨ CapMonsterTool ✨ ? CapMonsterTool is a set of Go tools designed to simply make requests to the CapMonst

Dec 1, 2022
set and get github user statuses

gh user-status being an extension for interacting with the status on a GitHub profile. gh user-status set gh user-status set interactively set status

Nov 19, 2022
Set of reusable components for Golang projects

go-utils Table of contents go-utils Table of contents 1. Overview 2. Install 3. Utils package 3.1 logger 3.2 error 3.3 datetime 1. Overview In my free

Sep 12, 2022
Set of functions/methods that will ease GO code generation

Set of functions/methods that will ease GO code generation

Dec 1, 2021
Tanzu Framework provides a set of building blocks to build atop of the Tanzu platform and leverages Carvel packaging

Tanzu Framework provides a set of building blocks to build atop of the Tanzu platform and leverages Carvel packaging and plugins to provide users with a much stronger, more integrated experience than the loose coupling and stand-alone commands of the previous generation of tools.

Dec 16, 2022
API and a set of tools to manage Netbox configuration declaratively

declarative-netbox An experimental project to explore the idea of managing the N

Jan 24, 2022
Set of scripts & tools for converting between numbers and major system encoded words.
Set of scripts & tools for converting between numbers and major system encoded words.

major-system-converter Set of scripts & tools for converting between numbers and major system encoded words. Uses phonetics instead of letters to conv

Aug 9, 2022
HTTP service to generate PDF from Json requests

pdfgen HTTP service to generate PDF from Json requests Install and run The recommended method is to use the docker container by mounting your template

Dec 2, 2022