Package tar; Helpers tab = 9; cr = 13; lf = 10; eol = [[cr + lf] + [cr + lf]]; white = [[' ' + tab] + eol]; lowercase = ['a' .. 'z']; uppercase = ['A' .. 'Z']; letter = uppercase; digit = ['0'..'9']; id_part = lowercase (lowercase | digit)*; blank = (' ' | tab | eol)+; Tokens tar = 'tar'; id = id_part ('_' id_part)*; minus = '-'; semicolon = ';'; l_bkt = '['; r_bkt = ']'; letter = letter; blank = blank; Ignored Tokens /* These tokens are simply ignored by the parser. */ blank; /*****************/ Productions /*********************************************************************** The first production of this section must be transformed to the first production of Abstract Syntax Tree section but it is not necessary to explicitely specify it if it has the same name. So, in this case, we should write : grammar -> grammar but the software automatically do it when nothing is specified. So we have less things to do :-) ***********************************************************************/ /*#####*/ grammar = P.tar -> New grammar((P.tar.letter), (P.tar.id)); /*#####*/ /*********************************************************************** Here the production #tar# is supposed to be transformed to a list of #letter# followed by a list of #id#. Since the unique alternative of #options# is composed by token #tar#, production #options# and production #files#, we can get a list of letter by productions #options# transformations and a list of id by production #files# one's. As it can be notice here, there is no new statement in this transformation. So the 'New' statement is not needed in all cases. ***********************************************************************/ /*#####*/ tar -> letter* id* = T.tar options files -> (options.letter) (files.id); /*#####*/ /*********************************************************************** #options# is transformed to a list of letter. So the alternative transformation #(letter)# means that we created a new list in which we add all elements of #elem+# So there is no more #options# node in the AST. They are all transformed to lists of #letter#. ***********************************************************************/ /*#####*/ options -> letter* = minus letter+ -> (letter); /*#####*/ /*********************************************************************** This transformation is similar production #tar# transformation ***********************************************************************/ /*#####*/ files -> id* = file_name+ semicolon? -> (file_name.id) ; /*#####*/ /*********************************************************************** In this case, #file_name# is transformed to #id#. So we only get the already existing #id# from the unique alternative. ***********************************************************************/ file_name -> id = l_bkt id r_bkt -> id; /*****************/ Abstract Syntax Tree grammar = letter* id*;