Are the JSON arrays LL(1) parsable?
Asked Answered
B

5

7

I've heard if you parse something LL(1) it's faster so I was wondering if you want to parse a JSON string can this be done by using a LL(1) parser

Breakaway answered 8/7, 2013 at 19:59 Comment(0)
W
2

Yes, they are, since there's no ambiguity in the JSON grammar.

Wightman answered 8/7, 2013 at 20:1 Comment(4)
In addition, you can check out my implementation which is hopefully not too difficult to understand.Wightman
While it's true that JSON is LL(1), this answer implies that all non-ambiguous grammars are LL(1). This is not correct. LL(1) grammars are a subset of the non-ambiguous grammars. For example, left-recursive grammars like "A -> A a | a" are not LL(1).Deflected
@JoshHaberman It is my understanding that simple transformations on a left-recursive grammer will make it LL(1).Sheldonshelduck
@JoshHaberman any reference tha JSON is LL(1)?Rhetorician
T
1

Yes, it is. See to yourself that the implementation of a parser for JSON string can be done with a automaton consisting of no more than 1 token. In other words, there exists a Markov chain solution for it.

Taperecord answered 24/10, 2018 at 19:41 Comment(0)
L
1

array:

[ ] | [ elements ]

elements:

value | value , elements

it seems not LL(1) to me. Clear cannot parse on "value"

What if this way?

array: [ array1 ]
array1: <eps> | elements
elements: value elements1
elements1: <eps> | , elements
Les answered 13/5, 2021 at 9:29 Comment(0)
P
0

Yes, it is LL(1) parsable. It has a context-free grammar and no ambiguity.

Pupa answered 8/7, 2013 at 20:1 Comment(2)
That doesn't make it LL(1).Foetus
A grammar is LL(1) if an LL(1) parser can be constructed for it. Not all unambiguous context-free grammars have LL(1) parsers. Sorry if I'm struggling a little here, but I'm not sure what else to say other than to direct you to the Wikipedia page for LL_parserFoetus
I
0

array:

[] |
[ elements ]

elements:

value |
value , elements

it seems not LL(1) to me. Clear cannot parse on "value"

Instinct answered 16/5, 2015 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.