I use LPEG ( http://www.inf.puc-rio.br/~roberto/lpeg/ ) a lot for
writing grammars.  I'm not familiar with the ones you mention so I
have no idea how similar they are.  I too had a lot of trouble
debugging, so I ended up writing some tools that print out debugging
statements in a human readable form.  The ones I've found most useful
are listing out the matched tokens in order, the tokens attempted, and
a trace of the grammar rules the parser follows.  For reference, this
is a typical log of data I get (this one is for a Lua grammar):


1 1 -> block
1  2 -> chunk
1   3 -> stat
1    4 -> varlist
1     5 -> var
1      6 -> prefix
1     5 <-: prefix
1    4 <-: var
1   3 <-: varlist
1    4 -> functioncall
1     5 -> prefix
1    4 <-: prefix
1   3 <-: functioncall
2    4 -> funcname
2   3 <- funcname 3 MATCH
3    4 -> funcbody
4     5 -> parlist
4      6 -> namelist
8     5 <- namelist 9 MATCH
8    4 <- parlist 9 MATCH
10     5 -> block
10      6 -> chunk
10       7 -> stat
10        8 -> varlist
10         9 -> var
10          10 -> prefix
10         9 <- prefix 10 MATCH
11          10 -> suffix
11           11 -> call
11            12 -> args
11             13 -> tableconstructor
11            12 <-: tableconstructor
11           11 <-: args
11          10 <-: call
11           11 -> index
11          10 <-: index
11         9 <-: suffix
11          10 -> index
11         9 <-: index
10        8 <- var 11 MATCH
10       7 <- varlist 11 MATCH
10        8 -> functioncall
10         9 -> prefix
10        8 <- prefix 11 MATCH
11         9 -> suffix
11          10 -> call
11           11 -> args
11            12 -> tableconstructor
11           11 <-: tableconstructor
11          10 <-: args
11         9 <-: call
11          10 -> index
11         9 <-: index
11        8 <-: suffix
11         9 -> call
11          10 -> args
11           11 -> tableconstructor
11          10 <-: tableconstructor
11         9 <-: args
11        8 <-: call
10       7 <-: functioncall
10      6 <-: stat
10       7 -> laststat
10      6 <-: laststat
9     5 <- chunk 11 MATCH
9    4 <- block 11 MATCH
3   3 <-: funcbody
1  2 <-: stat
1   3 -> laststat
1  2 <-: laststat
0 1 <- chunk 11 MATCH
00 <- block 11 MATCH
********************************
Rule Stack:
{
  idx = 9,
  [1] = "block",
  [2] = "chunk",
  [3] = "stat",
  [4] = "funcbody",
  [5] = "block",
  [6] = "chunk",
  [7] = "stat",
  [8] = "functioncall",
  [9] = "prefix",
}
********************************
Attempted Tokens List:
{
  rules = {
    [1] = "args",
    [2] = "tableconstructor",
    [3] = "args",
    [4] = "call",
    [5] = "index",
    [6] = "index",
    [7] = "varlist",
    [8] = "stat",
  },
  tokens = {
    [1] = "LEFT_PAREN",
    [2] = "LEFT_BRACE",
    [3] = "STRING",
    [4] = "COLON",
    [5] = "LEFT_BRACKET",
    [6] = "DOT",
    [7] = "COMMA",
    [8] = "EQUALS",
  },
}

_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to