Questions tagged [packcc]

This tag should be used for questions regarding the PackCC parser generator, which produces C language parsers using a PEG algorithm. If your question has to do with writing PEG grammars, you should also tag it with the peg tag.

According to its ReadMe file on GitHub, which appears to be the primary documentation for the product, PackCC builds packrat parsers in C, using a grammar syntax inspired by PEG. Unlike some PEG parser generators, it allows left recursion.

7 questions
2
votes
2 answers

How to get the cursor location during parsing?

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…
Ploumploum
  • 311
  • 1
  • 9
0
votes
1 answer

How to change PackCC input from stdin to a file?

I'm trying to get PackCC to parse contents from a file. I open the file, read its contents into a buffer, then pass that inward as an auxiliary value to the .peg file. static void parser_read(const char *contents, int mode) { FILE *fp =…
0
votes
1 answer

How to retrieve all matched rules from PackCC?

I'm working on a small parser with PackCC and am having a bit of trouble knowing what to do when a rule is matched n times, where n is unknown at compile time. Essentially, I use C actions to create an abstract syntax tree for a given rule, then add…
0
votes
1 answer

Why the parser actions, preceding an error, aren't performed?

This Packcc grammar is just a list of string litterals. When a syntax error is found actions are skipped even if the error is in the last term of the file. It is a problem because I want to compute the line/column location during the spaces…
Ploumploum
  • 311
  • 1
  • 9
0
votes
1 answer

How to use the "$$" value returned by a PackCC parser?

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. %value "char*" word <- < [a-z]+[\n]* > {$$ = $1;} %% int main(void) { …
Ploumploum
  • 311
  • 1
  • 9
0
votes
1 answer

How to fix GCC type warning on variable returned by the parser generator?

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. word <-…
Ploumploum
  • 311
  • 1
  • 9
0
votes
2 answers

PEG grammar to accept late definition

I want to write a PEG parser with PackCC (but also peg/leg or other libraries are possible) which is able to calculate some fields with variables on random position. The first simplified approach is the following grammar: %source { …
Achim
  • 442
  • 1
  • 3
  • 13