Idea of ​​parsing parsing diagram

Folks I am implementing a strange thing, I have to write a utility for parsing a syntax diagram in text format and convert it to xml format, the thing is basically identical to this article from IBM (for example, in the "Creating a task without conversion" part): http: / /publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqls.doc/sqls17.htm A typical parser / lexer like ANTLR / yacc / bison doesn't seem to be able to handle such things, one idea is to convert the parser chart to a bitmap of a character and define some functions like more_up, move_down, left, right or so to cross the entire diagram to simulate the process of understanding as a person with the naked eye. This does not sound professional enough; I did not understand another better approach. Has anyone ever played with a similar scenario? Perhaps you could shed some light on this.

Thank you in advance!

+5
source share
2 answers

" " ; , . .

, , , . (duh), , .

, , , , (. ) , (, +). , , node. (:-)) , , .

, , ( ). Node , Node.

, node, , .

, ; (, , ).

. .

+1

, .

-, - :

class CharGrid(object):
    def __init__(self, text):
        self.lines = text.split('\n')

    def __getitem__(self, pos):
        try:
            col, row = pos
        except (TypeError, ValueError):
            raise KeyError('%r not a 2-tuple' % (pos,))
        if row >= len(self.lines):
            return ' '
        line = self.lines[row]
        if col >= len(line):
            return ' '
        return line[col]

2D-:

grid = CharGrid("""Creating a No-Conversion Job

>>-onpladm create job--job--+--------------+-- -n--------------->
                            '- -p--project-'

>-- -d--device-- -D--database-- -t--table----------------------->

   .---------------------------------------------------------------------.
   V                                                                     |
>----+-----------------------------------------------------------------+-+-><
     |                                                            (1)  |
     '-+-------------+--+-------------+--| Setting the Run Mode |------'
       '- -S--server-'  '- -T--target-'
""")

print ''.join((grid[0,0], grid[1,0], grid[2,0]))
print ''.join((grid[0,2], grid[1,2]))

()

Cre
>>

2D- 1D- :

  • , >>
  • , []

... .. .

1D- , .

+2

All Articles