-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
firrtl does not have context free grammar (specification 0.2.0) #5
Comments
Thanks for writing this up and providing concrete use cases. This was discussed at the dev meeting today. There's no conclusion, yet, but people are amenable to either (in serialized form) always require @jackkoenig had a point that ingestion of protobuf would be an easier format to work with and is available now. However, it's not clear how cleanly this would integrate with Yosys. Two high-level goals were identified:
This will need a bit more discussion. |
I have been thinking about this problem again today and I believe that the following might be a good compromise between how easy firrtl is to parse and how nice it is to write and read.
so
becomes:
becomes
I am not sure if
Is there a bug where a firrtl producer does not properly enclose these into |
SystemVerilog defines its own notion of escaped identifiers (IEEE 1800-2017 §5.6.1):
While backticks would be nicer (IMO), adopting the same convention than SystemVerilog would make the translation of identifiers between the two languages much simpler. Would this be considered acceptable? |
I keep meaning to loop back to this issue. We've fixed all of this except for All classes of (2) are replaced with operations which can't alias with identifiers, e.g., For (3) I don't know if this was actually a problem at the time given that the string-encoded integer literals would be lexed as strings not as integer literals. The conversion to integer literal would then happen in parsing which is more acceptable to have some context sensitive information. That said, all the integers were converted to radix-specified integer literals which have a leading The one lingering thing is flip. However, that is likely easiest by moving the
This may be confusing as flip is not part of the type. However, that's a bit of a nit. |
Hello!
I'm currently writing a firrtl lexer/parser for yosys using flex/bison and am a bit stuck because
the grammar of firrtl is not context-free.
This is because firrtl allows an id to be a reserved firrtl keyword or an integer literal.
(an id can be named
mem
,inst
,b1
,h32
,o3
)Example of problems this causes:
field of bundle named with a keyword:
This makes it impossible to write the following grammar:
where
TOK_FLIP
is a token representing the keywordflip
,where
TOK_ID
is a token representing an id (= a string)The following bundle definition would fail this grammar:
id named after a keyword used by a stmt, e.g.
inst
(signal inst: UInt<1>
)The following context-free gammar does not apply, and the parser will fail.
where
TOK_INST
is a token representing the keywordinst
,where
TOK_ID
is a token representing an id (=string),where
TOK_OF
is a token representing the keywordof
,where
opt_info
is a rule that matches the optional@[""]
info.This is a problem because the grammar above conflicts with:
The lexer/parser does not know how to interpret the signal
inst
:When the lexer matches the string
inst
, should it interpret it asTOK_INST
or asTOK_ID
(with valueinst
)?id named that collides with the integer rules
e.g.
b1
should be interpreted as the string/nameb1
but it can also be interpreted as the 1-bit literal0b1
by the lexer.Root cause:
This is the same problem as Java/C++/python disallowing use of reserved keywords as variables.
That's why I propose to force escaping of reserved keywords by firrtl.
My proposal
LLVM IR requires variables to be prefixed by
%
, which would solve this problem completely.I believe firrtl was designed in the image of LLVM IR, so why not copy this property too?
It would make it much clearer when reading code that something is a keyword or an id:
The text was updated successfully, but these errors were encountered: