bison | This package contains the GNU Bison parser generator | Parser library
kandi X-RAY | bison Summary
kandi X-RAY | bison Summary
This package contains the GNU Bison parser generator.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of bison
bison Key Features
bison Examples and Code Snippets
Community Discussions
Trending Discussions on bison
QUESTION
Take this minimized example
Critical place:
...ANSWER
Answered 2022-Mar-06 at 20:42This is because the bison_target
macro calls1 separate_arguments
on the value of the COMPILE_FLAGS
without using the new form that respects native shell rules (it just blindly replaces spaces with semicolons).
Unfortunately, the macro doesn't give you a chance to inject flags in a more modern way, either, so the best I could come up with was to use the variable_watch
command to hack at the internals of bison_target
, at least until this bug is fixed.
Here's a full example:
QUESTION
I'm attempting to write my own programming language at the moment, and I have the following simplified grammar:
...ANSWER
Answered 2022-Jan-06 at 03:03It's not really an ambiguity. As far as I can see, your language is unambiguous. However, the grammar is not deterministic when restricted to a single lookahead token.
The extremely useful counterexample generator does indeed describe the problem. When the parser sees the )
in let foo = (x)
it has to decide whether x
is a decl
or an expr_primary
. The answer will be obvious as soon as the second-next token is seen; if the )
is followed by ->
, then the parentheses contain a decl_list
; otherwise, the parentheses contain an expr
. So there's no ambiguity. But that doesn't necessarily help you :-)
LALR(2) grammars -- which is what you have -- are a perennial problem, and there are three basic strategies to solve them:
Use a GLR parser. This is certainly the easiest strategy; all it requires is to add
%glr-parser
to your parser declarations. (You might also need to update your bison version and possibly specify a different parser skeleton, depending on your bison version, if your semantic type is not compatible with C.) GLR parsers can parse any unambiguous grammar, regardless of how much lookahead might be required. The extra flexibility comes at a cost, but in the case of using GLR to parse an LALR(2) grammar, the cost is almost negligible.Note that even if you ask for a GLR parser, Bison will still report the conflict, on the assumption that you wanted to know about it. But it no longer matters, because the GLR parser can handle multiple possible parses at the same time, as long as the grammar is (eventually) unambiguous. Bison pretty well has to report the conflict, because a conflict could be the result of an ambiguity, in which case you'd need to do something. You can suppress the report using an
%expect-rr
declaration.There is no algorithm which can tell whether an arbitrary grammar is ambiguous. Bison does its best with the counterexamples report, but it doesn't always work and it certainly doesn't always indicate an ambiguity. But if the grammar happens to not be ambiguous, a GLR parser will work.
With GLR parsers, ambiguity is reported as a run-time error. That's maybe not ideal, but since there is no way to tell in advance, that's the best you can do. Other GLR parser generators will return both (or all) possible parses, which you can do with Bison using a custom ambiguity resolver, but in practical applications you generally want the grammar to be unambiguous. If Bison reports a conflict, you should test the parser with relevant inputs and ensure that it doesn't fail with an ambiguity message.
Change the grammar so that it's LALR(1). This is always possible because every LR(k) language has an LALR(1) grammar. There's even a (fairly) simple algorithm which can be used to convert an LALR(k) grammar into an LALR(1) grammar provided that
k
has a known value. Unfortunately, the algorithm produces enormous grammars, which become extremely hard to maintain. (I guess that would be OK if bison came with an automatic rewriter, but it doesn't.) So you'd probably be better off trying to rejig the grammar by hand, which isn't too awful because there's only one conflict which requires two lookahead tokens and you already know what it is.The rough outline of a solution goes like this:
The problem is that the parser can't tell what
( IDENTIFIER )
is until it sees the next token. So all we need to do is make it unnecessary for the parser to perform a unit reduction on that particularIDENTIFIER
. To do that, we can create a redundant non-terminal and add productions which use it:
QUESTION
I am creating a compiler for a C-like language using yacc/bison, flex, and the LLVM toolchain (LLVM 12) using the LLVM C++ API. I have been developing and testing on Ubuntu version 20.04.3 LTS (Focal Fossa) and macOS 11.6 Big Sur. Currently, the issue is the program segfaulting when exiting the program when a method declaration has method parameters such as simply:
...ANSWER
Answered 2021-Dec-16 at 00:10Solution:
The problem was in lines of code not included. llvm::Function::Create
requires an llvm::FunctionType
which can be provided by filling a vector with llvm::Type*
objects. I wrote a function to do this:
QUESTION
I am trying to write a reentrant C++ parser with bison, I followed the Complete C++ Example and I am using bison 3.5.1 and flex 2.6.4 (the versions available via apt-get in ubuntu buster).
After completing I had an issue in the lexer
‘make_YYEOF’ is not a member of ‘yy::parser’
My solution to that was to declare %token YYEOF
Then it compiles but the parser gives the syntax error, unexpected YYEOF, expecting $end
, for an apparently valid input.
Then I made the simplified rule unit: IDENTIFIER YYEOF
but again, the parser reports the same error.
ANSWER
Answered 2021-Nov-25 at 20:09That problem is solved by declaring
QUESTION
I'm trying to make two List
components: one of them is static and small, the second is incredibly large and dynamic. In the first List
I store food categories: Alcoholic products, Soups, Cereals, etc. In the second List
, the word is searched directly from the database - it can be anything: a dish or a category of dishes. Below is the code - it displays the start page. Initially, the first static and small List
is located on it, as well as the Search component (Navigationview.seacrhable()
). When you type a word into the search bar, the first List
disappears and the second one appears. At the moment, both sheets are loaded asynchronously. This is necessary because the second sheet is really big (thousands of rows). This is where my problem begins. Sometimes, when you type a word into the search bar, a copy of this sheet appears on top of it, as shown in the image. It only happens for a fraction of a second, but it's still noticeable. The problem is most likely due to asynchronous loading, before I added it, the List
was loading super slowly, but without such bugs.
My minimal reproducible example:
ContentView.sfiwt
Main List, displaying the food categories available for selection.
...ANSWER
Answered 2021-Nov-19 at 22:27Besides using id
for the IDs, as mentioned in the comments, you can do some refactoring to get SwiftUI to not re-render as much of the view hierarchy and instead reuse components. For example, you have an if
condition and in each you have separate Section
, ForEach
, etc components. Instead, you could render the content of the ForEach
based on the state of the search:
QUESTION
I am getting ready to submit an R package to CRAN and I am working through one final note from R CMD check. The note is that I have a reference to stdout. The "Writing R Extensions" manual has this to say about the problem:
Compiled code should not write to stdout or stderr and C++ and Fortran I/O should not be used. As with the previous item such calls may come from external software and may never be called, but package authors are often mistaken about that.
In all of my code I have made sure to call Rprintf or REprintf when I need to write something, but I have one more place where I can't make this switch: generated code from Flex.
I use GNU Flex/Bison to parse a DSL and Flex has its own pointers and references it uses for things like writing to stdout. Specifically, it has what it calls yyout
which I can overwrite with the yyout_set
function. Great! But what do I set it to?
The problem I have is that I can't change the (generated) C code to call REprintf, but I can't figure out if R exports a FILE *
I can use to overwrite yyout
. I tried digging around the R source code but I couldn't figure out where to look.
Is there a FILE *
that I can use to write to the R console? If not, is there a sometimes acceptable solution? I haven't ever submitted a package to CRAN, but my impression is that this will not pass muster.
ANSWER
Answered 2021-Nov-16 at 15:40I have a two part solution to this problem that seems to do the trick. Please note, I am using re-entrant options for Flex/Bison, so this might not work exactly the same for everyone.
I defineECHO
to use Rprintf
in the preamble of my lexer code.
I actually already had code to define YY_FATAL_ERROR
so I added the ECHO code to that. I added the following code to the preamble of my .l
file:
QUESTION
I'm just starting with Flex/Bison and I'm trying to translate pascal-look-alike variables declarations like this:
...ANSWER
Answered 2021-Nov-12 at 12:29For more informative error strings you need %error-verbose
in yacc file. Perhaps like that in your file:
QUESTION
I am facing a problem with rules that with long look ahead
Take as an example a parser that consumes integer or fractions, also the fractions have no GAP
s in the numerator (however it may have GAP
s between the numerator and the SLASH
)
The regular expression [0-9_ ]*?([0-9]+\/[0-9_ ]+)|[0-9_ ]+
describes the valid inputs
you can check some examples here.
Here is one way to write it
...ANSWER
Answered 2021-Nov-08 at 22:29The basic problem is that you've split digit sequences with gaps and digit sequences without gaps into two independent rules, which means you need to decide which you're going to match first, which requires (possibly unbounded) lookahead to decide which to match.
The solution is generally to match tokens "bottom up" -- single rule for each thing independent of context, and build up lookahead-dependent things from that. In you case, that means building up IntegerToken
from DigitStar
rather than from DIGIT
directly -- an input of digits will be recognized as a DigitStar
and only when you get to the end of it (and see the non-digit) do you need to decide what it is.
The problem is that the obvious fix for your grammar (changing IntegerToken: DIGIT | GAP
to DigitStar | GAP
) doesn't work because it makes IntegerTokenStar
(and -Plus
) ambigous as any sequence of 2 or more digits might be any number of DigitStar
tokens. So you need to rewrite this to make sure you can't have two consecutive DigitStar
tokens, which turns out to be quite tricky. Your really need to rethink things "bottom up" -- the input is a sequence of alternating numbers (1+ digits each) and gaps (1+ spaces), with an optional single /
that can appear directly between two numbers (no gaps) or a number and a gap (no gap before the /
). So you get rules that look more like:
QUESTION
I am trying to compile CFortranTranslator in Visual Studio 2015.
Getting the following error:
...ANSWER
Answered 2021-Oct-27 at 22:49Open the file:
QUESTION
I am trying to recreate the indexOf function in JavaScript. I can not get the return -1 portion to work, but the other parts work fine. It seems like the end of my for loop is not running, as I try to print out "end of loop". I have some test code as well and the outputs below. Any help would be appreciated.
...ANSWER
Answered 2021-Oct-07 at 20:50In the last test case you are not sending a second argument to the function, so it is the first part of the if-else that will run - the if
part. There is no return -1
in that part.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bison
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page