• 大小: 1.14MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-20
  • 语言: 其他
  • 标签: decaf_PA2  

资源简介

清华大学计算机系编译原理实验。实验第二部分

资源截图

代码片段和文件信息

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ts=4 sw=4 expandtab:

“““
完成作业以后,运行本文件,它会将你的代码、实验报告一起打包为 submit.zip。
“““

from __future__ import print_function # Requires Python 2.7+

import locale
import os
import re
import sys
import zipfile


# Python3‘s input == Python2‘s raw_input
try:
    input_compat = raw_input
except NameError:
    input_compat = input


def S(s):
    # F*** systems that still refuse to use UTF-8 by default in the 21st century
    if ‘decode‘ in dir(s):
        return s.decode(‘utf-8‘).encode(locale.getpreferredencoding()) # Python 2 is naughty
    else:
        return s # Python 3 is good
    # FIXME: Can anybody please tell me whether there is a simpler way to make Chinese
    # characters display correctly in both Python 2 and 3 and in all three major OSes
    # (Win/Lin/Mac)?


def main():

    # Preparations
    locale.setlocale(locale.LC_ALL ‘‘)

    # Check whether decaf.jar exists
    decaf_jar = os.path.join(‘result‘ ‘decaf.jar‘)
    if not os.path.exists(decaf_jar):
        print(S(‘未找到 decaf.jar 文件。请重新编译。‘) file=sys.stderr)
        return 1
    print(S(‘已找到 {}‘.format(decaf_jar)))

    # Check whether report exists
    for report_file in [‘report.txt‘ ‘report.doc‘ ‘report.docx‘ ‘report.pdf‘ ‘report.odf‘]:
        if os.path.exists(report_file):
            break
    else:
        print(S(‘未找到实验报告。请确认它的文件名正确 (report.txt/doc/docx/pdf/odf)。‘) file=sys.stderr)
        return 1
    print(S(‘已找到实验报告 {}‘.format(report_file)))

    # Ask for E-mail
    email = input_compat(S(‘请输入您的 Email: ‘))
    while not re.match(r‘[^@]+@\w+\.[\w.]+‘ email):
        email = input_compat(S(‘Email 格式不正确,请重新输入: ‘))

    # Creating submit.zip
    with zipfile.ZipFile(‘submit.zip‘ ‘w‘) as submit_zip:
        submit_zip.write(decaf_jar ‘decaf.jar‘ zipfile.ZIP_STORED)
        submit_zip.write(report_file report_file zipfile.ZIP_DEFLATED)
        submit_zip.writestr(‘email.txt‘ email.encode(‘utf-8‘) zipfile.ZIP_STORED)

    # Finished
    print(S(‘完成。请将 submit.zip 文件上传到网络学堂。‘))
    return 0


if __name__ == ‘__main__‘:
    retcode = main()
    if os.name == ‘nt‘:
        input_compat(‘Press Enter to continue...‘)
    sys.exit(retcode)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        292  2012-11-18 11:24  decaf_PA2\.classpath

     文件        385  2012-11-18 11:24  decaf_PA2\.project

     文件         57  2012-11-18 11:27  decaf_PA2\.settings\org.eclipse.core.resources.prefs

     文件         50  2012-11-18 11:27  decaf_PA2\.settings\org.eclipse.core.runtime.prefs

     文件        981  2012-12-21 08:08  decaf_PA2\bin\decaf\Driver$1.class

     文件       3608  2012-12-21 08:08  decaf_PA2\bin\decaf\Driver.class

     文件        976  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadArgCountError.class

     文件        987  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadArgTypeError.class

     文件        510  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadArrElementError.class

     文件        519  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadInheritanceError.class

     文件        817  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadLengthArgError.class

     文件        496  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadLengthError.class

     文件        502  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadNewArrayLength.class

     文件        915  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadOverrideError.class

     文件        893  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadPrintArgError.class

     文件        883  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadReturnTypeError.class

     文件        484  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadTestExpr.class

     文件        786  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BadVarTypeError.class

     文件        510  2012-11-18 11:27  decaf_PA2\bin\decaf\error\BreakOutOfLoopError.class

     文件        772  2012-11-18 11:27  decaf_PA2\bin\decaf\error\ClassNotFoundError.class

     文件       1015  2012-11-18 11:27  decaf_PA2\bin\decaf\error\DecafError.class

     文件        948  2012-11-18 11:27  decaf_PA2\bin\decaf\error\DeclConflictError.class

     文件        872  2012-11-18 11:27  decaf_PA2\bin\decaf\error\FieldNotAccessError.class

     文件        859  2012-11-18 11:27  decaf_PA2\bin\decaf\error\FieldNotFoundError.class

     文件        921  2012-11-18 11:27  decaf_PA2\bin\decaf\error\IncompatBinOpError.class

     文件        841  2012-11-18 11:27  decaf_PA2\bin\decaf\error\IncompatUnOpError.class

     文件        776  2012-11-18 11:27  decaf_PA2\bin\decaf\error\IntTooLargeError.class

     文件        540  2012-11-18 11:27  decaf_PA2\bin\decaf\error\MsgError.class

     文件        774  2012-11-18 11:27  decaf_PA2\bin\decaf\error\NewlineInStrError.class

     文件        771  2012-11-18 11:27  decaf_PA2\bin\decaf\error\NoMainClassError.class

............此处省略378个文件信息

评论

共有 条评论

相关资源