[antlr-interest] Smalltalk grammar

Adam Ainsworth aainsworth2000 at yahoo.co.uk
Mon Dec 31 03:47:53 PST 2007


Hi Fede,

Let me say that I'm by no means an expert in grammars or Antlr, I've just been playing around for the last couple of weeks, so please read the following with that in mind.

Firstly lexical rules which do not correspond to output tokens should be marked as fragments, e.g. "fragment Character : '\u0000'..'\uFFFE';" This is necessary to prevent these building blocks being incorrectly output as tokens.

Note that EBNF only allows simple cases of 'syntactic exception', where the set of exceptions could be replaced with a fixed set of strings. 

I think the first two cases in the smalltalk lexer rules can easily be handled in Antlr by ordering the lexical rules appropriately. For example ensure that ReservedIdentifier appears before Identifier and BindableIdentifier, and then 'self' will be recognised as a ReservedIdentifier.  There is then no need for the syntactic exception in the definition of BindableIdentifier.

However the third instance is much more complicated; here we have a lexer rule which references 2 parser rules for a start, which makes me think that the split between lexer and parser is not correct. There is no way to replace the syntactic exception with a set of strings, and therefore I do not think that this grammar is actually an EBNF grammar. I don't think there is a simple way to resolve this problem with the grammar, it needs a detailed analysis of what the grammar is trying to achieve here, which then needs restating in a correct grammar.

Another tricky problem with the lexer rules proposed on 'Smalltalk in One Page'  is that there is no way for the lexer to distinguish between a Reference and a BindableIdentifier. I suspect this is simply asking too much of the lexing phase, I think it would be more typical just to output identifiers at this stage, and leave classification of the identifiers until parsing, since it requires knowledge of the construct in which the identifier is being used.

These problems lead me to believe that this grammar has not been tested (i.e. used with any automated tool)  and some serious effort will be needed to get it working with Antlr or any other tool.

Regards,

Adam





      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/ 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071231/3f729da4/attachment.html 


More information about the antlr-interest mailing list