Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context Free Grammar (CFG) Parser in Go

Tags:

parsing

go

nlp

I am looking for a Go library providing CFG parsing (preferably not in Chomsky Normal Form). Has anybody heard of anything, or should I write it ? :)

like image 905
Blacksad Avatar asked Aug 23 '12 18:08

Blacksad


People also ask

Is Golang grammar context-free?

Most programming language grammars are not context-free. That means the parser has to maintain state in order to process a snippet of the language. Often when discussing context somebody will point out the parsing strings, parentheses and so on also require a kind of state in order to match their terminators.

What is parsing in context-free grammar?

These are rules that, when applied, can generate all possible legal phrases in the language. Parsing Expression Grammar (PEG) — describes a CFG in terms of recognition rules. These are rules that can be used to match valid phrases in the language.

What is context-free in CFG?

A context free grammar (CFG) is a forma grammar which is used to generate all the possible patterns of strings in a given formal language.

Why CFG is used in parsing?

A CFG only defines a language. It does not say how to determine whether a given string belongs to the language it defines. To do this, a parser can be used whose task is to map a string of words to its parse tree. The parse tree of course remains the same.


1 Answers

Do you know about goyacc?. Although it's not a library, but a code generator. Anyway it supports CFGs and it's IMO a pretty standard way to handle such tasks. (?)

like image 53
zzzz Avatar answered Oct 19 '22 03:10

zzzz