PackCC | PackCC is a packrat parser generator for C | Parser library
kandi X-RAY | PackCC Summary
kandi X-RAY | PackCC Summary
PackCC is a packrat parser generator for C. Its defining features are:.
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 PackCC
PackCC Key Features
PackCC Examples and Code Snippets
Community Discussions
Trending Discussions on PackCC
QUESTION
I try to print an AST representation from the calculator example of PackCC.
I added a "Node" object and functions to write a dot file.
That seems to works correctly with '+' and '-' expressions, but the result is unexpected when I mix '+' and '*'.
Notice these two operations has different precedence levels if it can help you.
This is the grammar file.
...ANSWER
Answered 2021-May-30 at 08:25It's the way you walk the trees. You're not correctly identifying the parent node during your scan. As far as I can see, it has nothing to do with the parse (and hence packcc), and the results and the code I present below were created without using packcc or the grammar at all; I just created a few trees by hand using your node
function. That's usually a better way to debug, as well as being a better way to create minimal examples, because it helps clarify what is irrelevant to the problem (in this case, the parser, which is quite a lot of irrelevant code).
Here's what your function produces, with the correct lines on the right (produced with diff --side-by-side so that you can see the differences):
QUESTION
This is a minimal PackCC grammar example.
I try to retrieve and print the $$
value after parsing. The word is matched but only garbage is displayed by the printf
call.
ANSWER
Answered 2021-Feb-11 at 00:16There is no problem with your use of $$
, in the sense that the char *
value stored in $$
by the word
action is faithfully returned into val
.
The problem is that the char*
value is a pointer to dynamically-allocated memory, and by the time the parser returns that dynamically-allocated memory has already been freed. So the pointer returned into val
is a dangling pointer, and by the time printf
is called, the memory region has been been used for some other object.
The documention for PackCC, such as it is, does not go into any detail about its memory management strategy, so it's not really clear how long the $1
pointer in a rule is valid. I think it would be safest to assume that it is only valid until the end of the last action in the rule. But it is certainly not reasonable to assume that the pointer will outlast a call to pcc_parse
. After all, the parser has no way to know that you have stored the pointer outside of the parser context. The parser cannot rely on the programmer to free
capture strings produced during rules; having to free
every capture, even the ones never used, would be a sever inconvenience. To avoid memory leaks, the parser therefore must free
its capture buffers.
The problem is easy to see if you are able to use valgrind or some similar tool. (Valgrind is available for most Linux distributions and for OS X since v10.9.x. Other platforms might be supported.) Running your parser under valgrind produced the following error report (truncated):
QUESTION
I'm looking to write foos,bars,bazs by using a custom language in ctags. It works fine, I
can jump to the tag but I'm only allowed to have one unique tag name. I would
like to be able to jump through all the tags in different files with a tag named
todo1. Ctags is not generating more than one of the same tag name. If I fix this then the next question would be how to jump in vim to the same tag names? I presume :tn
probably would not work because I've tried having the same tag names in asciidoc in the past.
For example:
[todo1] This is something important in some/file/path/foo.txt
[todo1] This is something important in another/path/bar.txt
[foo] Some other foo.
My ctags config file is
...ANSWER
Answered 2021-Jan-17 at 17:56The answer is very simple yet many people don't know this so I'm going to post the answer so that it can help someone out in the future.
I'm not sure if ctags allows for same name tags but it's irrelevant. What you can do is generate your own tags as explained in :help tags-file-format
. This can be accomplished with a script containing less than 20 lines of code with a program like rip grep or you can use vimwiki plugin which implements this feature.
Here is an example of a simple tags file that jumps to bar:
QUESTION
I made a minimal example for Packcc parser generator. Here, the parser have to recognize float or integer numbers. I try to print the location of the detected numbers. For simplicity there is no line/column count, just the number from "ftell".
...ANSWER
Answered 2020-Sep-10 at 20:49Without looking more closely at the generated code, it would seem that the parser insists on reading the entire text into memory before executing any of the actions. That seems unnecessary for this grammar, and it is certainly not the way a typical generated lexical scanner would work. It's particularly odd since it seems like the generated scanner uses getchar
to read one byte at a time, which is not very efficient if you are planning to read the entire file.
To be fair, you wouldn't be able to use ftell
in a flex-generated scanner either, unless you forced the scanner into interactive mode. (The original AT&T lex, which also reads one character at a time, would give you reasonable value from ftell
. But you're unlikely to find a scanner built with it anymore.)
Flex would give you the wrong answer because it deliberately reads its input in chunks the size of its buffer, usually 8k. That's a lot more efficient than character-at-a-time reading. But it doesn't work for interactive environments -- for example, where you are parsing directly from user input -- because you don't want to read beyond the end of the line the user typed.
You'll have to ask whoever maintains packcc what their intended approach for maintaining source position is. It's possible that they have something built in.
QUESTION
I expect Packcc parser generator "$0s" or "$0e" variables to throw an int in the parser actions, because theses variables represents a position in the input.
I made a minimal parser that prints the position of the last char of the word.
...ANSWER
Answered 2020-Sep-13 at 18:15This looks like a bug in that version of the packcc parser generator. It is now fixed in master, so try upgrading.
Or you can simply ignore the warning as the type should indeed be int
.
QUESTION
I have a simple c++ file like this:
...ANSWER
Answered 2019-Sep-05 at 14:29You'll need either:
- to pass the right number to
:tag
& co, - or to use
:tselect
- or to use a plugin that'll help distinguish/select the overload you're interested in (like my old lh-tags plugin)
- or a more modern solution like a LSP server: lately I've found coc+ccls to be quite nice as it'll know from the context which is the exact overload under the cursor, which is impossible with tag based solutions.
QUESTION
I'm trying without success to build GNU Global with universal-ctags support. Is there something that I'm missing out on, or maybe I'm using incompatible versions of GNU Global and univeral-ctags? I'm doing this on Ubuntu 18.04.2 LTS (also tested on Ubuntu 16.04)
Official installation instructions
Other related information
- https://stackoverflow.com/a/15169556/5518304
- https://gist.github.com/carakan/60496e0f05033417be2352419639fcc5
In short I perform the following commands.
...ANSWER
Answered 2019-Aug-21 at 17:36I don't know why that is, but it happened to me as well. I found a workaround that I cannot explain (user error? bug?), by removing these lines from the gtags.conf file (in the one for universal-ctags|setting to use Universal Ctags plug-in parser
part):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PackCC
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