def unary_STL_expr_1(s): """handles unary STL expressions (G: Globally, F: Eventually)""" # obtain the operator of the STL expression op = s[0].getstr() if op == "G": return AST.G_STL_Expr(op, s[2], s[4], s[7], s[10], s[12]) elif op == "F": return AST.F_STL_Expr(op, s[2], s[4], s[7], s[10], s[12]) else: # Parse_Error raise exceptions.Parse_Error("STL Operator: " + op + " not recognized.")
def test_type_context(self): ctx_1 = AST.Type_Context.get_empty_context() ctx_1.add(AST.Id_Val("i"), 10) ctx_1.add(AST.Id_Val("j"), 20) ctx_1.add(AST.Id_Val("k"), 30) ctx_2 = AST.Type_Context.get_empty_context() ctx_2.add(AST.Id_Val("a"), 100, {"val": True}) ctx_2.add(AST.Id_Val("b"), 200) ctx_2.add(AST.Id_Val("c"), 300) self.assertEqual(ctx_1.lookup(AST.Id_Val("k")), 30) self.assertEqual(ctx_2.lookup(AST.Id_Val("b")), 200) # look up something that doesn't exist in the context scope try: ctx_1.lookup(AST.Id_Val("ds")) except exceptions.Context_Lookup_Error as e: # flush out the error message so that it doesn't print at the end sys.stdout.flush() # look up outer scope of top-level context, result in None self.assertEqual(ctx_2.get_outer_context_var_id(), None)
def print_stmt(s): """parse print/println statements""" return AST.Print_Stmt(s[1], s[0].gettokentype())
def multi_line_stmt(s): """parse multi-line statements""" # append the statement to the statements list return AST.Stmt_List(s[0].get_stmt_list() + [s[1]])
def binary_arith_expr(s): """handles binary logic expressions""" return AST.Binary_Arith_Expr(s[1].getstr(), s[1].gettokentype(), s[0], s[2])
def extract_list_val(s): """parse list values""" return AST.List_Val(s[1])
def mutiple_expr_list(s): """parse list values, handle expr list in the beginning or the middle""" # return AST.List_Val(s[0].get_expr_list, None, s[0].gettokentype()) return AST.Expr_List(s[0].get_expr_list() + [s[2]])
def float_val(s): """parse Float values""" return AST.Float_Val(s[0].getstr(), s[0].gettokentype())
def boolean_val(s): """parse Float values""" return AST.Boolean_Val(s[0].getstr(), s[0].gettokentype())
def unary_STL_expr_2(s): """handle unary STL expressions (X: next)""" op = s[0].getstr() if op == "X": return AST.X_STL_Expr(op, s[2], s[5], s[8], s[10])
def function_invocation(s): """invoke specific function of a data structure""" return AST.Invocation(s[0], s[2].getstr())
def typed_var_decl_stmt(s): return AST.Var_Decl_Stmt(s[0].gettokentype(), s[1], s[3], s[5])
def assign_stmt(s): return AST.Assign_Stmt(s[0], s[2])
def untyped_var_decl_stmt(s): return AST.Var_Decl_Stmt(s[0].gettokentype(), s[1], None, s[3])
def while_stmt(s): return AST.While_Stmt(s[1], s[2])
def stmt_list_block_new_line(s): """parse block of statement list""" return AST.Block_Stmt(s[2])
def stmt_list_block(s): """parse block of statement list""" return AST.Block_Stmt(s[1])
def single_line_stmt(s): """parse single-line statements""" return AST.Stmt_List([s[0]])
def binary_STL_expr(s): """handler binary STL expressions""" return AST.Binary_STL_Expr(s[3].getstr(), s[5], s[7], s[1], s[10], s[13], s[15])
def single_println_stmt(s): return AST.Print_Stmt(None, s[0].gettokentype())
def int_val(s): """parse Int values""" return AST.Int_Val(s[0].getstr(), s[0].gettokentype())
def var_expr(s): return AST.Id_Val(s[0].getstr())
def string_val(s): """parse Float values""" return AST.String_Val(s[0].getstr(), s[0].gettokentype())
def meta_var_expr(s): return AST.Meta_Id_Val(s[0].getstr())
def signal_val(s): """parse Float values""" return AST.Signal_Val(s[0].getstr(), None, s[0].gettokentype())
def binary_comp_expr(s): """handles binary comparison expressions""" return AST.Binary_Comp_Expr(s[1].getstr(), s[1].gettokentype(), s[0], s[2])
def extract_tuple_val(s): """parse tuple values""" return AST.Tuple_Val(s[1])
def unary_logic_expr(s): return AST.Unary_Logic_Expr(s[0].getstr(), s[0].gettokentype(), s[1])
def single_expr_list(s): """parse list values, handle expr list in the end""" return AST.Expr_List([s[0]])
def unary_arith_expr(s): return AST.Unary_Arith_Expr(s[0].getstr(), s[0].gettokentype(), s[1])