www.pudn.com > cppcc.rar > verilog.cg
/* -*-c-*- */
/*
* File: verilog.cg
* $Id: verilog.cg,v 1.4 2002/07/09 08:54:51 alec Exp $
*
* Author: Alec Panoviciu (alecu@email.com)
*
* Comments:
*
* Revision history:
*
* $Log: verilog.cg,v $
* Revision 1.4 2002/07/09 08:54:51 alec
* 0.0.3 stuff
*
* Revision 1.3 2002/07/09 03:04:58 alec
* OWN_STRINGS bu*beep*it finally vanished
* gcc 3.1&mingw - related cleanups
*
* Revision 1.2 2002/06/23 23:47:59 alec
* sync
*
* Revision 1.1 2002/06/02 14:40:31 alec
* *** empty log message ***
*
*/
/*
* This file is Public Domain software. Use it as you wish and in good
* health.
*/
/*
* This is a "structural" Verilog parser. It is suitable (and very good at
* that - read fast).
*
* A summary of the constructs it knows would be:
* - nets
* - rages (only literal constants are accepted as range limits)
* - ports
* - module instances (no primitives). Both positional and names port
* connections are allowed.
*/
OPTIONS
{
// DEBUG_SCANNER = true;
// USE_EXCEPTIONS = false;
// OWN_STRINGS = false; DEPRECATED !
//COUNT_COLUMNS = true;
PROFILING_FILE = "profile.dat";
}
TOKEN VlogToken
{}
SCANNER VlogScanner
{
/*
* Comments, whitespaces, strings, new line handling.
*/
SKIP
{
{ newLine(); }
}
MORE
{
{ pushState(LONG_COMMENT); }
}
MORE
{
{ newLine(); }
}
SKIP
{
{ popState(); }
}
/*
* These are the keywords (See Annex. B)
*/
KEYWORD
{
}
/*
* Identifiers.
*/
TOKEN
{
<#SIMPLE_IDENTIFIER: ['a'-'z','A'-'Z','_']['a'-'z','A'-'Z','_','$','0'-'9']* >
<#ESCAPED_IDENTIFIER: "\\"~['\n','\r',' ','\t']* >
| >
>
}
/*
* Operators. This will need to be refined when doing actual parsing.
*/
TOKEN
{
','|','^'] | "==" | "!=" | "===" | "!==" | "&&" | "||" | "<=" | ">=" | "^~" | "~^" | ">>" | "<<" >
}
/*
* Preprocessing stuff. Just to make it pass through the scanner, its
* defiently worthless for anything else.
*/
TOKEN
{
}
/*
* Numbers.
*/
TOKEN
{
<#HEX_DIGIT: ['x','X','z','Z','?','0'-'9','a'-'f','A'-'F'] >
<#DECIMAL_DIGIT: ['x','X','z','Z','?','0'-'9'] >
<#OCTAL_DIGIT: ['x','X','z','Z','?','0'-'7'] >
<#BINARY_DIGIT: ['x','X','z','Z','?','0'-'1'] >
<#HEX_BASE: "\'h"|"\'H">
<#DECIMAL_BASE: "\'d"|"\'D">
<#OCTAL_BASE: "\'o"|"\'O">
<#BINARY_BASE: "\'b"|"\'B">
<#UNSIGNED_NUMBER: ("_" | )* >
<#SIZE: >
<#SIGN: ['+','-'] >
? ("_" | )* >
? )
| ( ? ) >
? ("_" | )* >
? ("_" | )* >
? "." )
| ( ? ("." )?
['e', 'E'] ? ) >
}
/* STRING LITERALS */
TOKEN
{
// i am not sure whether this string is good, as the std
// does not seem to define escape sequences. i just accept
// here \letter (no octals yet).
// the std dose not accept multiline strings with excaped
// eol as C
}
}
PARSER VlogParser
{
/**************************** SOURCE TEXT ************************/
(void) sourceText ()
{
description() *
}
(void) description ()
{
moduleDeclaration()
}
(void) moduleDeclaration ()
{
listOfPorts()?
moduleItem()*
}
(void) listOfPorts ()
{
port() ( port())*
}
(void) port ()
{
portExpression()
| portExpression()
}
(void) portExpression ()
{
portReference()
| portReference() ( portReference() )*
}
(void) portReference ()
{
( constantExpression()
( constantExpression() )? )?
}
(void) moduleItem ()
{
moduleItemDeclaration()
| moduleInstantiation()
}
(void) moduleItemDeclaration ()
{
inputDeclaration()
| outputDeclaration()
| inoutDeclaration()
| netDeclaration()
}
/************************** DECLARATIONS ****************************/
(void) inputDeclaration ()
{
range() ? listOfPortIdentifiers()
}
(void) outputDeclaration ()
{