當前位置: 首頁>>代碼示例>>Python>>正文


Python SemanticAnalyzer.analyzeStart方法代碼示例

本文整理匯總了Python中Racecar.SemanticAnalyzer.analyzeStart方法的典型用法代碼示例。如果您正苦於以下問題:Python SemanticAnalyzer.analyzeStart方法的具體用法?Python SemanticAnalyzer.analyzeStart怎麽用?Python SemanticAnalyzer.analyzeStart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Racecar.SemanticAnalyzer的用法示例。


在下文中一共展示了SemanticAnalyzer.analyzeStart方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_assign_word_print_complicated

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_assign_word_print_complicated(self):
        test_string = \
            """color is a word
set color to "blue"
print color
c2 is a word
set c2 to "green"
set color to c2
"""
        correct_translation = \
            """color = None
color = "blue"
print_to_console(color)
c2 = None
c2 = "green"
color = c2
"""
        result = Compiler.getPythonCode(test_string)
        ast = Parser.parseString(test_string)

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 0)

        self.assertEqual(len(ast.errors), 0)
        self.assertEqual(result[0], correct_translation)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:27,代碼來源:test.py

示例2: test_function_invocation_with_two_parameters

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_function_invocation_with_two_parameters(self):
        test_string = \
            """define turnLeftThenDriveStraight using numStepsTurn \
            (number) and numStepsDrive (number)
{
turn left
drive forward numStepsTurn steps
turn right
drive forward numStepsDrive steps
}
turnLeftThenDriveStraight 5 10
"""
        correct_translation = \
            """def turnLeftThenDriveStraight(numStepsTurn, numStepsDrive):
    rotate_car(WheelDirection.LEFT)
    translate_car(numStepsTurn, CarDirection.FORWARDS)
    rotate_car(WheelDirection.RIGHT)
    translate_car(numStepsDrive, CarDirection.FORWARDS)
turnLeftThenDriveStraight(5, 10)
"""
        result = Compiler.getPythonCode(test_string)
        ast = Parser.parseString(test_string)

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 0)

        self.assertEqual(len(ast.errors), 0)
        self.assertEqual(result[0], correct_translation)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:30,代碼來源:test.py

示例3: test_if_elseif_else_statement

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_if_elseif_else_statement(self):
        test_string = \
            """if 1
{
    print "yay"
}
elseIf 2
{
    print "no"
}
else
{
    print "done"
}
"""
        correct_translation = \
            """if 1:
    print_to_console("yay")
elif 2:
    print_to_console("no")
else:
    print_to_console("done")
"""
        result = Compiler.getPythonCode(test_string)
        ast = Parser.parseString(test_string)

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 0)

        self.assertEqual(len(ast.errors), 0)
        self.assertEqual(result[0], correct_translation)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:33,代碼來源:test.py

示例4: test_if_statement_nested

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_if_statement_nested(self):
        test_string = \
            """if 1
{
    print "yay"
    if 1
    {
        print "yahoo"
    }
}
"""
        correct_translation = \
            """if 1:
    print_to_console("yay")
    if 1:
        print_to_console("yahoo")
"""
        result = Compiler.getPythonCode(test_string)
        ast = Parser.parseString(test_string)

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 0)

        self.assertEqual(len(ast.errors), 0)
        self.assertEqual(result[0], correct_translation)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:27,代碼來源:test.py

示例5: test_loop_for_nested

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_loop_for_nested(self):
        test_string = \
            """myCounter is a number
set myCounter to 10
myCounter2 is a number
set myCounter2 to 10
repeat myCounter times
{
    drive forward 1 step
    repeat myCounter2 times
    {
        drive forward 1 step
    }
}
"""
        correct_translation = \
            """myCounter = None
myCounter = 10
myCounter2 = None
myCounter2 = 10
for x in range(myCounter):
    translate_car(1, CarDirection.FORWARDS)
    for x in range(myCounter2):
        translate_car(1, CarDirection.FORWARDS)
"""
        result = Compiler.getPythonCode(test_string)
        ast = Parser.parseString(test_string)

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 0)

        self.assertEqual(len(ast.errors), 0)
        self.assertEqual(result[0], correct_translation)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:35,代碼來源:test.py

示例6: test_function_invocation_no_params

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_function_invocation_no_params(self):
        test_string = \
            """define moveBackwardFive
{
    drive backward 5
}
define moveForwardThenBackward
{
    drive forward 5
    moveBackwardFive
}
moveForwardThenBackward
"""
        correct_translation = \
            """def moveBackwardFive():
    translate_car(5, CarDirection.BACKWARDS)
def moveForwardThenBackward():
    translate_car(5, CarDirection.FORWARDS)
    moveBackwardFive()
moveForwardThenBackward()
"""
        result = Compiler.getPythonCode(test_string)
        ast = Parser.parseString(test_string)

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 0)

        self.assertEqual(len(ast.errors), 0)
        self.assertEqual(result[0], correct_translation)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:31,代碼來源:test.py

