8000 GitHub - batuhanoktem/CFGParser: Context Free Grammar (CFG) Parser
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

batuhanoktem/CFGParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Context Free Grammar (CFG) Parser

Given a grammar (in grammar.txt file) and a list of words (in words.txt file), the program will decide whether the given words are in the language defined by the grammar.

Donate

  • Bitcoin: 1FHFU14DRWWHaJyq8fK1coKR57KqQJg2ZH

Input

A sample grammar.txt file is given below. First line states the terminals (alphabet) of the language. Second line gives the Non-terminals of the grammar. Note that first non-terminal is the start symbol. After these initial two lines, rules of the grammars are given (one rule on each line). Each line starts with the ID of the rule (an integer). Every term in the grammar file is separated by a single space character. For simplicity, all the terminals and non-terminals are just a single character.

) ( + 0 1 *
S E
1 S -> ( E )
2 S -> E + E
3 S -> E * E
4 E -> S
5 E -> 0
6 E -> 1

The words.txt file will contain words (one word on each line). An example words.txt file is given below.

(0+1)+1
(1+11)
0*(1)

Output

For each word in the words.txt file, if the word cannot be generated by the grammar, it will only print NO. If the word is in the language, it will print YES in the first line and on the next line it will print the rules which are applied to generate the word with a left-most derivation. The results are printed to results.txt file. For the grammar and words file given in the previous section, the results.txt file will be as follows:

YES
2 4 1 4 2 5 6 6
NO
YES
3 5 4 1 6

About

Context Free Grammar (CFG) Parser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0