コード例 #1
0
ファイル: cli.py プロジェクト: b0g3r/tg-codegen
def main(argv: typing.List[str]) -> int:
    parser = Parser()

    groups = parser.parse()
    generator = Generator(groups)
    generator.generate(out_dir)

    return 0
コード例 #2
0
def main():
    print ('Bok')
    X=open('dat2.txt','r')
    pars=Parser(X)
    pars.ucitaj_gramatiku()
    '''
コード例 #3
0
'''This is the main module of the lexycal analyzer generator

The project is the 1st laboratory excercise for the PPJ subject at FER

created: 11. 10. 2011
Ivan Slijepcevic
'''

import sys

from generator.parser import Parser

datoteka_s_pravilima = 'analizator/analizator.upute'

if __name__ == '__main__':
    
    #create parser object (with sys.stdin)
    parser = Parser( sys.stdin )
    automat = parser.parse()
    
    automat.napravi_analizator( datoteka_s_pravilima )
コード例 #4
0
ファイル: optimizer.py プロジェクト: jiggum/c-compiler
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='AST optimizer')
    parser.add_argument('input',
                        type=str,
                        metavar='Input_File',
                        help='Input .c file path')
    parser.add_argument('output',
                        type=str,
                        metavar='Output_File',
                        help='Output .c file path')
    parser.add_argument('--debug', action='store_true')
    args = parser.parse_args()

    src_path = args.input
    target_path = args.output
    parser = Parser(debug=args.debug)
    ast = parser.run(src_path)
    if args.debug:
        printVisitor = PrintVisitor()
        ast.accept(printVisitor)
        print(printVisitor)
    constantFoldingVisitor = ConstantFoldingVisitor(debug=args.debug,
                                                    mark_used=True)
    ast.accept(constantFoldingVisitor)
    ast.accept(constantFoldingVisitor)
    writeVisitor = WriteVisitor(dead_code_elimination=True)
    s = ast.accept(writeVisitor)
    f = open(target_path, 'w')
    f.write(s)
    f.close()
コード例 #5
0
CLI_EXIT_REGEX = re.compile('^exit$')
LINE_RGEX = re.compile('^\d+$')
VARIABLE_RGEX = re.compile('^[a-zA-Z_$][a-zA-Z_$0-9]*$')

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='AST optimizer')
    parser.add_argument('input',
                        type=str,
                        metavar='Input_File',
                        help='Input .c file path')
    parser.add_argument('--debug', action='store_true')
    args = parser.parse_args()

    sys.setrecursionlimit(2**16)
    try:
        parser = Parser(debug=args.debug)
        ast = parser.run(args.input)
        if args.debug:
            printVisitor = PrintVisitor()
            ast.accept(printVisitor)
            print(printVisitor)
        flowVisitor = InterpreterVisitor(debug=args.debug)
        ast.accept(flowVisitor)
        while True:
            input_str = input(
                str(flowVisitor.linenos) + '>>' if args.debug else '>>')
            if CLI_NEXT_REGEX.search(input_str):
                m = CLI_NEXT_REGEX.match(input_str)
                lines_str = m.groups()[0]
                if lines_str is not None and LINE_RGEX.search(
                        lines_str) is None:
コード例 #6
0
import sys
from datetime import datetime

from generator.parser import Parser
from generator.model_analizatora import ModelAnalizatora

datoteka_tablice = 'analizator/tablice.upute'
datoteka_sinkronizacijski = 'analizator/sinkronizacijski.upute'

if __name__ == '__main__':
    
    t1 = datetime.now()
    
    parser = Parser( sys.stdin )
    gramatika = parser.ucitaj_gramatiku()
    
    model = ModelAnalizatora( gramatika )
    
    # 
    model.ispisi_tablice( datoteka_tablice )
    
    # stvara datoteku sa sinkronizacijskim znakovima
    parser.ispisi_sinkronizacijske_znakove( datoteka_sinkronizacijski )
    
    t2 = datetime.now()
    print( t2 - t1 )