antlr/runtime/Python3/tests/ctest.py

50 lines
1.2 KiB
Python
Raw Permalink Normal View History

2016-12-05 02:49:53 +08:00
#
# Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2016-12-05 03:37:49 +08:00
# Use of this file is governed by the BSD 3-clause license that
2016-12-05 02:49:53 +08:00
# can be found in the LICENSE.txt file in the project root.
#
2015-08-26 01:15:59 +08:00
import sys
sys.setrecursionlimit(4000)
import antlr4
from parser.cparser import CParser
from parser.clexer import CLexer
from datetime import datetime
2015-08-26 23:43:03 +08:00
import cProfile
2015-08-26 01:15:59 +08:00
class ErrorListener(antlr4.error.ErrorListener.ErrorListener):
def __init__(self):
super(ErrorListener, self).__init__()
self.errored_out = False
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
self.errored_out = True
def sub():
# Parse the input file
input_stream = antlr4.FileStream("c.c")
lexer = CLexer(input_stream)
token_stream = antlr4.CommonTokenStream(lexer)
parser = CParser(token_stream)
errors = ErrorListener()
parser.addErrorListener(errors)
tree = parser.compilationUnit()
def main():
before = datetime.now()
sub()
after = datetime.now()
print(str(after-before))
2015-08-26 23:43:03 +08:00
# before = after
# sub()
# after = datetime.now()
# print(str(after-before))
2015-08-26 01:15:59 +08:00
if __name__ == '__main__':
2015-08-26 23:43:03 +08:00
cProfile.run("main()", sort='tottime')