Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
PHP Objects, Patterns, and Practice- P11: This book takes you beyond the PHP basics to the enterprise development practices used by professional programmers. Updated for PHP 5.3 with new sections on closures, namespaces, and continuous integration, this edition will teach you about object features such as abstract classes, reflection, interfaces, and error handling. You’ll also discover object tools to help you learn more about your classes, objects, and methods. | APPENDIX B A SIMPLE PARSER function trigger Scanner scanner return true protected function doScan Scanner scanner start_state scanner- getState if empty this- parsers return true parser this- parsers 0 count 0 while true if this- max 0 count this- max return true if parser- trigger scanner if this- min 0 count this- min return true else scanner- setState start_state return false if parser- scan scanner if this- min 0 count this- min return true else scanner- setState start_state return false count return true This matches if one or other of two subparsers match class AlternationParse extends CollectionParse function trigger Scanner scanner foreach this- parsers as parser if parser- trigger scanner return true return false 479 APPENDIX B A SIMPLE PARSER protected function doScan Scanner scanner type scanner- tokenType foreach this- parsers as parser start_state scanner- getState if type parser- trigger scanner parser- scan scanner return true scanner- setState start_state return false this terminal parser matches a string literal class StringLiteralParse extends Parser function trigger Scanner scanner return scanner- tokenType Scanner APOS scanner- tokenType Scanner OUOTE protected function push Scanner scanner return protected function doScan Scanner scanner quotechar scanner- tokenType ret false string while token scanner- nextToken if token quotechar ret true break string . scanner- token if string this- discard scanner- getContext - pushResult string return ret this terminal parser matches a word token class WordParse extends Parser function construct word null name null options null parent __construct name options this- word word 480 APPENDIX B A SIMPLE PARSER function trigger Scanner scanner if scanner- tokenType Scanner WORD return false if is_null this- word return true return this- word scanner- token protected function doScan Scanner scanner ret this- trigger scanner return ret By combining terminal and nonterminal Parser objects I can build a .