org.opencores.verilogp
Class Parser

java.lang.Object
  |
  +--org.opencores.verilogp.Parser

public class Parser
extends java.lang.Object

Handwriten optimized LL(1) parser that reads data from stream and builds graph g.

Parser does not use standard parser or lexer builder, since the number of keyword is relatively small, and there is no need to parse complex objects. Only expression part is bit uglier. Java.io.StreamTokenizer is used instead.

NOTE: This parser accept only limited Verilog grammar, which should come out of design synthesis. - assign support only maxtern representation X->(X)|~X|X&X - only one module

- no tristate wires, etc

- no memory (e.g. reg [31:0] mem [16])


Field Summary
private  Dictionary d
          Dictionary of all names.
private  int expr_mark
          count for marking added nodes and nets
private  java.lang.String filename
          File name we are processing
private  Graph g
          currently built graph
private  int lsb
          [msb:lsb] from last readRange
private  int msb
          [msb:lsb] from last readRange
private  VTokenizer st
          Java's stream tokenizer.
 
Constructor Summary
Parser(java.lang.String filename)
          parses file and construct graph
 
Method Summary
private  void assimilate(Net np, Net nt)
          connects port's net np to net nt
private  java.lang.String errorPrefix()
          returns error prefix displayed
 Graph getGraph()
          returns newly built graph
private  void module()
          parses one module
private  void parse()
          parses whole file
private  void readASSIGN()
          processes ASSIGN statement
private  Net readExpr()
          Reads expression from the stream
private  Net readFinal()
          Reads final from the stream
private  void readIN_OUT(int dir)
          processes INPUT / OUTPUT statement
private  int readKeyword()
          expects keyword on input
private  void readKeyword(int k)
          expects keyword k on input
private  void readModule(java.lang.String name)
          reads module from file with same name
private  java.lang.String readNewWord()
          expects word on input
private  int readNumber()
          read number
private  java.lang.Object readParam()
          reads one module parameter
private  java.lang.Object readParamSimple()
          reads one module parameter inside () (no arrays {})
private  void readRange()
          reads [msb:lsb]
private  void readSym(int sym)
          expects sym on input
private  Net readTerminal()
          Reads terminal from the stream
private  void readWIRE()
          processes WIRE statement
private  java.lang.Object readWord()
          expects non-keyword on input
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

g

private Graph g
currently built graph

st

private VTokenizer st
Java's stream tokenizer.
See Also:
StreamTokenizer

d

private Dictionary d
Dictionary of all names.

filename

private java.lang.String filename
File name we are processing

expr_mark

private int expr_mark
count for marking added nodes and nets

msb

private int msb
[msb:lsb] from last readRange

lsb

private int lsb
[msb:lsb] from last readRange
Constructor Detail

Parser

public Parser(java.lang.String filename)
       throws java.io.IOException
parses file and construct graph
Parameters:
filename - file to read from
Method Detail

getGraph

public Graph getGraph()
returns newly built graph
Returns:
graph

parse

private void parse()
            throws java.io.IOException
parses whole file

module

private void module()
             throws java.io.IOException
parses one module

readParamSimple

private java.lang.Object readParamSimple()
                                  throws java.io.IOException
reads one module parameter inside () (no arrays {})

readParam

private java.lang.Object readParam()
                            throws java.io.IOException
reads one module parameter

readIN_OUT

private void readIN_OUT(int dir)
                 throws java.io.IOException
processes INPUT / OUTPUT statement

readWIRE

private void readWIRE()
               throws java.io.IOException
processes WIRE statement

readASSIGN

private void readASSIGN()
                 throws java.io.IOException
processes ASSIGN statement

readExpr

private Net readExpr()
              throws java.io.IOException
Reads expression from the stream
Returns:
net to assignment

readTerminal

private Net readTerminal()
                  throws java.io.IOException
Reads terminal from the stream
Returns:
net to assignment

readFinal

private Net readFinal()
               throws java.io.IOException
Reads final from the stream
Returns:
net to assignment

readRange

private void readRange()
                throws java.io.IOException
reads [msb:lsb]

readSym

private void readSym(int sym)
              throws java.io.IOException
expects sym on input

readWord

private java.lang.Object readWord()
                           throws java.io.IOException
expects non-keyword on input

readNewWord

private java.lang.String readNewWord()
                              throws java.io.IOException
expects word on input

readKeyword

private void readKeyword(int k)
                  throws java.io.IOException
expects keyword k on input

readNumber

private int readNumber()
                throws java.io.IOException
read number

readKeyword

private int readKeyword()
                 throws java.io.IOException
expects keyword on input

errorPrefix

private java.lang.String errorPrefix()
returns error prefix displayed

readModule

private void readModule(java.lang.String name)
                 throws java.io.IOException
reads module from file with same name

assimilate

private void assimilate(Net np,
                        Net nt)
connects port's net np to net nt