VBA 解析シリーズその2カッコ
2019年5月24日再帰版も実装しました。先読みせずに次の候補式を呼び出して成功か失敗を判断する手法ははけたさんからご回答いただきましたので先読みで作成してみました。
​​Function paren_lexar2(a_sts As String) As String
​​    '再帰版
​​    Dim token, peek, derived
​​    token = Split(get_token(a_sts, peek:=True), ",")
​​    If token(ATTR) = "(" Then
​​        derived = par_exp()
​​    Else
​​        derived = PARSE_ERROR
​​    End If
​​    paren_lexar2 = derived
​​End Function
​​Function par_exp()
​​    '括弧式
​​    Dim token, peek, derived
​​    token = Split(get_token(""), ",")
​​    If token(ATTR) = "(" Then
​​        peek = Split(get_token("", peek:=True), ",")
​​        Select Case True
​​            Case peek(CLASS) = "ALF"
​​                derived = alf_exp()
​​            Case peek(CLASS) = "NUM"
​​                derived = num_exp()
​​            Case peek(ATTR) Like "("
​​                derived = par_exp()
​​            Case peek(ATTR) Like ")"
​​                derived = ""
​​            Case Else
​​                derived = PARSE_ERROR
​​        End Select
​​    Else
​​        derived = PARSE_ERROR
​​    End If
​​    par_exp = derived
​​End Function
​​Function alf_exp()
​​    'アルファベット式
​​    Dim token, peek, derived
​​    token = Split(get_token(""), ",")
​​    If token(CLASS) = "ALF" Then
​​        peek = Split(get_token("", peek:=True), ",")
​​        If peek(ATTR) = "(" Then
​​            derived = token(ATTR) & par_exp()
​​        ElseIf peek(ATTR) = ")" Then
​​            derived = token(ATTR)
​​        Else
​​            derived = PARSE_ERROR
​​        End If