如何使用jsSyntaxTree绘制解析树

问题描述 投票:0回答:1

我有这段代码需要绘制解析树:

for(id=num;id<=num;id=id+1){ 
   id=id/num; 
   if(id==num){ 
      id=id*num; 
   } 
   else{ 
      id=id+num; 
   } 
}

我在其他帖子中看到有人建议使用这个网站:https://ironcreek.net/syntaxtree/。我该如何使用它?

parsing tree parse-tree
1个回答
1
投票

我希望这对你有用。

[ForLoop
  [Initialization 
    [Assignment 
      [Identifier "id"]
      [Literal "num"]
    ]
  ]
  [Condition 
    [Comparison 
      [Identifier "id"] 
      [Operator "<="] 
      [Literal "num"]
    ]
  ]
  [Increment 
    [Assignment 
      [Identifier "id"] 
      [Expression 
        [Identifier "id"] 
        [Operator "+"] 
        [Literal "1"]
      ]
    ]
  ]
  [Body 
    [Block 
      [Assignment 
        [Identifier "id"] 
        [Expression 
          [Identifier "id"] 
          [Operator "/"] 
          [Literal "num"]
        ]
      ]
      [IfStatement 
        [Condition 
          [Comparison 
            [Identifier "id"] 
            [Operator "=="] 
            [Literal "num"]
          ]
        ]
        [ThenBlock 
          [Assignment 
            [Identifier "id"] 
            [Expression 
              [Identifier "id"] 
              [Operator "*"] 
              [Literal "num"]
            ]
          ]
        ]
        [ElseBlock 
          [Assignment 
            [Identifier "id"] 
            [Expression 
              [Identifier "id"] 
              [Operator "+"] 
              [Literal "num"]
            ]
          ]
        ]
      ]
    ]
  ]
]
© www.soinside.com 2019 - 2024. All rights reserved.