示例#1
0
def main():
    rules = get_rules()
    lex_arr = get_lex()
    tests = get_tests()

    while True:
        x = input('\n\nInput a test number, type \'help\' to see all test cases or \'exit\' to exit the program\n')
        if x in 'help':
            print('-----------------------------------------------------------')
            print_tests()

        elif x in 'exit':
            return

        elif x.isdigit():
             print('\n\nRESULTS\n-----------------------------------------------------------')
             x = int(x)
             pos = pos_tagger(x,tests,lex_arr)

             if grammar_check(pos, rules) == True:
                 print('Verdict: Sentence is grammatically correct\n')
                 bracketed_sentence(pos)
                 build_tree(pos)
             else:
                 test = tests[x].split()
                 print('Verdict: Sentence is not grammatically correct\n')
                 incorrect_sentence_parser(test)
        else:
            print('\n-----------------------------------------------------------')
            print('\nPLEASE INPUT A CORRECT COMMAND!\n')
        print('-----------------------------------------------------------')
示例#2
0
def main():
    argparser = argparse.ArgumentParser(
        description='Compiles SPL programs toSSM instruction files.')
    argparser.add_argument('spl', metavar='infile',
        help="the SPL source file")
    argparser.add_argument('ssm', metavar='outfile',
        help="the SSM output file")
    argparser.add_argument('--verbose', '-v', action='count',
        help="increase the level of verbosity")
    args = argparser.parse_args()
    if not args.verbose or args.verbose < 4:
        sys.tracebacklimit = 0  # so that we only show our own exceptions
    sys.setrecursionlimit(10000)  # since we're compiling recursively..
    with io.open(args.spl, encoding='utf-8') as fin:
        tokens = scanner.scan_spl(fin)
    tree = parser.build_tree(tokens)
    usedsyms, symtabs = semanticanalysis.check_binding(tree, stdlib.functions)
    with open(args.ssm, 'w') as fout:
        generator.generate_ssm(tree, usedsyms, stdlib.functions, fout)
    if args.verbose:
        if args.verbose >= 2:
            prettyprinter.print_tree(tree)
        if args.verbose >= 3:
            print(tree)
        semanticanalysis.print_symboltables(symtabs)
    print("Successfully compiled {0.spl} to {0.ssm}.".format(args))
示例#3
0
文件: p.py 项目: 0apm/Lexer
#coding=utf8
import sys
from lexer import *
import lexer as l
from parser import build_tree

with open(sys.argv[-1], 'r') as my_file:
    data = my_file.read()
    l._FFlag = 1;
    l.lexer = lex.lex()
    print(build_tree(data))
示例#4
0
IF(NOT NOT a)
{
}



[UINT a = 0] FUNCTION (UINT w = 12)
{


}

WHILE (a)
{
}

IF ()
{

}

IF (8)
{
} ELSE
{
}
'''

# нужно сделать так, чтобы это не работало
result = build_tree(data)
# print(result)
示例#5
0
# coding=utf8

from parser import build_tree

data = '''
<?php
$val = 5;
$result = substr( "foobar", 2*(7-$val) ); /* comment */
echo "это наш результат: ", $result;
'''

result = build_tree(data)
print result