1Parser(3)             User Contributed Perl Documentation            Parser(3)
2
3
4

NAME

6       Verilog::Parser - Parse Verilog language files
7

SYNOPSIS

9         use Verilog::Parser;
10
11         my $parser = new Verilog::Parser;
12         $string = $parser->unreadback ();
13         $line   = $parser->lineno ();
14         $parser->parse ($text)
15         $parser->parse_file ($filename)
16

DESCRIPTION

18       Verilog::Parser will tokenize a Verilog file when the parse() method is
19       called and invoke various callback methods.  This is useful for
20       extracting information and editing files while retaining all context.
21       For netlist like extractions, see Verilog::Netlist.
22
23       See the "Which Package" section of Verilog::Language if you are unsure
24       which parsing package to use for a new application.
25
26       Note the parser allows some constructs that are syntax errors according
27       to the specification (for example "foo.bar(1)++".) This is done when
28       the parser can't easily detect these cases.  It's up to the consumer of
29       the parser to filter out such errors if it cares.
30

METHODS

32       $parser = Verilog::Parser->new (args...)
33           Create a new Parser. Passing the named argument "use_unreadback =>
34           0" will disable later use of the unreadback method, which may
35           improve performance.
36
37           Adding "use_std => 1" will add parsing of the SystemVerilog built-
38           in std:: package, or "use_std => 0" will disable it.  If
39           unspecified it is silently included (no callbacks will be involed)
40           when suspected to be necessary.
41
42           Adding "symbol_table => []" will use the specified symbol table for
43           this parse, and modify the array reference to include those symbols
44           detected by this parse.  As the SystemVerilog language requires
45           packages and typedefs to exist before they are referenced, you must
46           pass the same symbol_table to subsequent parses that are for the
47           same compilation scope.  The internals of this symbol_table should
48           be considered opaque, as it will change between package versions,
49           and must not be modified by user code.
50
51       $parser->callback_names ()
52           Return an array of callback function names.  This may be used to
53           automatically create callbacks for all functions, or to test for
54           different callback functionality between versions of Verilog-Perl.
55
56       $parser->eof ()
57           Indicate the end of the input stream.  All incomplete tokens will
58           be parsed and all remaining callbacks completed.
59
60       $parser->filename ($set)
61           Return (if $set is undefined) or set current filename.
62
63       $parser->lineno ($set)
64           Return (if $set is undefined) or set current line number.
65
66       $parser->parse ($string)
67           Parse the $string as verilog text.  Can be called multiple times.
68           Note not all callbacks may be invoked until the eof method is
69           called.
70
71       $parser->parse_file ($filename);
72           This method can be called to parse text from a file.  The argument
73           can be a filename or an already opened file handle. The return
74           value from parse_file() is a reference to the parser object.
75
76       $parser->parse_preproc_file ($preproc);
77           This method can be called to parse preprocessed text from a
78           predeclared Verilog::Preproc object.
79
80       $parser->unreadback ($string)
81           Return any input string from the file that has not been sent to the
82           callback.  This will include whitespace and tokens which did not
83           have a callback.  (For example comments, if there is no comment
84           callback.)  This is useful for recording the entire contents of the
85           input, for preprocessors, pretty-printers, and such.
86
87           With the optional argument, set the text to be returned with the
88           next unreadback call.  See also unreadbackCat, which is much
89           faster.
90
91           To use this option, "use_unreadback => 1" must have been passed to
92           the constructor.
93
94       $parser->unreadbackCat ($text)
95           Add text to be returned with the next unreadback call.  This is
96           much faster than using "$parser->unreadback($parser->unreadback .
97           $text)".
98

CALLBACKS

