Questions tagged [peg]

A “Parsing Expression Grammar” (“PEG”) is a formal language to describe formal languages.

A Parsing Expression Grammar (“PEG”) is a formal language that defines a set of rules to describe a certain class of formal languages similar to context-free grammars.

In comparison to context-free grammars, PEGs have the advantage of always being unambiguous, and of mapping naturally to recursive descent parsers, which makes them easy to implement.

288 questions
0
votes
1 answer

How to replace newline followed by space in Parsley PEG grammar

all I'm learning Parsley by writing parser that parse vCard format. My problem is that some lines in vCard format may be split over several lines. Multiple-line representation using the RFC 822 “folding” technique. That is, wherever there may be…
0
votes
0 answers

Parse bitarray in python

I am using bitarrays in one of my projects to store the bits(reading from a file which has "0"s and "1"s, and time information which is required. File can also have not necessary fields like comments etc.). Now I want to parse the bits. I filter out…
user2109788
  • 1,266
  • 2
  • 12
  • 29
0
votes
1 answer

peg/leg - some curious behavior of PEG specification for expression parsing

Recently I was learning about Parsing Expression Grammars. After reading some materials on it by searching the web I finally sat down to make my hands dirty. I thought of implementing the hoc program from The Unix Programming Environment by…
Santanu
  • 113
  • 7
0
votes
1 answer

Parser doesn't stop parsing arbitrary newlines and whitespaces

So, I'm trying to write a very basic Lisp parser in pegjs and I got it to spit out the same code as long as the Lisp code was syntactically valid and fit on one line. I wish to extend the parser to be able to accept any newline character inserted…
Hassan Hayat
  • 1,056
  • 8
  • 20
0
votes
1 answer

Can explain what is necesariy the extra rule on this PEG

I'm playing with PEG.js and reading and in the Nathans University i found a good "explain" how to build my own languaje but i'm stuck with this step i dont understand the primary can explain me please start = comma comma = left: additive…
rkmax
  • 17,633
  • 23
  • 91
  • 176
0
votes
2 answers

Treetop ignore grammar rules

Treetop seems to ignore turther rules after the first and fails to parse anything that doesn't match the first rule on the grammar file. I already tried to swap the order of the rules, but still, only the first one is considered. #…
paul.ago
  • 3,904
  • 1
  • 22
  • 15
0
votes
1 answer

Why does pegjs fail to process the whitespace rule " "*

The following simple pegjs grammar works fine: start = sentence sentence = word ws sentence / word word = [a-z]* ws = " " It is available at http://jsfiddle.net/4V3Zt/ . The gramar can be also pasted into http://pegjs.majda.cz/online…
citykid
  • 9,916
  • 10
  • 55
  • 91
0
votes
0 answers

how can I parse an object definition like in coffeescript

let's say we have this in cofeescript obj = one: one: 11 two: 12 two: 2 three: four: 34 and that compiles to var obj = { one: { one: 11, two: 12 }, two: 2, three: { four: 34 } } so let's say I have this PEG.js grammar start =…
Theofilos Mouratidis
  • 1,146
  • 12
  • 32
0
votes
1 answer

PegJS: How to match a phrase in surrounding text

I'm tryingto make a parser with PegJS I'm trying to parse something like this.. I would like to email john@gmail.com today or tomorrow. How would you make a parser that matches on certain phrases, like email john@gmail.com and throw away the…
GN.
  • 8,672
  • 10
  • 61
  • 126
0
votes
1 answer

buffer overflow when using peg/leg

I'm using Ian Piumarta's peg/leg software to parse a toy language that I'm working on. Unfortunately some inputs to the parser are causing a crash that Clang's address sanitizer says is caused by a heap buffer overflow. Here's the output I get and…
jenga
  • 33
  • 4
0
votes
2 answers

PEGjs: Fallback (backtrack?) to string if floating point rule fail

I have an atom rule that tries to parse everything as either a number or a quoted string first, if that fails, then treat the thing as a string. Everything parses fine except one particular case that is this very specific string: DUD 123abc Which…
chakrit
  • 61,017
  • 25
  • 133
  • 162
0
votes
2 answers

pyPEG2: what is wrong with PEG grammar for 'f(x)'?

Yet another what is wrong with this grammar question: I am playing with pyPEG2 by Volker Birk and I am stuck with a very trivial case: from pypeg2 import * text = 'f(x)' grammar = name, '(' , word,')' print parse(text, grammar) The exception I am…
Yauhen Yakimovich
  • 13,635
  • 8
  • 60
  • 67
0
votes
1 answer

PEG grammar to parse optional content

Can anyone tell me how to write syntax on Treetop that supports both: system u AAA1 car=5, motor=4 and system u car=5, motor=4
Sokmesa Khiev
  • 2,910
  • 3
  • 19
  • 30
-1
votes
1 answer

Grammar parser for parsing parliamentary debates?

I'm looking to parse the plain text from a transcription tool (the goal is to render it into LegalDocML). My issue is that I do not know where to start and learning a grammar parser is quite a steep learning curve. I'm looking for guidance as to…
baradhili
  • 514
  • 1
  • 7
  • 27
-1
votes
1 answer

Some Information About PEG Needed

I'm interested in making computer languages recently. BNF & yacc made me crazy. Then I saw PEG, and I am attracted by its graceful.I want to learn more about it.The detail is: 1 how does PEG work (algorithm) 2 is there any tools about it on…
ljt12138
  • 35
  • 2
1 2 3
19
20