示例7: test_loop_while

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_loop_while(self):
        test_string = \
            """myCounter is a number
set myCounter to 1
repeat if myCounter is not 5
{
    drive forward 1 step
    set myCounter to myCounter + 1
}
"""
        correct_translation = \
            """myCounter = None
myCounter = 1
while myCounter != 5:
    translate_car(1, CarDirection.FORWARDS)
    myCounter = ((myCounter) + (1))
"""
        result = Compiler.getPythonCode(test_string)
        ast = Parser.parseString(test_string)

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 0)

        self.assertEqual(len(ast.errors), 0)
        self.assertEqual(result[0], correct_translation)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:27,代碼來源:test.py

示例8: test_drive_backwards

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_drive_backwards(self):
        test_string1 = \
            """drive backwards 10 steps
"""
        test_string2 = \
            """drive backward 10 steps
"""
        test_string3 = \
            """drive backwards 10 step
"""
        test_string4 = \
            """drive backward 10 step
"""
        correct_translation = \
            """translate_car(10, CarDirection.BACKWARDS)
"""

        ast1 = Parser.parseString(test_string1)
        ast2 = Parser.parseString(test_string1)
        ast3 = Parser.parseString(test_string1)
        ast4 = Parser.parseString(test_string1)

        self.assertEqual(len(ast1.errors), 0)
        self.assertEqual(len(ast2.errors), 0)
        self.assertEqual(len(ast3.errors), 0)
        self.assertEqual(len(ast4.errors), 0)

        result1 = Compiler.getPythonCode(test_string1)
        result2 = Compiler.getPythonCode(test_string2)
        result3 = Compiler.getPythonCode(test_string3)
        result4 = Compiler.getPythonCode(test_string4)

        saErrors1 = SemanticAnalyzer.analyzeStart(ast1)
        saErrors2 = SemanticAnalyzer.analyzeStart(ast2)
        saErrors3 = SemanticAnalyzer.analyzeStart(ast3)
        saErrors4 = SemanticAnalyzer.analyzeStart(ast4)

        self.assertEqual(len(saErrors1), 0)
        self.assertEqual(len(saErrors2), 0)
        self.assertEqual(len(saErrors3), 0)
        self.assertEqual(len(saErrors4), 0)

        self.assertEqual(result1[0], correct_translation)
        self.assertEqual(result2[0], correct_translation)
        self.assertEqual(result3[0], correct_translation)
        self.assertEqual(result4[0], correct_translation)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:48,代碼來源:test.py

示例9: test_print_undeclared_var

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_print_undeclared_var(self):
        test_string = \
            """print myNum
"""

        ast = Parser.parseString(test_string)
        self.assertEqual(len(ast.errors), 0, "Test failed at parser.")

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 1)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:12,代碼來源:test.py

示例10: test_basic

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_basic(self):
        test_string = \
            """drive forward 5 steps
"""

        ast = Parser.parseString(test_string)
        self.assertEqual(len(ast.errors), 0, "Test failed at parser.")

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 0)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:12,代碼來源:test.py

示例11: test_template

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_template(self):
        test_string = \
            """
"""

        ast = Parser.parseString(test_string)
        self.assertEqual(len(ast.errors), 0, "Test failed at parser.")

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 0)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:12,代碼來源:test.py

示例12: test_built_in_functions_params

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_built_in_functions_params(self):
        test_string = \
            """drive forwards five steps
"""

        ast = Parser.parseString(test_string)
        self.assertEqual(len(ast.errors), 0, "Test failed at parser.")

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 1)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:12,代碼來源:test.py

示例13: test_calling_nonexistant_function

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_calling_nonexistant_function(self):
        test_string = \
            """fullTurn "left"
"""

        ast = Parser.parseString(test_string)
        self.assertEqual(len(ast.errors), 0, "Test failed at parser.")

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 1)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:12,代碼來源:test.py

示例14: test_assignments_var_str_literal

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_assignments_var_str_literal(self):
        test_string = \
            """myNum is a number
set myNum to "hello"
"""

        ast = Parser.parseString(test_string)
        self.assertEqual(len(ast.errors), 0, "Test failed at parser.")

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 1)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:13,代碼來源:test.py

示例15: test_var_uninitialized

# 需要導入模塊: from Racecar import SemanticAnalyzer [as 別名]
# 或者: from Racecar.SemanticAnalyzer import analyzeStart [as 別名]
    def test_var_uninitialized(self):
        test_string = \
            """myNum is a number
drive forward myNum steps
"""

        ast = Parser.parseString(test_string)
        self.assertEqual(len(ast.errors), 0, "Test failed at parser.")

        saErrors = SemanticAnalyzer.analyzeStart(ast)
        self.assertEqual(len(saErrors), 1)
開發者ID:MDSilber,項目名稱:RacecarLanguage,代碼行數:13,代碼來源:test.py


注:本文中的Racecar.SemanticAnalyzer.analyzeStart方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。