100       In order to make the parser do anything interesting, you must make a
101       subclass where you override one or more of the following callback
102       methods as appropriate.
103
104       $self->attribute ( $token )
105           This method is called when any text in (* *) are recognized.  The
106           first argument, $token, is the contents of the attribute including
107           the delimiters.
108
109       $self->comment ( $token )
110           This method is called when any text in // or /**/ comments are
111           recognized.  The first argument, $token, is the contents of the
112           comment including the comment delimiters.
113
114       $self->endparse ( $token )
115           This method is called when the file has been completely parsed, at
116           the End-Of-File of the parsed file.  It is useful for writing clean
117           up routines.
118
119       $self->keyword ( $token )
120           This method is called when any Verilog keyword is recognized.  The
121           first argument, $token, is the keyword.
122
123       $self->number ( $token )
124           This method is called when any number is recognized.  The first
125           argument, $token, is the number.  The
126           Verilog::Language::number_value function may be useful for
127           converting a Verilog value to a Perl integer.
128
129       $self->operator ( $token )
130           This method is called when any symbolic operator (+, -, etc) is
131           recognized.  The first argument, $token, is the operator.
132
133       $self->preproc ( $token )
134           This method is called when any Verilog preprocessor `command is
135           recognized.  Most of these are handled by the preprocessor, however
136           any unrecognized `defines are passed through.  For backward
137           compatibility, if not defined this function will call the symbol
138           callback.
139
140       $self->string ( $token )
141           This method is called when any text in double quotes are
142           recognized, or on the text of protected regions.  The first
143           argument, $token, is the contents of the string including the
144           quotes.
145
146       $self->symbol ( $token )
147           This method is called when any Verilog symbol is recognized.  A
148           symbol is considered a non-keyword bare-word.  The first argument,
149           $token, is the symbol.
150
151       $self->sysfunc ( $token )
152           This method is called when any Verilog $syscall is recognized.  The
153           first argument, $token, is the symbol.  For backward compatibility,
154           if not defined this function will call the symbol callback.
155

EXAMPLE

157       Here's a simple example which will print every symbol in a verilog
158       file.
159
160         package MyParser;
161         use Verilog::Parser;
162         @ISA = qw(Verilog::Parser);
163
164         # parse, parse_file, etc are inherited from Verilog::Parser
165         sub new {
166             my $class = shift;
167             #print "Class $class\n";
168             my $self = $class->SUPER::new();
169             bless $self, $class;
170             return $self;
171         }
172
173         sub symbol {
174             my $self = shift;
175             my $token = shift;
176
177             $self->{symbols}{$token}++;
178         }
179
180         sub report {
181             my $self = shift;
182
183             foreach my $sym (sort keys %{$self->{symbols}}) {
184                printf "Symbol %-30s occurs %4d times\n",
185                $sym, $self->{symbols}{$sym};
186             }
187         }
188
189         package main;
190
191         my $parser = MyParser->new();
192         $parser->parse_file (shift);
193         $parser->report();
194

BUGS

196       This is being distributed as a baseline for future contributions.
197       Don't expect a lot, the Parser is still naive, and there are many
198       awkward cases that aren't covered.
199
200       The parser currently assumes the string it is passed ends on a newline
201       boundary.  It should be changed to allow arbitrary chunks.
202
203       Cell instantiations without any arguments are not supported, an empty
204       set of parenthesis are required.  (Use "cell cell();", not "cell
205       cell;".)
206

DISTRIBUTION

208       Verilog-Perl is part of the <http://www.veripool.org/> free Verilog EDA
209       software tool suite.  The latest version is available from CPAN and
210       from http://www.veripool.org/verilog-perl
211       <http://www.veripool.org/verilog-perl>.
212
213       Copyright 2000-2009 by Wilson Snyder.  This package is free software;
214       you can redistribute it and/or modify it under the terms of either the
215       GNU Lesser General Public License Version 3 or the Perl Artistic
216       License Version 2.0.
217

AUTHORS

219       Wilson Snyder <wsnyder@wsnyder.org>
220

SEE ALSO

222       Verilog-Perl, Verilog::Preproc, Verilog::SigParser, Verilog::Language,
223       Verilog::Netlist, Verilog::Getopt, vrename, vpassert vppreproc
224
225
226
227perl v5.12.0                      2009-07-20                         Parser(3)
Impressum