Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP で AST 解析をして Java のオペコードを生成する

memory
PRO
November 22, 2019

PHP で AST 解析をして Java のオペコードを生成する

- Kichijoji.pm in Japan

English Title:
Generates Operation Codes of Java on performed an Abstract Syntax Tree from PHP code.

memory
PRO

November 22, 2019
Tweet

More Decks by memory

Other Decks in Programming

Transcript

  1. 2019/11/22 .pm PHP AST Java © - BASE, Inc.

  2. © - BASE, Inc. Who am I? (@m m r

    ) BASE GameWith PHP, TypeScript
  3. © - BASE, Inc. Software Design

  4. © - BASE, Inc. PHP

  5. © - BASE, Inc.

  6. © - BASE, Inc. PHP JVM

  7. © - BASE, Inc. PHP JVM 


  8. © - BASE, Inc.

  9. © - BASE, Inc. PHP AST AST PHP AST Java

  10. © - BASE, Inc. + DEMO

  11. © - BASE, Inc. AST

  12. © - BASE, Inc. AST Abstract Syntax Tree, + -

  13. © - BASE, Inc. AST 1 + 2 + 3

    AST + +
  14. © - BASE, Inc. AST + + PlusOp PlusOp::left PlusOp::right

    Number Number Number PlusOp
  15. © - BASE, Inc. AST + PlusOp PlusOp::left PlusOp::right Number

    Number
  16. © - BASE, Inc. AST Number

  17. © - BASE, Inc.

  18. © - BASE, Inc. (PHP, Perl, Python, etc) Lexical Analyzer

    ( , ) Lexer
  19. © - BASE, Inc. 1 + 2 + 3 Value

    Label Means Number Whitespace + Plus Whitespace Number Whitespace + Plus Whitespace Number
  20. © - BASE, Inc. PHP Value Label Means T_LNUMBER T_WHITESPACE

    + - ( ) Whitespace T_LNUMBER T_WHITESPACE + - ( ) T_WHITESPACE T_LNUMBER
  21. © - BASE, Inc. PHP AST

  22. © - BASE, Inc. PHP AST

  23. © - BASE, Inc. PHP AST AST PHP AST

  24. © - BASE, Inc. PHP AST AST PHP AST

  25. © - BASE, Inc.

  26. © - BASE, Inc. 
 AST

  27. © - BASE, Inc. composer require nikic/php-parser

  28. © - BASE, Inc. PHP AST

  29. © - BASE, Inc. PHP AST

  30. © - BASE, Inc. PHP AST T_ECHO T_LNUMBER T_LNUMBER T_LNUMBER

  31. © - BASE, Inc. PHP AST ZEND_AST_BINARY_OP ZEND_AST_BINARY_OP

  32. © - BASE, Inc. PHP AST Echo_ (Stmt) Plus (BinaryOp)

    Plus (BinaryOp) (LNumber) (LNumber) (LNumber) left right left right expressions ( ) (*1) (* ) PHP echo , print ,
  33. © - BASE, Inc. PHP AST Echo_ (Stmt) Plus (BinaryOp)

    Plus (BinaryOp) (LNumber) (LNumber) (LNumber) left right left right expressions ( ) (*1) (* ) PHP echo , print ,
  34. © - BASE, Inc.

  35. © - BASE, Inc.

  36. © - BASE, Inc. PHP AST Java

  37. © - BASE, Inc. Java

  38. © - BASE, Inc.

  39. © - BASE, Inc.

  40. © - BASE, Inc.

  41. © - BASE, Inc. Java 1 + 2 + 3

  42. © - BASE, Inc. Java 1 + 2 + 3

    1 2 2 (3 ) 2 (6 ) 3 iconst_ iconst_ iadd iconst_ iadd
  43. © - BASE, Inc. PHP

  44. © - BASE, Inc. PHP Java PHP AST Java PHP

    echo System.out.println
  45. © - BASE, Inc. PHP Java Plus (BinaryOp) Plus (BinaryOp)

    (LNumber) (LNumber) (LNumber) left right left right PHP AST
  46. © - BASE, Inc. PHP Java Plus (BinaryOp) Plus (BinaryOp)

    (LNumber) left right left right iconst_ iconst_
  47. © - BASE, Inc. PHP Java Plus (BinaryOp) (LNumber) left

    right iconst_ iconst_ iadd left right
  48. © - BASE, Inc. PHP Java Plus (BinaryOp) left right

    iconst_ iconst_ iadd left right iconst_
  49. © - BASE, Inc. PHP Java iconst_ iconst_ iadd left

    right iconst_ iadd left right
  50. © - BASE, Inc. PHP Java 
 Java iconst_ iconst_

    iadd iconst_ iadd
  51. © - BASE, Inc. PHP Java

  52. © - BASE, Inc. DEMO

  53. © - BASE, Inc. php-java Java PHP Java PHP https://github.com/php-java/php-java

  54. © - BASE, Inc.

  55. © - BASE, Inc.

  56. © - BASE, Inc.

  57. © - BASE, Inc. PHP Java (^o^)

  58. © - BASE, Inc.