本文整理汇总了Python中naulang.compiler.compiler.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_while_statement
def test_while_statement():
assert(parse("""while true {
100
200
}""") == ast.Block([ast.WhileStatement(ast.BooleanConstant(True),
ast.Block([ast.IntegerConstant(100),
ast.IntegerConstant(200)]))]))
示例2: test_function_call_and_definition
def test_function_call_and_definition():
assert parse("""
let n = 10
let a = fn(x) {
print (x * 2) + n
}
a(2)
a(4)
a(8)
a(16)
a(32)
""") == ast.Block([
ast.ScopedAssignment('n', ast.IntegerConstant(10)),
ast.ScopedAssignment('a', ast.FunctionExpression(
paramlist=ast.ParameterList(['x']),
block=ast.Block([
ast.PrintStatement(
ast.Add(
ast.Multiply(
ast.IdentifierExpression('x'),
ast.IntegerConstant(2)
),
ast.IdentifierExpression('n')
)
)
])
)
),
ast.FunctionCall(ast.IdentifierExpression('a'),
ast.ArgumentList([
ast.IntegerConstant(2)
])
),
ast.FunctionCall(ast.IdentifierExpression('a'),
ast.ArgumentList([
ast.IntegerConstant(4)
])
),
ast.FunctionCall(ast.IdentifierExpression('a'),
ast.ArgumentList([
ast.IntegerConstant(8)
])
),
ast.FunctionCall(ast.IdentifierExpression('a'),
ast.ArgumentList([
ast.IntegerConstant(16)
])
),
ast.FunctionCall(ast.IdentifierExpression('a'),
ast.ArgumentList([
ast.IntegerConstant(32)
])
)
])
示例3: test_compound_expression
def test_compound_expression():
assert parse("10 * 6 - 5 + 2 + 1000 / 2") == ast.Block([
ast.Add(
ast.Add(
ast.Subtract(
ast.Multiply(
ast.IntegerConstant(10),
ast.IntegerConstant(6)
),
ast.IntegerConstant(5)
),
ast.IntegerConstant(2)
),
ast.Divide(
ast.IntegerConstant(1000),
ast.IntegerConstant(2)
)
)])
示例4: test_parse_channel_out
def test_parse_channel_out():
assert parse("""let n =<: channel""") == ast.Block(
[ast.ScopedAssignment('n', ast.ChannelOut(ast.IdentifierExpression('channel')))])
示例5: test_parse_channel_in_out
def test_parse_channel_in_out():
assert parse(
"""in <-<: out""") == ast.Block([ast.ChannelIn(ast.IdentifierExpression("in"),
ast.ChannelOut(ast.IdentifierExpression("out")))])
示例6: test_less_than_eq_expression
def test_less_than_eq_expression():
assert parse("100 <= 100") == ast.Block([ast.LessThanOrEqual(ast.IntegerConstant(100), ast.IntegerConstant(100))])
示例7: test_function_statement_args
def test_function_statement_args():
assert parse("""fn a(x, y, z) {
100
}""") == ast.Block([ast.FunctionStatement('a',
ast.ParameterList(['x', 'y', 'z']),
ast.Block([ast.IntegerConstant(100)]))])
示例8: test_not_equal_expression
def test_not_equal_expression():
assert parse("100 != 100") == ast.Block([ast.NotEquals(ast.IntegerConstant(100), ast.IntegerConstant(100))])
示例9: test_logical_or_expression
def test_logical_or_expression():
assert parse("100 or 100") == ast.Block([ast.Or(ast.IntegerConstant(100), ast.IntegerConstant(100))])
示例10: test_subtraction_expression
def test_subtraction_expression():
assert parse("100-100") == ast.Block([ast.Subtract(ast.IntegerConstant(100), ast.IntegerConstant(100))])
示例11: test_equality_expression
def test_equality_expression():
assert parse("100 == 100") == ast.Block([ast.Equals(ast.IntegerConstant(100), ast.IntegerConstant(100))])
assert parse("100 is 100") == ast.Block([ast.Equals(ast.IntegerConstant(100), ast.IntegerConstant(100))])
示例12: test_scope_assignment
def test_scope_assignment():
assert parse("""let a = 10""") == ast.Block([ast.ScopedAssignment('a', ast.IntegerConstant(10))])
示例13: test_expression_assignment
def test_expression_assignment():
assert parse(
"""a = 10 * 10""") == ast.Block([ast.Assignment('a',
ast.Multiply(ast.IntegerConstant(10),
ast.IntegerConstant(10)))])
示例14: test_array_access_assignment
def test_array_access_assignment():
assert parse("""a[0] = 10""") == ast.Block(
[ast.ArrayAssignment(ast.ArrayAccess(ast.IdentifierExpression('a'),
ast.IntegerConstant(0)),
ast.IntegerConstant(10))])
示例15: test_array_access
def test_array_access():
assert parse("""a[10]""") == ast.Block([ast.ArrayAccess(ast.IdentifierExpression('a'), ast.IntegerConstant(10))])