BNFã¨ãæ£è¦è¡¨ç¾ã®è©±ãã
ãããã ãªBNFã¨æ£è¦è¡¨ç¾
BNFï¼ããã«ã¹ï¼ãã¦ã¢è¨æ³ï¼ã¯ãããã°ã©ãã³ã°è¨èªã®æ§æè¨è¿°ã«ãã使ãããã¡ã¿æ§æã§ãããã¨ãã¨ã¯ãã?ãï¼çç¥å¯è½ï¼ãã*ãï¼ä»»æåã®ç¹°ãè¿ãï¼ã®ãããªè¨å·ã¯ä½¿ããªãã£ãããã§ããç¾å¨ã®æ£è¦è¡¨ç¾ã§æ¨æºçã«ä½¿ãããã?ãã*ãã+ãã¯ããªãã¦ã次ã®ããã«å®ç¾©å¯è½ãªã®ã§ããï¼ä»¥ä¸ã§ãEMPTYã¯ããã«ä½ããªããã¨ã§ããã»ãã¨ã«ä½ãç¡ãã¨åããã«ããã®ã§ç®å°ã«EMPTYã使ãã¾ããï¼
// X 㯠A? X ::= EMPTY | A // Y 㯠A* Y ::= EMPTY | A Y // Z 㯠A+ Z ::= A | A Z
ã|ããããã°ã?ãã*ãã+ããå®ç¾©ã§ãã¾ããããã®ä»£ããã«å帰çãªå®ç¾©ã«ãªãã¾ãã
ã::=ãã®å·¦ã«åãè¨å·ãè¤æ°åç»å ´ããã®ã許ãã¨ãã|ããããä¸è¦ã«ãªãã¾ãã
// X 㯠A? X ::= EMPTY X ::= A // Y 㯠A* Y ::= EMPTY Y ::= A Y // Z 㯠A+ Z ::= A Z ::= A Z
ãããã ãªè¨æ³ãæ¬å®¶BNFã¨ããã¨ãã¯ãã?ãã*ãã+ããªã©ã使ãæµåã¯EBNF(æ¡å¼µBNF)ã¨å¼ã¶ãã¨ãããã¾ãããã£ã¨ããç¾å¨ã§ã¯EBNFã使ããã¨ãå¤ãã§ãããããããã¡ãã¡ Eï¼Extendedï¼ãä»ããå¿ è¦ã¯ãªãã¨æãã¾ãã
å¤æ ãªBNF -- ABNF
A? ã®ä»£ããã« [A]ãA+ ã®ä»£ããã« A ... ã®ãããªä»£æ¿è¨æ³ããã¾ã«è¦ããã¾ããããã¯åãããããã¦ããããããªãã§ããããã
RFCãèªãã§ã¿ãã¨ããªããå¤ãªBNFã使ããã¦ãããã¨ã«æ°ãã¤ãã§ããããããã¯ãABNFï¼Augmented BNFï¼ã§ããRFC以å¤ã§ä½¿ããã¦ããä¾ãåã¯ç¥ããªãã®ã§ãããRFCã§ã¯ããã使ãã®ãæ £ä¾ã¿ããã§ãã
ABNFèªä½ãRFCã«ãªã£ã¦ã㦠http://www.ietf.org/rfc/rfc2234.txt "Augmented BNF for Syntax Specifications: ABNF" ã§å®ç¾©ããã¦ãã¾ããæ®éã®BFNããããã¯æ£è¦è¡¨ç¾ã¨æ¯ã¹ã¦ã¿ãã¨ã次ã®è¡¨ã®ããã«ã¾ãã¾ãã
ï¼¼ | é常ã®BNF | ABNF |
---|---|---|
å®ç¾© | X ::= ... | X = ... |
é¸æ | A | B | A / B |
ãªãã·ã§ã³ | A? | *1A |
ç¹°ãè¿ã | A* | *A |
1å以ä¸ç¹°ãè¿ã | A+ | 1*A |
ABNFã§ã¯ãç¹°ãè¿ãã®æå° * ã¯åã«ä»ãã¾ããn*m ã¨ããå½¢ã使ãã¦ããnå以ä¸ãmå以ä¸ã®ç¹°ãè¿ããã®æå³ã«ãªãã¾ããnã®ããã©ã«ãã0, mã®ããã©ã«ããç¡éãªã®ã§ã* ã ãã§ãä»»æåã®ç¹°ãè¿ããã«ãªãã¾ããPerlã®æ£è¦è¡¨ç¾ã¨æ¯ã¹ã¦ã¿ãã¨ï¼
Perlã®æ£è¦è¡¨ç¾ | ABNF |
---|---|
A{2,5} | 2*5A |
A{2,} | 2*A |
A{3} | 3A |
ABNFã¯ããªãã§ããããæ®éï¼å¤æ°æ´¾ï¼ã¨éã表ç¾ã使ããã§ããããï¼
ããã¨ãæããããã¨ã«ã¯ã"ABNF strings are case-insensitive"ï¼ABNFã®æååã¯ã大æåå°æåãåºå¥ãã¾ããï¼ã¨ã®ãã¨ã
name = "ab"
ãã®å®ç¾©ã¯ãnameã«"ab"ã½ãã¢ããå²ãå½ã¦ããã¨ã«ã¯ãªãã¾ãããæ®éã®æ¸ãæ¹ã§è¡¨ç¾ãããªãï¼
name ::= "ab" | "Ab" | "aB" | "AB"
ã¤ã³ã¿ã¼ãããã«ããã¦ä½¿ãããæååå®æ°ï¼ä¾ãã°ãããã¬ãã«ãã¡ã¤ã³åï¼ã¯å¤§æåå°æåãåºå¥ããªããã¨ãå¤ãã®ã§ãããããä»æ§ãªãã§ãããããã ãã¶éåæããã¾ããã
"ab"ã½ãã¢ããå®ç¾©ããããªã次ã®ããã«æ¸ãã¾ãã
name = %d97 %d98
%d97 %d98 ã®ä»£ããã«ã%d97.98 ã§ãOKã§ãããããã¯ã%x61 %x62ã%x61.62 ã使ãã¾ããæåçªå·ã®å é ã«ã¯ã%ããä»ãã¾ããç¯å²ã表ãã«ã¯ %x30-39 ã使ãã¾ããXMLä»æ§ãªã©ãè¦æ £ããåã«ã¯ã#x61 #x62ã[#x61-#x65] ã®ã»ãããã£ã¨ã·ãã¯ãªãã¾ãã
ãã·ãã¯ãªãã¯å人çãªæè¦ã§ãããããã«ãã¦ãABNFã¯ãããããå¤ãªæ§æãªã®ã§ããã使ãã®ãããã°ããã®ã«ã