lexical analysis - Conflict while parsing a set of expressions -
i parse set of expressions: r[3]c
, r[2]c
, r[3]c-r[2]c
... there conflict cannot solve...
here part of lexer.mll
:
rule token = parse | 'r' { r } | 'c' { c } | "rc" { rc } | ['0'-'9']+ lxm { integer (int_of_string lxm) } | '+' { plus } | '-' { minus } | '[' { lbracket } | ']' { rbracket } | eof { eof } ...
a part of parser.mly
:
main: e_expression eof { $1 }; e_expression: | ec = e_cell { ee_rc (rc.cell ec) } | e_expression minus e_expression { ee_string_eel ("minus", [$1; $3]) } e_cell: | r lbracket r = index rbracket c c = index { (rc.i_relative r, rc.i_absolute c) } | r lbracket r = index rbracket c { (rc.i_relative r, rc.i_relative 0) } index: | integer { $1 } | minus integer { printf.printf "%n\n" 8; 0 - $2 }
this code curiously not work r[3]c-r[2]c
, here parser.conflicts, can not understand.
if comment line line | r lbracket r = index rbracket c c = index ...
in e_cell
, code can parse r[3]c-r[2]c
, 3
, 2
index
, `r[3]c
, r[2]c
e_cell
, , r[3]c-r[2]c
e_expression
.
could help?
so problem seems when sees "-" token after ], parser unsure whether making index, or if separating 2 expressions.
i.e. when parser reaches r[3]c-, isn't sure whether needs wait integer complete e_cell , reduce, or reduce , start work on e_expression.
the best way solve move negative integer code lexer. don't have ocamllex install handy, think changing
['0'-'9']+
to
'-'? ['0'-'9']+
would work, , remove negative integer case index (obviously cause problem printf statement, can make internal logic more complex account this.
Comments
Post a Comment