Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

30 changes: 0 additions & 30 deletions .idea/csv-plugin.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/dictionaries/Morteza.xml

This file was deleted.

16 changes: 0 additions & 16 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

175 changes: 0 additions & 175 deletions .idea/misc.xml

This file was deleted.

This file was deleted.

This file was deleted.

Empty file.
Empty file.
11 changes: 0 additions & 11 deletions .idea/sonarlint/issuestore/index.pb

This file was deleted.

8 changes: 8 additions & 0 deletions code/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
43 changes: 43 additions & 0 deletions code/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions code/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml → code/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml → code/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions code/AST_Main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from antlr4 import *
import argparse
from .Ast import ASTListener
from .gen.MiniJavaLexer import MiniJavaLexer
from .gen.MiniJavaParser import MiniJavaParser


def main(args):
# Step 1: Load input source into stream
stream = FileStream(args.file, encoding='utf8')
print('Input code:\n{0}'.format(stream))
print('Result:')

# Step 2: Create an instance of AssignmentStLexer
lexer = MiniJavaLexer(stream)

# Step 3: Convert the input source into a list of tokens
token_stream = CommonTokenStream(lexer)

# Step 4: Create an instance of the AssignmentStParser
parser = MiniJavaParser(token_stream)

# Step 5: Create parse tree
parse_tree = parser.start()

# Step 6: Create an instance of AssignmentStListener
# code_generator_listener = ThreeAddressCodeGeneratorListener()
code_generator_listener = ASTListener()

# Step 7(a): Walk parse tree with a customized listener (Automatically)
walker = ParseTreeWalker()
walker.walk(t=parse_tree, listener=code_generator_listener)

if __name__ == '__main__':
argparser = argparse.ArgumentParser()
argparser.add_argument(
'-n', '--file',
help='Input source', default=r'input.txt')
args = argparser.parse_args()
main(args)
Loading