Re: Lua syntax ambiguity

Halalaluyafail3 <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
The syntax is token based as far as I understand, so in t={[[[a]]]=true} it 
sees: punctuator {, string literal [[[a]], punctuator ], punctuator =, 
keyword true, and punctuator }. That does not meet the syntax so it is 
invalid.

On Sunday, August 16, 2026 at 10:25:12 AM UTC-4 Martin Eden wrote:

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/1a35c810-a4be-4697-86bf-454af3892e23n%40googlegroups.com.
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.