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
Are the JSON arrays LL(1) parsable?
Yes, they are, since there's no ambiguity in the JSON grammar.
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
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.
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
Yes, it is LL(1) parsable. It has a context-free grammar and no ambiguity.
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_parser –
Foetus
array:
[] |
[ elements ]
elements:
value |
value , elements
it seems not LL(1)
to me. Clear cannot parse on "value"
© 2022 - 2024 — McMap. All rights reserved.