-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added experimental parser using ANTLR4 and the grammar vba.g4 (not in…
…tegrated with ViperMonkey yet)
- Loading branch information
Showing
7 changed files
with
1,061 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ prettytable | |
colorlog | ||
colorama | ||
pyparsing | ||
antlr4-python2-runtime |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@echo off | ||
set classpath0=%CLASSPATH% | ||
SET CLASSPATH=.;C:\Javalib\antlr-4.6-complete.jar;%CLASSPATH% | ||
java org.antlr.v4.Tool %* | ||
set classpath=%classpath0% | ||
set classpath0= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@echo off | ||
set classpath0=%CLASSPATH% | ||
SET CLASSPATH=.;C:\Javalib\antlr-4.6-complete.jar;%CLASSPATH% | ||
java org.antlr.v4.gui.TestRig %* | ||
set classpath=%classpath0% | ||
set classpath0= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
antlr4 -Dlanguage=Python2 -encoding utf8 vba.g4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import antlr4 | ||
import sys | ||
|
||
from vbaLexer import vbaLexer | ||
from vbaListener import vbaListener | ||
from vbaParser import vbaParser | ||
|
||
class MyListener(vbaListener): | ||
def __init__(self): | ||
pass | ||
|
||
def enterSubStmt(self, ctx): | ||
for child in ctx.children: | ||
# Skip all children that aren't AmbiguousIdentifier | ||
if isinstance(child, vbaParser.AmbiguousIdentifierContext): | ||
# if type(child).__name__ != 'AmbiguousIdentifierContext': | ||
name = child.getText() | ||
print('Sub %r' % name) | ||
# self.that.globals[name.lower()] = ctx | ||
|
||
def exitSubStmt(self, ctx): | ||
print('exitSubStmt') | ||
|
||
def enterFunctionStmt(self, ctx): | ||
for child in ctx.children: | ||
# Skip all children that aren't AmbiguousIdentifier | ||
if type(child).__name__ != 'AmbiguousIdentifierContext': | ||
continue | ||
name = child.getText() | ||
print('Function %r' % name) | ||
# self.that.globals[name.lower()] = ctx | ||
|
||
def enterBlockStmt(self, ctx): | ||
print('enterBlockStmt:') | ||
print(ctx.getText()) | ||
|
||
def enterLiteral(self, ctx): | ||
print('enterLiteral:') | ||
print(ctx.getText()) | ||
|
||
|
||
try: | ||
filename = sys.argv[1] | ||
except: | ||
sys.exit('Usage: %s <VBA text file>' % sys.argv[0]) | ||
|
||
print('Parsing %s' % filename) | ||
print('Lexer') | ||
lexer = vbaLexer(antlr4.FileStream(sys.argv[1])) | ||
print('Stream') | ||
stream = antlr4.CommonTokenStream(lexer) | ||
print('vbaParser') | ||
parser = vbaParser(stream) | ||
print('Parsing from startRule') | ||
tree = parser.startRule() | ||
print('Walking the parse tree') | ||
listener = MyListener() | ||
walker = antlr4.ParseTreeWalker() | ||
walker.walk(listener, tree) |
Oops, something went wrong.