Does Pyparsing support context sensitive grammars?

Forgive me if I have the wrong terminology; perhaps just getting the “right” words to describe what I want is enough to find the answer on my own.

I'm working on a parser for ODL (Object Description Language), a secret language that, as far as I can tell, is now only used by NASA PDS (Planetary Data Systems, how NASA makes its data publicly available). Fortunately, PDS will finally move in XML, but I still need to write mission software that crashed just before the shutdown.

ODL defines objects as follows:

OBJECT              = TABLE
  ROWS              = 128
  ROW_BYTES         = 512 
END_OBJECT          = TABLE

I am trying to write a parser with pyparsing, and I did everything right until I came to the above construction.

I need to create some rule that can guarantee that the right value of the OBJECT string is identical to RHV END_OBJECT. But I can’t imagine that this is the rule pyparsing. I can guarantee that both are syntactically valid values, but I cannot perform the extra step and make sure the values ​​are identical.

  • Am I correct in my intuition that this is a context-sensitive grammar? Is this a phrase I should use to describe this problem?
  • Whatever grammar is in the theoretical sense, can it pyparsingcope with such a construction?
  • If you pyparsingcan't handle it, is there another Python tool capable of doing this? How about ply(Python lex/ implementation yacc)?
+5
2

- , wcw, w (a | b) * ( , wcw', ' , ).

wcw-, . PyParsing matchPreviousExpr() matchPreviousLiteral() , .

w = Word("ab")
s = w + "c" + matchPreviousExpr(w)

, , , -

table_name = Word(alphas, alphanums)
object = Literal("OBJECT") + "=" + table_name + ... +
  Literal("END_OBJECT") + "=" +matchPreviousExpr(table_name)
+6

, - . , (, , ).

- :

  head = 'OBJECT' '=' IDENTIFIER ;
  tail = 'END_OBJECT'  '=' IDENTIFIER ;
  element = IDENTIFIER '=' value ;
  element_list = element ;
  element_list = element_list element ;
  block = head element_list tail ;

, head tail , .

, , . . , IDENTIFIER - ; , IDENTIFIER , , . * IDENTIFIER * , * IDENTIFIER *.

, , , - (, IDENTIFIER node ). , node , , .

, , , . : -} , , , -, , .

python, PyParsing .

+3

All Articles