
Hi, I'm new to the Python source and I have a (hopefully) quick question that someone more familiar with it should be able to answer so I can continue on my way to understanding how Python is put together. I have started looking at the parser and have gotten a little confused about how the grammar is instantiated (perhaps the wrong term). Here's how I understand things at the moment. graminit.c contains the definition of the grammar in terms of static structures. Everything seems simple enough until I get to the DFA (in graminit.c): static dfa dfas[84] = { {256, "single_input", 0, 3, states_0, "\004\050\014\000\000\000\000\025\074\005\023\310\011\020\004\000\300\020\222\006\201"}, ... I assume that the last bit of my snippet (\004\050\014\ ...) is a bitset structure. When I look at bitset it is defined as a char array. Can someone explain how this works please? I've never come across escape sequences like this; I've only ever seen \0 (nul) before; not \2, \3 etc. or are they not escape sequences, but literal forward slashes. Thanks, Ty

Can someone explain how this works please?
Don't try reading these files. They are generated; read Parser/pgen instead (which generates these files), or see how they are used.
I've never come across escape sequences like this; I've only ever seen \0 (nul) before; not \2, \3 etc. or are they not escape sequences, but literal forward slashes.
They are octal escapes; this is a standard C construct. You need three octal digits to build one character. So it's \222, not \2, and \310, not \3. The integer values are 0222 and 0310, respectively (i.e. 146 and 200). HTH, Martin
participants (2)
-
"Martin v. Löwis"
-
Ty Newton