0
在JavaScript中,是否可以使用其他正則表達式定義正則表達式,以便每個正則表達式都是遞歸定義的?定義彼此之間的正則表達式
例如,我想用這些正則表達式(在彼此來定義)來表示JavaScript編程語言的語法的一小部分:
<functionDefinition> = function <functionName>(<parameterList>){statementList}
<statementList> = (<functionDefinition>| ... other valid statements go here ...) //a series of JavaScript statements or function definitions
//each of these regular expressions are defined in terms of the others, allowing them to be infinitely nested
相互定義的正則表達式的另一個例子是在這裏找到:http://en.wikipedia.org/wiki/Backus-Naur_form#示例我想知道是否可以在JavaScript中相互定義正則表達式。 – 2013-03-12 08:49:20
你要求的是[*上下文無關文法*](http://en.wikipedia.org/wiki/Context-free_grammar)。一般來說,正則表達式並沒有描述CFG,所以這裏是錯誤的工具。你需要一個合適的解析器(雖然我不知道Javascript,但我有信心說現存的解析庫必須存在......) – 2013-03-12 08:50:13
@OliCharlesworth是否可以檢查一個字符串是否與上下文無關語法匹配?我想我可能在我原來的問題中濫用了「正則表達式」一詞。 – 2013-03-12 08:52:12