提交 9b59ec71 编写于 作者: 饶先宏's avatar 饶先宏

202105281750 parser开始编写语法说明

上级 bebefe39
......@@ -33,6 +33,8 @@ bld/
[Ll]og/
[Ll]ogs/
*.output
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
......
......@@ -7,11 +7,11 @@ project ("hdl4se")
# 包含子项目。
add_subdirectory ("preprocess")
# add_subdirectory ("parser")
add_subdirectory ("testpreprocess")
# add_subdirectory ("testparser")
add_subdirectory ("hdl4secell")
add_subdirectory ("hdl4sesim")
add_subdirectory ("bignumber")
add_subdirectory ("examples")
......@@ -2,30 +2,34 @@
cmake_minimum_required (VERSION 3.8)
add_library (verilog_parser STATIC
"verilog_ast.h"
"verilog_ast_common.h"
"verilog_ast_mem.h"
"verilog_keyword.c"
"verilog_module.c"
"verilog_module.h"
"verilog_parser.tab.c"
"verilog_parser.tab.h"
"verilog_parser.h"
"verilog_parser.c"
"verilog_parsetree.c"
"verilog_parsetree.h"
"verilog_parsetree.h"
"verilog_root.c"
"verilog_root.h"
"verilog_scanner.c"
"verilog_scanner.c"
"verilog_keyword.h")
include_directories("../../lcom/include")
include_directories("../hdl4secell/include")
include_directories("../bignumber/include")
include_directories("../parser")
include_directories("../preprocess/include")
include_directories("../preprocess/include")
add_custom_command(OUTPUT verilog_scanner.c
COMMAND flex ARGS ../../../../../hdl4se/parser/verilog_scanner.l
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/verilog_parser.c ${CMAKE_CURRENT_SOURCE_DIR}/verilog_parser.h
COMMAND bison ${CMAKE_CURRENT_SOURCE_DIR}/verilog_parser.y -o ${CMAKE_CURRENT_SOURCE_DIR}/verilog_parser.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/verilog_parser.y
)
add_custom_command(OUTPUT verilog_parser.tab.c verilog_parser.tab.h
COMMAND bison ARGS ../../../../../hdl4se/parser/verilog_parser.y)
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/verilog_scanner.c
COMMAND flex -o ${CMAKE_CURRENT_SOURCE_DIR}/verilog_scanner.c ${CMAKE_CURRENT_SOURCE_DIR}/verilog_scanner.l
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/verilog_scanner.l ${CMAKE_CURRENT_SOURCE_DIR}/verilog_parser.h
)
\ No newline at end of file
此差异已折叠。
/*!
@file verilog_ast_common.h
@brief Contains Declarations of value-independent data structures like
linked lists which are used in the ast.
*/
#include "stdarg.h"
#include "stdlib.h"
#include "string.h"
#include "verilog_ast_mem.h"
#ifndef VERILOG_AST_COMMON_H
#define VERILOG_AST_COMMON_H
// --------------- Linked List ------------------------
/*!
@defgroup ast-linked-lists Linked List
@{
@ingroup ast-utility
*/
//! Typedef for the ast_list_element_t
typedef struct ast_list_element_t ast_list_element;
/*!
@brief Storage container for a single element in the linked list.
*/
struct ast_list_element_t{
ast_list_element * next;
void * data;
};
/*!
@brief Container struct for the linked list data structure.
*/
typedef struct ast_list_t {
ast_list_element * head; //!< The "front" of the list.
ast_list_element * tail; //!< The "end" of the list.
ast_list_element * walker; //!< Used to "walk" along the list.
unsigned int items; //!< Number of items in the list.
unsigned int current_item; //! Current position of walker in list.
} ast_list;
/*!
@brief Creates and returns a pointer to a new linked list.
*/
ast_list * ast_list_new ();
/*!
@brief Frees the memory of the supplied linked list.
@note Does not free the memory of the data elements in the list, only
the list construct itself.
*/
void ast_list_free(ast_list * list);
/*!
@brief Adds a new item to the end of a linked list.
*/
void ast_list_append(ast_list * list, void * data);
/*!
@brief Adds a new item to the front of a linked list.
*/
void ast_list_preappend(ast_list * list, void * data);
/*!
@brief Finds and returns the i'th item in the linked list.
@details Returns a void* pointer. The programmer must be sure to cast this
as the correct type.
*/
void * ast_list_get(ast_list * list, unsigned int item);
/*!
@brief Removes the i'th item from a linked list.
*/
void ast_list_remove_at(ast_list * list, unsigned int i);
/*!
@brief concatenates the two supplied lists into one.
@param head - This will form the "front" of the new list.
@param tail - This will form the "end" of the new list.
@details This function takes all the elements in tail and appends them
to those in head. The tail argument is then released from memory, and the
original head pointer is returned, with all data items still in tact.
*/
ast_list * ast_list_concat(ast_list * head, ast_list * tail);
/*!
@brief Searches the list, returning true or false if the data item supplied is
contained within it.
@details Performs a *pointer* comparison. That is, if the internal list
pointer has the same address as the supplied data pointer, the item is
considered to be found.
*/
int ast_list_contains(
ast_list * list,
void * data
);
/*! @} */
// ----------------------- Stack --------------------------------------
/*!
@defgroup ast-stack Stack
@{
@ingroup ast-utility
*/
//! Typedef for the ast_stack_element_t
typedef struct ast_stack_element_t ast_stack_element;
/*!
@brief Storage container for a single element in the stack
*/
struct ast_stack_element_t{
ast_stack_element * next;
void * data;
};
//! A very simple stack.
typedef struct ast_stack_t{
unsigned int depth; //!< How many items are on the stack?
ast_stack_element * items; //!< The stack of items.
} ast_stack;
/*!
@brief Creates and returns a new stack object.
*/
ast_stack * ast_stack_new();
/*!
@brief Free the stack, but not it's contents
*/
void ast_stack_free(ast_stack * stack);
/*!
@brief Push a new item to the top of the stack.
@param [inout] stack - The stack to push to.
@param [in] item - The thing to push onto the stack.
*/
void ast_stack_push(
ast_stack * stack,
void * item
);
/*!
@brief Pop the top item from the top of the stack.
@param [inout] stack - The stack to pop from.
*/
void * ast_stack_pop(
ast_stack * stack
);
/*!
@brief Peek at the top item on the top of the stack.
@param [inout] stack - The stack to peek at
*/
void * ast_stack_peek(
ast_stack * stack
);
/*!
@brief Peek at the item *below* the top item on the top of the stack.
@param [inout] stack - The stack to peek into
*/
void * ast_stack_peek2(
ast_stack * stack
);
/*! @} */
// ----------------------- Hash Table ---------------------------------
/*!
@defgroup ast-hashtable Hash Table
@{
@ingroup ast-utility
@brief A *very* simple hash table implemented (for now) over a linked list.
@details This can be used for simple key-value pair storage. Current
access time is O(n) for a table with N elements in it.
@warning This is a *terrible* way to implement a hash table. It doesn't
even do any hashing!
@todo Re-implement over a proper hash table structure.
*/
/*! @} */
//! A single element in the hash table.
typedef struct ast_hashtable_element_t{
char * key; //!< The key for the element.
void * data; //!< The data associated with they key.
} ast_hashtable_element;
//! A hash table object.
typedef struct ast_hashtable_t{
ast_list * elements; //!< The items.
unsigned int size; //!< The number of elements in the table.
} ast_hashtable;
typedef enum ast_hashtable_result_e{
HASH_SUCCESS = 0,
HASH_FAIL = 1,
HASH_KEY_COLLISION = 2,
HASH_KEY_NOT_FOUND = 3
} ast_hashtable_result;
//! Creates and returns a new hashtable.
ast_hashtable * ast_hashtable_new();
//! Frees an existing hashtable, but not it's contents, only the structure.
void ast_hashtable_free(
ast_hashtable * table //!< The table to free.
);
//! Inserts a new item into the hashtable.
ast_hashtable_result ast_hashtable_insert(
ast_hashtable * table, //!< The table to insert into.
char * key, //!< The key to insert with.
void * value //!< The data being added.
);
//! Returns an item from the hashtable.
ast_hashtable_result ast_hashtable_get(
ast_hashtable * table, //!< The table to fetch from.
char * key, //!< The key of the data to fetch.
void ** value //!< [out] The data being returned.
);
//! Removes a key value pair from the hashtable.
ast_hashtable_result ast_hashtable_delete(
ast_hashtable * table, //!< The table to delete from.
char * key //!< The key to delete.
);
//! Updates an existing item in the hashtable.
ast_hashtable_result ast_hashtable_update(
ast_hashtable * table, //!< The table to update.
char * key, //!< The key to update with.
void * value //!< The new data item to update.
);
#endif
/*!
@file verilog_ast_mem.h
@brief Contains Declarations of datastructures and functions for helping to
manage dynamic memory allocation within the library.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#ifndef VERILOG_AST_MEM_H
#define VERILOG_AST_MEM_H
//! Typedef over ast_memory_T
typedef struct ast_memory_t ast_memory;
//! Stores information on some allocated memory as a linked list.
struct ast_memory_t{
size_t size; //!< Amount of memory allocated.
void * data; //!< Pointer to the allocated memory.
ast_memory * next; //!< Next element to be allocated.
};
//! Iterates over all allocated memory and frees it.
void ast_free_all();
//! Duplicates the supplied null terminated string.
char * ast_strdup(char * in);
/*!
@brief A simple wrapper around calloc.
@details This function is identical to calloc, but uses the head and
walker variables above to keep a linked list of all heap memory that the
AST construction allocates. This makes it very easy to clean up afterward
using the @ref ast_free_all function.
@param [in] num - Number of elements to allocate space for.
@param [in] size - The size of each element being allocated.
@returns A pointer to the start of the block of memory allocated.
*/
void * ast_calloc(size_t num, size_t size);
#endif
......@@ -36,6 +36,7 @@
*/
#include "verilog_keyword.h"
#include "verilog_parser.h"
#include "string.h"
#define DEFKEYWORD(id, n) {KW_##id, n}
......
......@@ -42,140 +42,139 @@ extern "C" {
#endif
#ifndef _ASMLANGUAGE
typedef enum verilog_keyword
{
KW_ALWAYS,
KW_AND,
KW_ASSIGN,
KW_AUTOMATIC,
KW_BEGIN,
KW_BUF,
KW_BUFIF0,
KW_BUFIF1,
KW_CASE,
KW_CASEX,
KW_CASEZ,
KW_CELL,
KW_CMOS,
KW_CONFIG,
KW_DEASSIGN,
KW_DEFAULT,
KW_DEFPARAM,
KW_DESIGN,
KW_DISABLE,
KW_EDGE,
KW_ELSE,
KW_END,
KW_ENDCASE,
KW_ENDCONFIG,
KW_ENDFUNCTION,
KW_ENDGENERATE,
KW_ENDMODULE,
KW_ENDPRIMITIVE,
KW_ENDSPECIFY,
KW_ENDTABLE,
KW_ENDTASK,
KW_EVENT,
KW_FOR,
KW_FORCE,
KW_FOREVER,
KW_FORK,
KW_FUNCTION,
KW_GENERATE,
KW_GENVAR,
KW_HIGHZ0,
KW_HIGHZ1,
KW_IF,
KW_IFNONE,
KW_INCDIR,
KW_INCLUDE,
KW_INITIAL,
KW_INOUT,
KW_INPUT,
KW_INSTANCE,
KW_INTEGER,
KW_JOIN,
KW_LARGE,
KW_LIBLIST,
KW_LIBRARY,
KW_LOCALPARAM,
KW_MACROMODULE,
KW_MEDIUM,
KW_MODULE,
KW_NAN,
KW_NEGEDGE,
KW_NMOS,
KW_NOR,
KW_NOSHOWCANCELLED,
KW_NOT,
KW_NOTIF0,
KW_NOTIF1,
KW_OR,
KW_OUTPUT,
KW_PARAMETER,
KW_PATHPULSE,
KW_PMOS,
KW_POSEDGE,
KW_PRIMITIVE,
KW_PULL0,
KW_PULL1,
KW_PULLDOWN,
KW_PULLUP,
KW_PULSESTYLE_ONEVENT,
KW_PULSESTYLE_ONDETECT,
KW_RCMOS,
KW_REAL,
KW_REALTIME,
KW_REG,
KW_RELEASE,
KW_REPEAT,
KW_RNMOS,
KW_RPMOS,
KW_RTRAN,
KW_RTRANIF0,
KW_RTRANIF1,
KW_SCALARED,
KW_SHOWCANCELLED,
KW_SIGNED,
KW_SMALL,
KW_SPECIFY,
KW_SPECPARAM,
KW_STRONG0,
KW_STRONG1,
KW_SUPPLY0,
KW_SUPPLY1,
KW_TABLE,
KW_TASK,
KW_TIME,
KW_TRAN,
KW_TRANIF0,
KW_TRANIF1,
KW_TRI,
KW_TRI0,
KW_TRI1,
KW_TRIAND,
KW_TRIOR,
KW_TRIREG,
KW_UNSIGNED,
KW_USE,
KW_VECTORED,
KW_WAIT,
KW_WAND,
KW_WEAK0,
KW_WEAK1,
KW_WHILE,
KW_WIRE,
KW_WOR,
KW_XNOR,
KW_XOR,
KW_NAND,
}verilog_keyword_t;
#if 0
#define KW_ALWAYS 128
#define KW_AND 129
#define KW_ASSIGN 130
#define KW_AUTOMATIC 131
#define KW_BEGIN 132
#define KW_BUF 133
#define KW_BUFIF0 134
#define KW_BUFIF1 135
#define KW_CASE 136
#define KW_CASEX 137
#define KW_CASEZ 138
#define KW_CELL 139
#define KW_CMOS 140
#define KW_CONFIG 141
#define KW_DEASSIGN 142
#define KW_DEFAULT 143
#define KW_DEFPARAM 144
#define KW_DESIGN 145
#define KW_DISABLE 146
#define KW_EDGE 147
#define KW_ELSE 148
#define KW_END 149
#define KW_ENDCASE 150
#define KW_ENDCONFIG 151
#define KW_ENDFUNCTION 152
#define KW_ENDGENERATE 153
#define KW_ENDMODULE 154
#define KW_ENDPRIMITIVE 155
#define KW_ENDSPECIFY 156
#define KW_ENDTABLE 157
#define KW_ENDTASK 158
#define KW_EVENT 159
#define KW_FOR 160
#define KW_FORCE 161
#define KW_FOREVER 162
#define KW_FORK 163
#define KW_FUNCTION 164
#define KW_GENERATE 165
#define KW_GENVAR 166
#define KW_HIGHZ0 167
#define KW_HIGHZ1 168
#define KW_IF 169
#define KW_IFNONE 170
#define KW_INCDIR 171
#define KW_INCLUDE 172
#define KW_INITIAL 173
#define KW_INOUT 174
#define KW_INPUT 175
#define KW_INSTANCE 176
#define KW_INTEGER 177
#define KW_JOIN 178
#define KW_LARGE 179
#define KW_LIBLIST 180
#define KW_LIBRARY 181
#define KW_LOCALPARAM 182
#define KW_MACROMODULE 183
#define KW_MEDIUM 184
#define KW_MODULE 185
#define KW_NAN 186
#define KW_NEGEDGE 187
#define KW_NMOS 188
#define KW_NOR 189
#define KW_NOSHOWCANCELLED 190
#define KW_NOT 191
#define KW_NOTIF0 192
#define KW_NOTIF1 193
#define KW_OR 194
#define KW_OUTPUT 195
#define KW_PARAMETER 196
#define KW_PATHPULSE 197
#define KW_PMOS 198
#define KW_POSEDGE 199
#define KW_PRIMITIVE 200
#define KW_PULL0 201
#define KW_PULL1 202
#define KW_PULLDOWN 203
#define KW_PULLUP 204
#define KW_PULSESTYLE_ONEVENT 205
#define KW_PULSESTYLE_ONDETECT 206
#define KW_RCMOS 207
#define KW_REAL 208
#define KW_REALTIME 209
#define KW_REG 210
#define KW_RELEASE 211
#define KW_REPEAT 212
#define KW_RNMOS 213
#define KW_RPMOS 214
#define KW_RTRAN 215
#define KW_RTRANIF0 216
#define KW_RTRANIF1 217
#define KW_SCALARED 218
#define KW_SHOWCANCELLED 219
#define KW_SIGNED 220
#define KW_SMALL 221
#define KW_SPECIFY 222
#define KW_SPECPARAM 223
#define KW_STRONG0 224
#define KW_STRONG1 225
#define KW_SUPPLY0 226
#define KW_SUPPLY1 227
#define KW_TABLE 228
#define KW_TASK 229
#define KW_TIME 230
#define KW_TRAN 231
#define KW_TRANIF0 232
#define KW_TRANIF1 233
#define KW_TRI 234
#define KW_TRI0 235
#define KW_TRI1 236
#define KW_TRIAND 237
#define KW_TRIOR 238
#define KW_TRIREG 239
#define KW_UNSIGNED 240
#define KW_USE 241
#define KW_VECTORED 242
#define KW_WAIT 243
#define KW_WAND 244
#define KW_WEAK0 245
#define KW_WEAK1 246
#define KW_WHILE 247
#define KW_WIRE 248
#define KW_WOR 249
#define KW_XNOR 250
#define KW_XOR 251
#define KW_NAND 252
#endif
int verilog_find_keyword_word(const char* ident);
#endif
#ifdef __cplusplus
}
#endif
......
此差异已折叠。
/* A Bison parser, made by GNU Bison 3.7. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
#ifndef YY_YY_VERILOG_PARSER_TAB_H_INCLUDED
# define YY_YY_VERILOG_PARSER_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* "%code requires" blocks. */
#line 24 "verilog_parser.y"
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#include "verilog_parsetree.h"
#include "verilog_ast.h"
#include "verilog_root.h"
#include "verilog_module.h"
#line 59 "verilog_parser.tab.h"
/* Token kinds. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
YYEMPTY = -2,
YYEOF = 0, /* "end of file" */
YYerror = 256, /* error */
YYUNDEF = 257, /* "invalid token" */
END = 258, /* END */
ANY = 259, /* ANY */
NEWLINE = 260, /* NEWLINE */
SPACE = 261, /* SPACE */
TAB = 262, /* TAB */
AT = 263, /* AT */
COMMA = 264, /* COMMA */
HASH = 265, /* HASH */
DOT = 266, /* DOT */
EQ = 267, /* EQ */
COLON = 268, /* COLON */
IDX_PRT_SEL = 269, /* IDX_PRT_SEL */
SEMICOLON = 270, /* SEMICOLON */
OPEN_BRACKET = 271, /* OPEN_BRACKET */
CLOSE_BRACKET = 272, /* CLOSE_BRACKET */
OPEN_SQ_BRACKET = 273, /* OPEN_SQ_BRACKET */
CLOSE_SQ_BRACKET = 274, /* CLOSE_SQ_BRACKET */
OPEN_SQ_BRACE = 275, /* OPEN_SQ_BRACE */
CLOSE_SQ_BRACE = 276, /* CLOSE_SQ_BRACE */
BIN_VALUE = 277, /* BIN_VALUE */
OCT_VALUE = 278, /* OCT_VALUE */
HEX_VALUE = 279, /* HEX_VALUE */
DEC_VALUE = 280, /* DEC_VALUE */
DEC_BASE = 281, /* DEC_BASE */
BIN_BASE = 282, /* BIN_BASE */
OCT_BASE = 283, /* OCT_BASE */
HEX_BASE = 284, /* HEX_BASE */
NUM_REAL = 285, /* NUM_REAL */
NUM_SIZE = 286, /* NUM_SIZE */
UNSIGNED_NUMBER = 287, /* UNSIGNED_NUMBER */
SYSTEM_ID = 288, /* SYSTEM_ID */
SIMPLE_ID = 289, /* SIMPLE_ID */
ESCAPED_ID = 290, /* ESCAPED_ID */
DEFINE_ID = 291, /* DEFINE_ID */
ATTRIBUTE_START = 292, /* ATTRIBUTE_START */
ATTRIBUTE_END = 293, /* ATTRIBUTE_END */
COMMENT_LINE = 294, /* COMMENT_LINE */
COMMENT_BLOCK = 295, /* COMMENT_BLOCK */
STRING = 296, /* STRING */
STAR = 297, /* STAR */
PLUS = 298, /* PLUS */
MINUS = 299, /* MINUS */
ASL = 300, /* ASL */
ASR = 301, /* ASR */
LSL = 302, /* LSL */
LSR = 303, /* LSR */
DIV = 304, /* DIV */
POW = 305, /* POW */
MOD = 306, /* MOD */
GTE = 307, /* GTE */
LTE = 308, /* LTE */
GT = 309, /* GT */
LT = 310, /* LT */
L_NEG = 311, /* L_NEG */
L_AND = 312, /* L_AND */
L_OR = 313, /* L_OR */
C_EQ = 314, /* C_EQ */
L_EQ = 315, /* L_EQ */
C_NEQ = 316, /* C_NEQ */
L_NEQ = 317, /* L_NEQ */
B_NEG = 318, /* B_NEG */
B_AND = 319, /* B_AND */
B_OR = 320, /* B_OR */
B_XOR = 321, /* B_XOR */
B_EQU = 322, /* B_EQU */
B_NAND = 323, /* B_NAND */
B_NOR = 324, /* B_NOR */
TERNARY = 325, /* TERNARY */
UNARY_OP = 326, /* UNARY_OP */
MACRO_TEXT = 327, /* MACRO_TEXT */
MACRO_IDENTIFIER = 328, /* MACRO_IDENTIFIER */
KW_ALWAYS = 329, /* KW_ALWAYS */
KW_AND = 330, /* KW_AND */
KW_ASSIGN = 331, /* KW_ASSIGN */
KW_AUTOMATIC = 332, /* KW_AUTOMATIC */
KW_BEGIN = 333, /* KW_BEGIN */
KW_BUF = 334, /* KW_BUF */
KW_BUFIF0 = 335, /* KW_BUFIF0 */
KW_BUFIF1 = 336, /* KW_BUFIF1 */
KW_CASE = 337, /* KW_CASE */
KW_CASEX = 338, /* KW_CASEX */
KW_CASEZ = 339, /* KW_CASEZ */
KW_CELL = 340, /* KW_CELL */
KW_CMOS = 341, /* KW_CMOS */
KW_CONFIG = 342, /* KW_CONFIG */
KW_DEASSIGN = 343, /* KW_DEASSIGN */
KW_DEFAULT = 344, /* KW_DEFAULT */
KW_DEFPARAM = 345, /* KW_DEFPARAM */
KW_DESIGN = 346, /* KW_DESIGN */
KW_DISABLE = 347, /* KW_DISABLE */
KW_EDGE = 348, /* KW_EDGE */
KW_ELSE = 349, /* KW_ELSE */
KW_END = 350, /* KW_END */
KW_ENDCASE = 351, /* KW_ENDCASE */
KW_ENDCONFIG = 352, /* KW_ENDCONFIG */
KW_ENDFUNCTION = 353, /* KW_ENDFUNCTION */
KW_ENDGENERATE = 354, /* KW_ENDGENERATE */
KW_ENDMODULE = 355, /* KW_ENDMODULE */
KW_ENDPRIMITIVE = 356, /* KW_ENDPRIMITIVE */
KW_ENDSPECIFY = 357, /* KW_ENDSPECIFY */
KW_ENDTABLE = 358, /* KW_ENDTABLE */
KW_ENDTASK = 359, /* KW_ENDTASK */
KW_EVENT = 360, /* KW_EVENT */
KW_FOR = 361, /* KW_FOR */
KW_FORCE = 362, /* KW_FORCE */
KW_FOREVER = 363, /* KW_FOREVER */
KW_FORK = 364, /* KW_FORK */
KW_FUNCTION = 365, /* KW_FUNCTION */
KW_GENERATE = 366, /* KW_GENERATE */
KW_GENVAR = 367, /* KW_GENVAR */
KW_HIGHZ0 = 368, /* KW_HIGHZ0 */
KW_HIGHZ1 = 369, /* KW_HIGHZ1 */
KW_IF = 370, /* KW_IF */
KW_IFNONE = 371, /* KW_IFNONE */
KW_INCDIR = 372, /* KW_INCDIR */
KW_INCLUDE = 373, /* KW_INCLUDE */
KW_INITIAL = 374, /* KW_INITIAL */
KW_INOUT = 375, /* KW_INOUT */
KW_INPUT = 376, /* KW_INPUT */
KW_INSTANCE = 377, /* KW_INSTANCE */
KW_INTEGER = 378, /* KW_INTEGER */
KW_JOIN = 379, /* KW_JOIN */
KW_LARGE = 380, /* KW_LARGE */
KW_LIBLIST = 381, /* KW_LIBLIST */
KW_LIBRARY = 382, /* KW_LIBRARY */
KW_LOCALPARAM = 383, /* KW_LOCALPARAM */
KW_MACROMODULE = 384, /* KW_MACROMODULE */
KW_MEDIUM = 385, /* KW_MEDIUM */
KW_MODULE = 386, /* KW_MODULE */
KW_NAN = 387, /* KW_NAN */
KW_NEGEDGE = 388, /* KW_NEGEDGE */
KW_NMOS = 389, /* KW_NMOS */
KW_NOR = 390, /* KW_NOR */
KW_NOSHOWCANCELLED = 391, /* KW_NOSHOWCANCELLED */
KW_NOT = 392, /* KW_NOT */
KW_NOTIF0 = 393, /* KW_NOTIF0 */
KW_NOTIF1 = 394, /* KW_NOTIF1 */
KW_OR = 395, /* KW_OR */
KW_OUTPUT = 396, /* KW_OUTPUT */
KW_PARAMETER = 397, /* KW_PARAMETER */
KW_PATHPULSE = 398, /* KW_PATHPULSE */
KW_PMOS = 399, /* KW_PMOS */
KW_POSEDGE = 400, /* KW_POSEDGE */
KW_PRIMITIVE = 401, /* KW_PRIMITIVE */
KW_PULL0 = 402, /* KW_PULL0 */
KW_PULL1 = 403, /* KW_PULL1 */
KW_PULLDOWN = 404, /* KW_PULLDOWN */
KW_PULLUP = 405, /* KW_PULLUP */
KW_PULSESTYLE_ONEVENT = 406, /* KW_PULSESTYLE_ONEVENT */
KW_PULSESTYLE_ONDETECT = 407, /* KW_PULSESTYLE_ONDETECT */
KW_RCMOS = 408, /* KW_RCMOS */
KW_REAL = 409, /* KW_REAL */
KW_REALTIME = 410, /* KW_REALTIME */
KW_REG = 411, /* KW_REG */
KW_RELEASE = 412, /* KW_RELEASE */
KW_REPEAT = 413, /* KW_REPEAT */
KW_RNMOS = 414, /* KW_RNMOS */
KW_RPMOS = 415, /* KW_RPMOS */
KW_RTRAN = 416, /* KW_RTRAN */
KW_RTRANIF0 = 417, /* KW_RTRANIF0 */
KW_RTRANIF1 = 418, /* KW_RTRANIF1 */
KW_SCALARED = 419, /* KW_SCALARED */
KW_SHOWCANCELLED = 420, /* KW_SHOWCANCELLED */
KW_SIGNED = 421, /* KW_SIGNED */
KW_SMALL = 422, /* KW_SMALL */
KW_SPECIFY = 423, /* KW_SPECIFY */
KW_SPECPARAM = 424, /* KW_SPECPARAM */
KW_STRONG0 = 425, /* KW_STRONG0 */
KW_STRONG1 = 426, /* KW_STRONG1 */
KW_SUPPLY0 = 427, /* KW_SUPPLY0 */
KW_SUPPLY1 = 428, /* KW_SUPPLY1 */
KW_TABLE = 429, /* KW_TABLE */
KW_TASK = 430, /* KW_TASK */
KW_TIME = 431, /* KW_TIME */
KW_TRAN = 432, /* KW_TRAN */
KW_TRANIF0 = 433, /* KW_TRANIF0 */
KW_TRANIF1 = 434, /* KW_TRANIF1 */
KW_TRI = 435, /* KW_TRI */
KW_TRI0 = 436, /* KW_TRI0 */
KW_TRI1 = 437, /* KW_TRI1 */
KW_TRIAND = 438, /* KW_TRIAND */
KW_TRIOR = 439, /* KW_TRIOR */
KW_TRIREG = 440, /* KW_TRIREG */
KW_UNSIGNED = 441, /* KW_UNSIGNED */
KW_USE = 442, /* KW_USE */
KW_VECTORED = 443, /* KW_VECTORED */
KW_WAIT = 444, /* KW_WAIT */
KW_WAND = 445, /* KW_WAND */
KW_WEAK0 = 446, /* KW_WEAK0 */
KW_WEAK1 = 447, /* KW_WEAK1 */
KW_WHILE = 448, /* KW_WHILE */
KW_WIRE = 449, /* KW_WIRE */
KW_WOR = 450, /* KW_WOR */
KW_XNOR = 451, /* KW_XNOR */
KW_XOR = 452, /* KW_XOR */
KW_NAND = 453 /* KW_NAND */
};
typedef enum yytokentype yytoken_kind_t;
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 35 "verilog_parser.y"
HOBJECT treenode;
char * string;
int token;
int operator;
IDListVar list;
#line 282 "verilog_parser.tab.h"
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_VERILOG_PARSER_TAB_H_INCLUDED */
此差异已折叠。
此差异已折叠。
%{
#include "verilog_parser.tab.h"
#include "verilog_parser.h"
#include "object.h"
#include "preprocess.h"
#include "verilog_preprocess.h"
#include "verilog_keyword.h"
static IPreprocess ** preprocess = NULL;
static char * __macroname = NULL;
int SetPreProcess(HOBJECT object)
{
return objectQueryInterface(object, IID_PREPROCESS, (const void **)&preprocess);
......@@ -23,89 +24,18 @@
#define EMIT_TOKEN(x) if (objectCall0(preprocess, SymbolEmitEnabled)) { return x; }
%}
%option outfile="verilog_scanner.c"
%option yylineno
%option nodefault
%option noyywrap
/* Pre-processor definitions */
CD_DEFAULT_NETTYPE "`default_nettype"
%x in_default_nettype
CD_LINE "`line"
%x in_line_1
%x in_line_2
%x in_line_3
%x in_line_4
CD_CELLDEFINE "`celldefine"
CD_DEFINE "`define"
CD_RESETALL "`resetall"
CD_ENDCELLDEFINE "`endcelldefine"
CD_ELSE "`else"
CD_ELSIF "`elsif"
CD_ENDIF "`endif"
CD_IFDEF "`ifdef"
CD_IFNDEF "`ifndef"
%x in_ifdef
%x in_ifndef
%x in_elseif
CD_UNDEF "`undef"
%x in_undef
CD_NOUNCONNECTED_DRIVE "`nounconnected_drive"
CD_UNCONNECTED_DRIVE "`unconnected_drive"
%x in_unconnected_drive
/* Include Directives */
CD_INCLUDE "`include"
%x in_include
/* Times and compiler directives */
CD_TIMESCALE "`timescale"
TIME_UNITS "(s|ms|us|ns|ps|fs)"
%x in_ts_1
%x in_ts_2
%x in_ts_3
/* Single character tokens */
NEWLINE "\n"|"\r\n"
SPACE " "
TAB "\t"
AT "@"
COMMA ","
HASH "#"
DOT "."
EQ "="
COLON ":"
IDX_PRT_SEL "+:"|"-:"
SEMICOLON ";"
OPEN_BRACKET "\("
CLOSE_BRACKET "\)"
OPEN_SQ_BRACKET "\["
CLOSE_SQ_BRACKET "\]"
OPEN_SQ_BRACE "{"
CLOSE_SQ_BRACE "}"
/* Tokens related to numbers */
EXP "e"|"E"
UNDERSCORE "_"
SIGN {PLUS}|{MINUS}
SIGN "+"|"-"
X "x"|"X"
Z "z"|"Z"|"?"
DOT "."
DIGIT_DECIMAL [0-9]
DIGIT_DECMIAL_NZ [1-9]
......@@ -140,25 +70,6 @@ NUM_UNSIGNED {DIGIT_DECIMAL}({UNDERSCORE}|{DIGIT_DECIMAL})*
SYSTEM_ID \$[a-zA-Z0-9_\$]+
SIMPLE_ID [a-zA-Z_][a-zA-Z0-9_$]*
ESCAPED_ID \\{SIMPLE_ID}
MACRO_IDENTIFIER `{SIMPLE_ID}
MACRO_TEXT .*\n
%x in_define
%x in_define_t
/* Attributes */
ATTRIBUTE_START \(\*
ATTRIBUTE_END \*\)
/* Comments */
COMMENT_LINE "//".*\n
COMMENT_BEGIN "/*"
COMMENT_END "*/"
%x in_comment
/* Strings */
......@@ -166,217 +77,70 @@ STRING \".*\"
/* Operators */
STAR "\*"
PLUS "+"
MINUS "-"
ASL "<<<"
ASR ">>>"
LSL "<<"
LSR ">>"
DIV "/"
POW "**"
MOD "%"
GTE ">="
LTE "<="
GT ">"
LT "<"
L_NEG "!"
L_AND "&&"
L_OR "||"
C_EQ "==="
L_EQ "=="
C_NEQ "!=="
L_NEQ "!="
B_NEG "~"
B_AND "&"
B_OR "|"
B_XOR "^"
B_EQU "^~"|"~^"
B_NAND "~&"
B_NOR "~|"
TERNARY "?"
%%
{ATTRIBUTE_START} {EMIT_TOKEN(ATTRIBUTE_START);}
{ATTRIBUTE_END} {EMIT_TOKEN(ATTRIBUTE_END);}
{COMMENT_LINE} {/*EMIT_TOKEN(COMMENT_LINE); IGNORE */}
{COMMENT_BEGIN} {BEGIN(in_comment); ;}
<in_comment>.|\n {/* IGNORE */}
<in_comment>{COMMENT_END} {BEGIN(INITIAL); }
{CD_CELLDEFINE} {/*verilog_preproc_enter_cell_define();*/}
{CD_ENDCELLDEFINE} {/*verilog_preproc_exit_cell_define();*/}
{CD_DEFAULT_NETTYPE} {BEGIN(in_default_nettype);}
<in_default_nettype>{SIMPLE_ID} {
objectCall3(preprocess, PreAction, PA_NETTYPE, yytext, "");
BEGIN(INITIAL);
}
{CD_TIMESCALE} {
BEGIN(in_ts_1);
}
<in_ts_1>{NUM_UNSIGNED} {
objectCall2(preprocess, SetParam, "timescale.scale", yytext);
}
<in_ts_1>{SIMPLE_ID} {
BEGIN(in_ts_2);
}
<in_ts_2>{DIV} {
BEGIN(in_ts_3);
}
<in_ts_3>{NUM_UNSIGNED} {
objectCall2(preprocess, SetParam, "timescale.precision", yytext);
}
<in_ts_3>{SIMPLE_ID} {
BEGIN(INITIAL);
}
{CD_RESETALL} {
/*verilog_preprocessor_resetall();*/
}
{CD_IFDEF} {
BEGIN(in_ifdef);
}
<in_ifdef>{SIMPLE_ID} {
objectCall3(preprocess, PreAction, PA_IFDEF, yytext, "");
BEGIN(INITIAL);
}
{CD_IFNDEF} {
BEGIN(in_ifndef);
}
<in_ifndef>{SIMPLE_ID} {
objectCall3(preprocess, PreAction, PA_IFNDEF, yytext, "");
BEGIN(INITIAL);
}
{CD_ELSIF} {
BEGIN(in_elseif);
}
<in_elseif>{SIMPLE_ID} {
objectCall3(preprocess, PreAction, PA_ELSEIFDEF, yytext, "");
BEGIN(INITIAL);
}
{CD_ELSE} {
objectCall3(preprocess, PreAction, PA_ELSE, "", "");
}
{CD_ENDIF} {
objectCall3(preprocess, PreAction, PA_ENDIF, "", "");
}
{CD_INCLUDE} {
BEGIN(in_include);
}
<in_include>{STRING} {
if (0 == objectCall3(preprocess, PreAction, PA_INCLUDE, yytext, "")) {
yypush_buffer_state(yy_create_buffer(stdin, YY_BUF_SIZE));
}
BEGIN(INITIAL);
}
{CD_LINE} {BEGIN(in_line_1);}
<in_line_1>{NUM_UNSIGNED} {BEGIN(in_line_2);}
<in_line_2>{STRING} {BEGIN(in_line_3);}
<in_line_3>{NUM_UNSIGNED} {BEGIN(INITIAL);}
{CD_NOUNCONNECTED_DRIVE} {
objectCall2(preprocess, SetParam, "nounconnected_drive", "NONE");
}
{CD_UNCONNECTED_DRIVE} {
BEGIN(in_unconnected_drive);
}
<in_unconnected_drive>{SIMPLE_ID} {
objectCall2(preprocess, SetParam, "nounconnected_drive", yytext);
BEGIN(INITIAL);
}
{CD_DEFINE} {
BEGIN(in_define);
}
<in_define>{SIMPLE_ID} {
__macroname = strdup(yytext);
BEGIN(in_define_t);
}
<in_define_t>{MACRO_TEXT} {
if(yyleng == 1)
{
// Macro has no value, and is just a newline character.
objectCall3(preprocess, PreAction, PA_DEFINE, __macroname, "");
}
else
{
objectCall3(preprocess, PreAction, PA_DEFINE, __macroname, yytext+1);
}
free(__macroname);
BEGIN(INITIAL);
}
{CD_UNDEF} {
BEGIN(in_undef);
}
<in_undef>{SIMPLE_ID} {
objectCall3(preprocess, PreAction, PA_UNDEF, yytext, "");
BEGIN(INITIAL);
}
{MACRO_IDENTIFIER} {
if (0 == objectCall3(preprocess, PreAction, PA_MACRO, (yytext)+1, "")) {
yypush_buffer_state(yy_create_buffer(stdin, YY_BUF_SIZE));
}
}
{AT} {EMIT_TOKEN(AT);}
{COMMA} {EMIT_TOKEN(COMMA);}
{HASH} {EMIT_TOKEN(HASH);}
{DOT} {EMIT_TOKEN(DOT);}
{EQ} {yylval.operator = OPERATOR_L_EQ; EMIT_TOKEN(EQ);}
{COLON} {EMIT_TOKEN(COLON);}
{IDX_PRT_SEL} {EMIT_TOKEN(IDX_PRT_SEL);}
{SEMICOLON} {EMIT_TOKEN(SEMICOLON);}
{OPEN_BRACKET} {EMIT_TOKEN(OPEN_BRACKET);}
{CLOSE_BRACKET} {EMIT_TOKEN(CLOSE_BRACKET);}
{OPEN_SQ_BRACKET} {EMIT_TOKEN(OPEN_SQ_BRACKET);}
{CLOSE_SQ_BRACKET} {EMIT_TOKEN(CLOSE_SQ_BRACKET);}
{OPEN_SQ_BRACE} {EMIT_TOKEN(OPEN_SQ_BRACE);}
{CLOSE_SQ_BRACE} {EMIT_TOKEN(CLOSE_SQ_BRACE);}
{STAR} { yylval.operator=OPERATOR_STAR ; EMIT_TOKEN(STAR);}
{PLUS} { yylval.operator=OPERATOR_PLUS ; EMIT_TOKEN(PLUS);}
{MINUS} { yylval.operator=OPERATOR_MINUS ; EMIT_TOKEN(MINUS);}
{ASL} { yylval.operator=OPERATOR_ASL ; EMIT_TOKEN(ASL);}
{ASR} { yylval.operator=OPERATOR_ASR ; EMIT_TOKEN(ASR);}
{LSL} { yylval.operator=OPERATOR_LSL ; EMIT_TOKEN(LSL);}
{LSR} { yylval.operator=OPERATOR_LSR ; EMIT_TOKEN(LSR);}
{DIV} { yylval.operator=OPERATOR_DIV ; EMIT_TOKEN(DIV);}
{POW} { yylval.operator=OPERATOR_POW ; EMIT_TOKEN(POW);}
{MOD} { yylval.operator=OPERATOR_MOD ; EMIT_TOKEN(MOD);}
{GTE} { yylval.operator=OPERATOR_GTE ; EMIT_TOKEN(GTE);}
{LTE} { yylval.operator=OPERATOR_LTE ; EMIT_TOKEN(LTE);}
{GT} { yylval.operator=OPERATOR_GT ; EMIT_TOKEN(GT);}
{LT} { yylval.operator=OPERATOR_LT ; EMIT_TOKEN(LT);}
{L_NEG} { yylval.operator=OPERATOR_L_NEG ; EMIT_TOKEN(L_NEG);}
{L_AND} { yylval.operator=OPERATOR_L_AND ; EMIT_TOKEN(L_AND);}
{L_OR} { yylval.operator=OPERATOR_L_OR ; EMIT_TOKEN(L_OR);}
{C_EQ} { yylval.operator=OPERATOR_C_EQ ; EMIT_TOKEN(C_EQ);}
{L_EQ} { yylval.operator=OPERATOR_L_EQ ; EMIT_TOKEN(L_EQ);}
{C_NEQ} { yylval.operator=OPERATOR_C_NEQ ; EMIT_TOKEN(C_NEQ);}
{L_NEQ} { yylval.operator=OPERATOR_L_NEQ ; EMIT_TOKEN(L_NEQ);}
{B_NEG} { yylval.operator=OPERATOR_B_NEG ; EMIT_TOKEN(B_NEG);}
{B_AND} { yylval.operator=OPERATOR_B_AND ; EMIT_TOKEN(B_AND);}
{B_OR} { yylval.operator=OPERATOR_B_OR ; EMIT_TOKEN(B_OR);}
{B_XOR} { yylval.operator=OPERATOR_B_XOR ; EMIT_TOKEN(B_XOR);}
{B_EQU} { yylval.operator=OPERATOR_B_EQU ; EMIT_TOKEN(B_EQU);}
{B_NAND} { yylval.operator=OPERATOR_B_NAND ; EMIT_TOKEN(B_NAND);}
{B_NOR} { yylval.operator=OPERATOR_B_NOR ; EMIT_TOKEN(B_NOR);}
{TERNARY} { yylval.operator=OPERATOR_TERNARY; EMIT_TOKEN(TERNARY);}
"@" {EMIT_TOKEN('@');}
"," {EMIT_TOKEN(',');}
"#" {EMIT_TOKEN('#');}
"." {EMIT_TOKEN('.');}
"=" {EMIT_TOKEN('=');}
":" {EMIT_TOKEN(':');}
";" {EMIT_TOKEN(';');}
"(" {EMIT_TOKEN('(');}
")" {EMIT_TOKEN(')');}
"[" {EMIT_TOKEN('[');}
"]" {EMIT_TOKEN(']');}
"{" {EMIT_TOKEN('{');}
"}" {EMIT_TOKEN('}');}
"+" {EMIT_TOKEN('+');}
"-" {EMIT_TOKEN('-');}
"*" {EMIT_TOKEN('*');}
"/" {EMIT_TOKEN('/');}
"%" {EMIT_TOKEN('%');}
">" {EMIT_TOKEN('>');}
"<" {EMIT_TOKEN('<');}
"!" {EMIT_TOKEN('!');}
"&" {EMIT_TOKEN('&');}
"|" {EMIT_TOKEN('|');}
"^" {EMIT_TOKEN('^');}
"~" {EMIT_TOKEN('~');}
"?" {EMIT_TOKEN('?');}
"(*" {EMIT_TOKEN(ATTRIBUTE_START);}
"*)" {EMIT_TOKEN(ATTRIBUTE_END);}
"<<<" {EMIT_TOKEN(ASL);}
">>>" {EMIT_TOKEN(ASR);}
"<<" {EMIT_TOKEN(LSL);}
">>" {EMIT_TOKEN(LSR);}
">=" {EMIT_TOKEN(GTE);}
"<=" {EMIT_TOKEN(LTE);}
"&&" {EMIT_TOKEN(L_AND);}
"||" {EMIT_TOKEN(L_OR);}
"==" {EMIT_TOKEN(L_EQ);}
"===" {EMIT_TOKEN(C_EQ);}
"!=" {EMIT_TOKEN(L_NEQ);}
"!==" {EMIT_TOKEN(C_NEQ);}
"^~" {EMIT_TOKEN(B_EQU);}
"~^" {EMIT_TOKEN(B_EQU);}
"~&" {EMIT_TOKEN(B_NAND);}
"~|" {EMIT_TOKEN(B_NOR);}
"+:" {EMIT_TOKEN(IDX_PRT_SEL);}
"-:" {EMIT_TOKEN(IDX_PRT_SEL);}
{BASE_DECIMAL} {BEGIN(in_dec_val); EMIT_TOKEN(DEC_BASE);}
{BASE_HEX} {BEGIN(in_hex_val); EMIT_TOKEN(HEX_BASE);}
......@@ -420,9 +184,9 @@ TERNARY "?"
{STRING} {yylval.string= _strdup(yytext);EMIT_TOKEN(STRING);}
<*>{NEWLINE} {/*EMIT_TOKEN(NEWLINE); IGNORE */ }
<*>{SPACE} {/*EMIT_TOKEN(SPACE); IGNORE */ }
<*>{TAB} {/*EMIT_TOKEN(TAB); IGNORE */ }
<*>"\n" {/*EMIT_TOKEN(NEWLINE); IGNORE */ }
<*>" " {/*EMIT_TOKEN(SPACE); IGNORE */ }
<*>"\t" {/*EMIT_TOKEN(TAB); IGNORE */ }
<<EOF>> {
......
cmake_minimum_required (VERSION 3.8)
add_executable (testparser "main.c")
target_link_libraries(testparser verilog_preprocess verilog_parser lcom)
include_directories("../../lcom/include")
include_directories("../preprocess/include")
include_directories("../parser")
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include "object.h"
#include "preprocess.h"
#include "verilog_preprocess.h"
#include "string.h"
int SetPreProcess(HOBJECT object);
int yylex();
int yyparse(void);
char* yytext;
int main(int argc, char* argv[])
{
IPreprocess** p;
preprocessVerilogCreate(&p);
objectCall1(p, AddIncludePath, "c:/tools/");
SetPreProcess(p);
objectCall2(p, SetFile, argv[1], 0);
yyparse();
objectRelease(p);
return 0;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册