From a06fc34dfb7bfd870e3af54c275a6a0ff48359f8 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 25 Apr 2019 17:02:51 +0100 Subject: [PATCH] start constructing class --- lexor.py | 2 +- parse_sv.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lexor.py b/lexor.py index d25ed61..754fcf1 100644 --- a/lexor.py +++ b/lexor.py @@ -811,7 +811,7 @@ def t_timescale_end(t): t.type = 'timescale' t.value = code t.lexer.pop_state() - print "match", code + print ("match", code) return t """ diff --git a/parse_sv.py b/parse_sv.py index df38a7c..39fe14b 100644 --- a/parse_sv.py +++ b/parse_sv.py @@ -3234,6 +3234,7 @@ def p_branch_probe_expression_2(p): def p_expression_1(p): '''expression : expr_primary_or_typename ''' print('expression_1', list(p)) + p[0] = p[1] # { $$ = $1; } () def p_expression_2(p): @@ -3681,10 +3682,12 @@ def p_expression_list_proper_2(p): def p_expr_primary_or_typename_1(p): '''expr_primary_or_typename : expr_primary ''' print('expr_primary_or_typename_1', list(p)) + p[0] = p[1] () def p_expr_primary_or_typename_2(p): '''expr_primary_or_typename : TYPE_IDENTIFIER ''' print('expr_primary_or_typename_2', list(p)) + p[0] = p[1] # { PETypename*tmp = new PETypename($1.type); # FILE_NAME(tmp,@1); # $$ = tmp; @@ -3694,6 +3697,7 @@ def p_expr_primary_or_typename_2(p): def p_expr_primary_1(p): '''expr_primary : number ''' print('expr_primary_1', list(p)) + p[0] = p[1] # { assert($1); # PENumber*tmp = new PENumber($1); # FILE_NAME(tmp, @1); @@ -3748,6 +3752,7 @@ def p_expr_primary_5(p): def p_expr_primary_6(p): '''expr_primary : hierarchy_identifier ''' print('expr_primary_6', list(p)) + p[0] = p[1] # { PEIdent*tmp = pform_new_ident(*$1); # FILE_NAME(tmp, @1); # $$ = tmp; @@ -4875,6 +4880,7 @@ def p_atom2_type_4(p): def p_lpvalue_1(p): '''lpvalue : hierarchy_identifier ''' print('lpvalue_1', list(p)) + p[0] = p[1] # { PEIdent*tmp = pform_new_ident(*$1); # FILE_NAME(tmp, @1); # $$ = tmp; @@ -4938,6 +4944,24 @@ def p_cont_assign_list_2(p): def p_module_1(p): '''module : attribute_list_opt module_start lifetime_opt IDENTIFIER _embed0_module module_package_import_list_opt module_parameter_port_list_opt module_port_list_opt module_attribute_foreign ';' _embed1_module timeunits_declaration_opt _embed2_module module_item_list_opt module_end _embed3_module endlabel_opt ''' print('module_1', list(p)) + clsname = [Leaf(token.NAME, 'class'), + Leaf(token.NAME, p[4], prefix=' '), + Leaf(token.COLON, ':')] + stmt = Node(syms.pass_stmt, [Leaf(token.NAME, "pass"),]) + stmts = Node(syms.small_stmt, [stmt, Leaf(token.NEWLINE, '\n')]) + stmts = Node(syms.stmt, [stmts]) + suite = Node(syms.suite, [Leaf(token.NEWLINE, '\n'), + Leaf(token.INDENT, ' '), + stmts, + Leaf(token.DEDENT, '') + ]) + clsdecl = Node(syms.classdef, clsname + [suite], + prefix='', fixers_applied=[]) + clsdecl = Node(syms.compound_stmt, [clsdecl]) + print ("clsdecl", repr(clsdecl)) + print ("clsstr:") + print (str(clsdecl)) + p[0] = clsdecl # { // Last step: check any closing name. This is done late so # // that the parser can look ahead to detect the present # // endlabel_opt but still have the pform_endmodule() called @@ -7312,6 +7336,7 @@ def p_statement_item_33(p): else: expr = Node(syms.expr_stmt, [p[1], Leaf(token.EQUAL, p[2]), ]) print ("expr", repr(expr)) + print ("expr (python):'%s'" % expr) p[0] = expr # { PAssign*tmp = new PAssign($1,$3); # FILE_NAME(tmp, @1); -- 2.30.2