Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

ProLeap ANTLR4-based parser for Visual Basic 6.0

License

NotificationsYou must be signed in to change notification settings

uwol/proleap-vb6-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is aVisual Basic 6.0 parser based on anANTLR4 grammar,which generates anAbstract Syntax Tree (AST) andAbstract Semantic Graph (ASG) for Visual Basic 6.0 code.The AST represents plain Visual Basic 6.0 source code in a syntax tree structure.The ASG is generated from the AST bysemantic analysis and provides data and controlflow information (e. g. variable access).

The parser is developed test-driven and has successfully beenapplied to large Visual Basic 6.0 projects. It is used by theProLeap analyzer & transformer for Visual Basic 6.0.

💫Star if you like our work.

License: MITProLeap on Twitter

Example

Input: VB6 code

Private Sub Command1_Click ()   Text1.Text = "Hello, world!"End Sub

Output: Abstract Syntax Tree (AST)

(startRule  (module    (moduleBody      (moduleBodyElement        (subStmt          (visibility Private) Sub          (ambiguousIdentifier Command1_Click)          (argList ( ))          (block            (blockStmt              (letStmt                (implicitCallStmt_InStmt                  (iCS_S_MembersCall                    (iCS_S_VariableOrProcedureCall                      (ambiguousIdentifier Text1))                    (iCS_S_MemberCall .                      (iCS_S_VariableOrProcedureCall                        (ambiguousIdentifier                          (ambiguousKeyword Text)))))) =                (valueStmt                  (literal "Hello, world!"))))) End Sub)))) <EOF>)

Getting started

To include the parser in your Maven project build it and add the dependency:

<dependency>  <groupId>io.github.uwol</groupId>  <artifactId>proleap-vb6-parser</artifactId>  <version>3.0.0</version></dependency>

Use the following code as a starting point for developing own code.

Simple: Generate an Abstract Semantic Graph (ASG) from VB6 code

// generate ASG from plain VB6 codejava.io.FileinputFile =newjava.io.File("src/test/resources/io/proleap/vb6/asg/HelloWorld.cls");io.proleap.vb6.asg.metamodel.Programprogram =newio.proleap.vb6.asg.runner.impl.VbParserRunnerImpl().analyzeFile(inputFile);// navigate on ASGio.proleap.vb6.asg.metamodel.Modulemodule =program.getClazzModule("HelloWorld");io.proleap.vb6.asg.metamodel.VariablevariableI =module.getVariable("I");io.proleap.vb6.asg.metamodel.type.TypetypeOfI =variableI.getType();

Complex: Generate an Abstract Semantic Graph (ASG) and traverse the Abstract Syntax Tree (AST)

// generate ASG from plain VB6 codejava.io.FileinputFile =newjava.io.File("src/test/resources/io/proleap/vb6/asg/HelloWorld.cls");io.proleap.vb6.asg.metamodel.Programprogram =newio.proleap.vb6.asg.runner.impl.VbParserRunnerImpl().analyzeFile(inputFile);// traverse the ASTio.proleap.vb6.VisualBasic6BaseVisitor<Boolean>visitor =newio.proleap.vb6.VisualBasic6BaseVisitor<Boolean>() {@OverridepublicBooleanvisitVariableSubStmt(finalio.proleap.vb6.VisualBasic6Parser.VariableSubStmtContextctx) {io.proleap.vb6.asg.metamodel.Variablevariable = (io.proleap.vb6.asg.metamodel.Variable)program.getASGElementRegistry().getASGElement(ctx);Stringname =variable.getName();io.proleap.vb6.asg.metamodel.type.Typetype =variable.getType();returnvisitChildren(ctx);  }};for (finalio.proleap.vb6.asg.metamodel.Modulemodule :program.getModules()) {visitor.visit(module.getCtx());}

Where to look next

How to cite

Please cite ProLeap Visual Basic 6.0 parser in your publications, if it helps your research. Here is an example BibTeX entry:

@misc{wolffgang2018vb6,  title={ProLeap Visual Basic 6.0 parser},  author={Wolffgang, Ulrich and others},  year={2018},  howpublished={\url{https://github.com/uwol/proleap-vb6-parser}},}

Features

  • The grammar is line-based and takes into account whitespace, so that member calls (e.g.A.B) are distinguished from contextual object calls in WITH statements (e.g.A .B).
  • Keywords can be used as identifiers depending on the context, enabling e.g.A.Type, but notType.B.
  • The ANTLR4 grammar is derived from theVisual Basic 6.0 language reference and tested against MSDN VB6 statement examples as well as several Visual Basic 6.0 code repositories.
  • Rigorous test-driven development.

Build process

The build process is based on Maven (version 3 or higher). Building requires a JDK 17 and generates a Maven JAR, which can be used in other Maven projects as a dependency.

  • Clone or download the repository.
  • InEclipse import the directory as a anexisting Maven project.
  • To build, run:
$ mvn clean package
  • The test suite executes AST and ASG tests against VB6 test code and MSDN statement examples. Unit tests and parse tree files were generated by classio.proleap.vb6.TestGenerator from those VB6 test files.
  • You should see output like this:
[INFO] Scanning for projects......------------------------------------------------------- T E S T S-------------------------------------------------------Running io.proleap.vb6.ast.calls.CallsTestParsing file Calls.cls.Comparing parse tree with file Calls.cls.tree.Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.991 secRunning io.proleap.vb6.ast.calls.Module1Test...Results :Tests run: 215, Failures: 0, Errors: 0, Skipped: 0[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------
  • To install the JAR in your local Maven repository:
$ mvn clean install
  • To only run the tests:
$ mvn clean test

Release process

License

Licensed under the MIT License. See LICENSE for details.


[8]ページ先頭

©2009-2025 Movatter.jp