parsing - Debug parser by printing useful information -


i parse set of expressions, instance:x[3], x[-3], xy[-2], x[4]y[2], etc.

in parser.mly, index (which inside []) defined follows:

index: | integer { $1 } | minus integer { 0 - $2 } 

the token integer, minus etc. defined in lexer normal.

i try parse example, fails. however, if comment | minus integer { 0 - $2 }, works well. problem related that. debug, want more information, in other words want know considered minus integer. tried add print:

index: | integer { $1 } | minus integer { printf.printf "%n" $2; 0 - $2 } 

but nothing printed while parsing.

could tell me how print information or debug that?

i tried coming example of describe , able output of 8 show below. [this example stripped down works [1] , [- 1 ], believe it's equivalent logically said did.]

however, notice example's debug string in example not have explicit flush %! @ end, debugging output might not flushed terminal until later expect.

here's used:

test.mll:

{    open ytest    open lexing } rule test = parse "-" { minus } | "1" { 1 one } | "[" { lb } | "]" { rb } | [ ' ' '\t' '\r' '\n'  ] { test lexbuf }  | eof { eoftoken }  

ytest.mly:

%{ %} %token <int> 1  %token minus lb rb eoftoken %start item %type <int> index item %% index:     1 { 2 }     | minus 1 { printf.printf "%n" 8; $2 } item : lb index rb eoftoken { $2 }  

parse.ml

open test;; open ytest;; open lexing;; let lexbuf = lexing.from_channel stdin in ignore (ytest.item test.test lexbuf) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -