Lua syntax ambiguity

"'Martin Eden' via lua-l" <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
Ahoy list,

Let's say we're writing Lua code generator. He just applies grammar rules.

So let's take parts of Lua grammar and apply them.

   chunk ::= block

   block ::= {stat} [retstat]

   stat ::= varlist ‘=’ explist

   varlist ::= var {‘,’ var}

   var ::=  Name | prefixexp ‘[’ exp ‘]’

   explist ::= exp {‘,’ exp}

   exp ::=  false | true | LiteralString | prefixexp | tableconstructor

   prefixexp ::= var

   tableconstructor ::= ‘{’ [fieldlist] ‘}’

   fieldlist ::= field {fieldsep field} [fieldsep]

   field ::= ‘[’ exp ‘]’ ‘=’ exp

   fieldsep ::= ‘,’ | ‘;’

Problem is that "LiteralString" can start with "[" (long quotes).
And so when writing index in "field" we emit "[", then we go
to "exp" which may be "LiteralString" and we will emit another "[".

So we'll have text like "t={[[[a]]]=true}".

It's generated by perfectly abiding EBNF rules and greedy parser will
miserably fail on it.

I doubt there is a way to fix it by mangling EBNF grammar.
That's just consequence that character to open index is "[",
same character was chosen to start "long quotes", and table
index can be literal string.

-- Martin

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/c5e8a307-74a1-4446-a032-29ffc5560cae%40disroot.org.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.