|
From: Evan L. <sa2...@cy...> - 2015-01-09 00:27:14
|
With no knowledge whatever of SV, I imagine the problem is that a
modport_ports_list might look like this:
in a, b, c, out d, e, f; // with a ';'?
and it's not immediately obvious to the parser if 'out' is a
port_direction, or an IDENTIFIER - is that right?
If so, you've got 2 options:
1 - find out whether 'out' is followed by a comma, which is presumably
why you mention lookahead. At first sight, I'd be inclined to handle
this by instead re-factoring a port list as something like this:
port_list
: first_port
| port_list ',' IDENTIFIER
first_port : port_direction IDENTIFIER ;
2 - add a terminal for PORT_IDENTIFIER, which is identical to
IDENTIFIER, but doesn't allow the presumably-reserved 'in', 'out', etc.
This will just work anyway if you've got your ordering correct in the
lex file - ie. you match on 'in'/'out'/etc before matching identifiers.
Having said that, I have a very vague recollection that lexing in Icarus
is table-based in some way, so you may not be able to do this. If so,
you could have a regex for PORT_IDENTIFIER which excludes the
directions. Or something like that... :)
BTW, I agree that you should never allow *any* conflicts in your grammars.
-Evan
On 08/01/2015 19:33, Martin Whitaker wrote:
> I'm trying to add support for SystemVerilog modports to the iverilog parser.
> The relevant snippet from parse.y looks like this:
>
> modport_item
> : IDENTIFIER
> { pform_start_modport_item(@1, $1); }
> '(' modport_ports_list ')'
> { pform_end_modport_item(@1); }
> ;
>
> modport_ports_list
> : modport_ports_declaration
> | modport_ports_list ',' modport_ports_declaration
> ;
>
> modport_ports_declaration
> : attribute_list_opt port_direction modport_simple_port_list
> { pform_add_modport_ports(@2, $1, $2, $3); }
> | attribute_list_opt import_export modport_tf_port_list
> { ... }
> | attribute_list_opt K_clocking IDENTIFIER
> { ... }
> ;
>
> modport_simple_port_list
> : IDENTIFIER
> { $$ = make_port_list($1, 0); }
> | '.' IDENTIFIER '(' expression ')'
> { $$ = make_port_list($2, $4); }
> | modport_simple_port_list ',' IDENTIFIER
> { $$ = make_port_list($1, $3, 0); }
> | modport_simple_port_list ',' '.' IDENTIFIER '(' expression ')'
> { $$ = make_port_list($1, $4, $6); }
> ;
>
> which is giving me a shift/reduce conflict. The problem is the parser can't
> distinguish between a ',' that separates items in a modport_simple_port_list
> and one that separates items in a modport_ports_list.
>
> I can't find a way to avoid the conflict with a single level of lookahead. Can
> anyone else?
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming! The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net
> _______________________________________________
> Iverilog-devel mailing list
> Ive...@li...
> https://lists.sourceforge.net/lists/listinfo/iverilog-devel
>
|