Posted by sanjay_dasgupta
on June 20, 2012 at 4:20 AM PDT
VisualLangLab grammars are now even more intuitive. Earlier versions required all tokens to have a user-specified alphanumeric name that was displayed in the body of rules. Now, a token's pattern, enclosed in quote marks, can be used as the name.
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.
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.
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.