# # Bounded stack language for Python # BSL type finite-state trans-line typefaces r---- C-Plain i--B- C-Comment rb-R- C-Directive rb--- C-Keyword r---- C-Identifier r---- C-Operator r---- C-Sequencer t--Gi C-String r--G- C-Number t--Ri C-Escape state set T C-Plain C C-Comment S C-String H C-String M C-String N C-String demo string if a is None: print >> sys.stderr, "hi" word range a-zA-Z0-9_ rules # # Normal scope # T \{C-Directive}\\$ nop T \{C-Keyword}\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\ nop T \{C-Plain}[ \t]+ nop T \{C-Number}0[xX][0-9a-fA-F]+:-0[xX][0-9a-fA-F]+:[\-0-9]*.[0-9]+[eE][0-9]+:[\-0-9]+.[0-9]*[eE][0-9]+:[\-0-9]+.[0-9]*:[\-0-9]*.[0-9]+:[0-9]+:-[0-9]+ nop T \{C-Number}\:\ nop T \{C-Identifier}\<[a-zA-Z_][a-zA-Z0-9_]*\> nop T \{C-Comment}# goto C T \{C-Directive}[uU]?[rR]?\{C-Plain}""" goto M T \{C-Directive}[uU]?[rR]?\{C-Plain}''' goto N T \{C-Directive}[uU]?[rR]?\{C-Plain}" goto S T \{C-Directive}[uU]?[rR]?\{C-Plain}' goto H T \{C-Operator}+:-:\*:\*\*:/://:%:<<:>>:&:|:\^:~:<:>:<=:>=:==:!=:<> nop T \{C-Operator}(:):\[:\]:{:}:,:\::.:`:=:;:+=:-=:*=:/=://=:%=:&=:|=:\^=:>>=:<<=:\*\*= nop # # Comments # C $ goto T # # Strings (S, H) and multi-line strings (M and N) # SHMN [^"'\\]+ nop S \{C-Plain}" goto T H \{C-Plain}' goto T M \{C-Plain}""" goto T N \{C-Plain}''' goto T SHMN \{C-Escape}\\[0-9][0-9][0-9]:\\a:\\b:\\f:\\n:\\N{[a-zA-Z-_]*}:\\r:\\t:\\u????:\\U????????:\\v:\\x?? nop SH \{C-Escape}\\\{C-String}? nop SH $ goto T