I need to parse a file line by line and check if the line is in a valid BNF format and print it out if it is.
Below is my BNF grammar:
<line> ::= <program names><spaces><uids><spaces><dest IPs><spaces><ports>
<spaces> ::= <blank character> | <blank character><spaces>
<blank character> ::= ' ' | '\t'
<uids> ::= '*' | <alnumstring seq>
<alnumstring seq> ::= <alnumstring> | <alnumstring>','<alnumstring seq> | <alnumstring>','<spaces><alnumstring seq>
<program names> ::= '*' | <prog name seq>
<prog name seq> ::= <progstring> | <progstring>','<prog name seq> | <progstring>','<spaces><prog name seq>
<dest IPs> ::= '*' | <IP address seq>
<IP address seq> ::= <dest IP> | <dest IP>','<spaces><IP address seq> | <dest IP>','<IP address seq>
<dest ports> ::= '*' | <dest port seq>
<dest port seq> ::= <destination port> | <destination port>','<spaces><dest port seq> | <destination port>','<dest port seq>
Example of Valid Sentences:
/usr/bin/firefox * * 80, 443, 8080
/usr/bin/ssh * 147.188.195.15, 147.188.193.15, 147.188.193.16 22
I understand the structure of the BNF grammar however i'm unsure of how to put this into C code.
Would it be possible for somebody to give me a simple example of how to do this in c e.g.
<sentences> ::= <words><Punctuation>|<words><Punctuation><sentences>|<sentences><sentences>
<words> ::= <word> | <word><space><words>
<word> ::= <characters a-z>
<space> ::= ' '
<Punctuation> ::= <,>|<.>|<;>| etc...
testsentences = "Thank you for your help, I appreciate it."
Thanks,
Techno_weenie