itevad – How to write your own protocol and its stack – part 6

Previous_Part_5

From this post, we will start our Flex and Bison journey. Before that, we will need a clarification for BNF and ABNF again and give ABNF description of Iitevad accordingly. As mentioned in General Background, BNF and ABNF are the guidelines to write lexer and parser for text decoding with Flex and Bison. However, there may be a gap between BNF/ABNF description and detailed implementation of lexer/parser, like what happens in Itevad. Our ultimate goal is to make our lexer/parser very close to BNF/ABNF description. Meanwhile, this ultimate goal may increase the complexity of lexer/parser, which may be not so favorable for stack writing. During the stack writing of Itevad, we will find the balance between ABNF and real lexer/parser.

/* ABNF description for Text Itevad Protocol */
[root@localhost ItevadBin]# cat itevad.abnf
;
; Itevad Protocol Text Encoding ABNF Example
; April 6, 2012
; http://daveti.blog.com
;

itevadMessage = LWSP message
message = ItevadToken SLASH Version SEP ip4Address SEP messageBody
messsageBody = (messageRequest / messageReply)
messageRequest = TransToken EQUAL TransactionID LBRKT askContent RBRKT
messageReply = ReplyToken EQUAL TransactionId LBRKT answerContent RBRKT
askContent = AskToken EQUAL quotedString
answerContent = AnswerToken EQUAL quotedString
Version = 1*2(DIGIT) ; "0".."99"
ip4Address = address [":" portNumber]
address = "[" IPv4address "]"
IPv4address = V4hex DOT V4hex DOT V4hex DOT V4hex
V4hex = 1*3(DIGIT) ; "0".."255"
TransactionId = UINT32
portNumber = UINT16

UINT16 = 1*5(DIGIT) ; %x0-FFFF
UINT32 = 1*10(DIGIT) ; %x0-FFFFFFFF
DIGIT = %x30-39 ; 0-9
DOT = "."
DQUOTE = 0x22 ; "
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
SafeChar = DIGIT / ALPHA / "+" / "-" / "&" / "!" / "_" / "/" / "'" / "?" / "@" /
 "^" / "`" / "~" / "*" / "$" / "" / "(" / ")" / "%" / "|" / "."
RestChar = ";" / "[" / "]" / "{" / "}" / ":" / "," / "#" / "<" / ">" / "="
CR = %x0D ; Carriage return
LF = %x0A ; linefeed
SP = %x20 ; space
HTAB = %x09 ; horizontal tab
COLON = ":" ; colon
WSP = SP / HTAB ; white space
COMMENT = ";" *(SafeChar / RestChar / WSP / %x22) EOL
EOL = (CR [LF] / LF)
LWSP = *(WSP / COMMENT / EOL)
SLASH = "/"
SEP = (WSP / EOL / COMMENT) LWSP
EQUAL = "="
LBRKT = LWSP "{" LWSP
RBRKT = LWSP "}" LWSP
quotedString = DQUOTE *(SafeChar / EOL / %x80-FF / RestChar / WSP) DQUOTE

ItevadToken = "Itevad"
TransToken = "Transaction"
ReplyToken = "Reply"
AskToken = "Ask"
AnswerToken = "Answer"
[root@localhost ItevadBin]#

About daveti

Interested in kernel hacking, compilers, machine learning and guitars.
This entry was posted in Dave's Tools, H.248/MEGACO/EGCP, Programming, Stuff about Compiler and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.