Skip to main content

VisualLangLab Grammars Now Even More Intuitive

Posted by sanjay_dasgupta on June 20, 2012 at 4:20 AM PDT

Earlier versions of VisualLangLab required the user to specify an alphanumeric name for all tokens. This made it difficult to understand rules using tokens without intuitive names. A good example is the rule infixOp from a Java grammar in Figure-1 below.

user-supplied names for tokens
Figure-1. Rule with non-intuitive token names

While PLUS and MINUS have good mnemonic value, many users will not understand TILDE and BANG. And the contrived names PLUS2 and MINUS2 will leave most users completely clueless. The AST does show the actual pattern, but this is not helpful in complex rules where the token-to-pattern association is not so obvious.

Starting version 10.37, tokens may use the pattern itself, enclosed in quote marks, as their name. Figure-2 below shows the same rule but with tokens using the new naming convention.

default-named tokens
Figure-2. Rule with new token-naming convention

Obviously, this makes the tokens far more understandable.

There are more examples in the complete grammar which you can read about in A Java7 Grammar for VisualLangLab. But if you are new to VisualLangLab, you may want to review Grammar Without Tears first. The grammar file itself is available as the file jls-se7-40.txt (which you should rename to jls-se7-40.vll before use).

The VisualLangLab documentation has been completely revised, and you can read all about the new token naming options in Editing the Grammar Tree.

Another article that uses VisualLangLab to work several examples from the book The Definitive ANTLR Reference can be read at A Quick Tour, and if you are interested in Scala parser combinators, then Scala Rapid Prototyping is a must read.

AttachmentSize
jls-se7-40.txt52.61 KB