ovidiu      02/03/11 08:19:50

  Modified:    src/scratchpad/schecoon/src/org/apache/cocoon/flow flow.g
  Log:
  Updated.
  
  Revision  Changes    Path
  1.6       +155 -122  
xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/flow/flow.g
  
  Index: flow.g
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/flow/flow.g,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- flow.g    7 Mar 2002 02:12:08 -0000       1.5
  +++ flow.g    11 Mar 2002 16:19:50 -0000      1.6
  @@ -10,22 +10,33 @@
   
   options {
       k = 1;
  +    exportVocab=jWeave;  // Call its vocabulary "jWeave"
  +    buildAST = true;     // uses CommonAST by default
  +    codeGenMakeSwitchThreshold = 2;  // Some optimizations
  +    codeGenBitsetTestThreshold = 3;
   }
   
   tokens {
  -    DOT;
  +    DOT; MTHINVOKE; FUNCALL; ARRAYIDX; SEQ; RETURN; ARRAY; DICT; FUNCTION;
  +    PARAMS; VARARGS;
   }
   
  -exprs
  -    :   (expr)? SEMI exprs
  +program
  +    :   exprs EOF!
  +    ;
  +
  +exprs!
  +    :   ( e:expr (SEMI!)+
  +          {#exprs = #([SEQ], #exprs, #e);}
  +        )+
       ;
   
   expr
  -    :   assignment  // Simple expressions
  -    |   block       // A sequence of expressions
  -    |   function    // Function declaration
  -    |   varDecl     // Variable declaration
  -    |   "if" LPAREN expr RPAREN expr
  +    :   assignment
  +    |   block           // A sequence of expressions
  +    |   varDecl         // Variable declaration
  +    |   function        // Function declaration
  +    |   "if"^ LPAREN! expr RPAREN! expr
           (
                           // CONFLICT: the old "dangling-else" problem...
                           //           ANTLR generates proper code matching
  @@ -35,8 +46,12 @@
               }:
               "else" expr
           )?
  -    |   "return" expr
  -    |   "try" expr
  +
  +        // The following expressions should be rewritten using macros,
  +        // when they become available
  +    |!  "return"^ return:expr
  +        {#expr = #([RETURN], return); }
  +    |   "try"^ expr
           (
               // CONFLICT: Similar with the dangling else
               options {
  @@ -44,130 +59,135 @@
               }:
               handler
           )+
  -    |   "throw" expr
  -
  -        // The following expressions should be rewritten using macros,
  -        // when they become available
  -    |   "import" identifierStar
  -    |   "while" LPAREN expr RPAREN expr
  -    |   "switch" LPAREN expr RPAREN casesGroup
  -    |   "for" LPAREN exprList SEMI exprList SEMI exprList RPAREN expr
  -    |   "foreach" LPAREN IDENT "in" expr RPAREN expr
  -    |   "do" expr "while" LPAREN expr RPAREN
  +    |   "throw"^ expr
  +    |   "import"^ identifierStar
  +    |   "while"^ LPAREN! expr RPAREN! expr
  +    |   "switch"^ LPAREN! expr RPAREN! casesGroup
  +    |   "for"^ LPAREN! exprList SEMI! exprList SEMI! exprList RPAREN! expr
  +    |   "foreach"^ LPAREN! IDENT "in" expr RPAREN! expr
  +    |   "do"^ expr "while" LPAREN! expr RPAREN!
       ;
   
   exprList
  -    :   expr
  +    :   assignment
           (
               // CONFLICT: Similar with the dangling else
               options {
                   warnWhenFollowAmbig = false;
               }:
  -            COMMA expr
  +            COMMA! assignment
           )*
       ;
   
   // A function is either named or unnamed. A named function is //
   // equivalent to a variable declaration whose value is an unnamed
   // function.
  -function
  -    :   "function" (IDENT)? parameters block
  +function!
  +    :   "function"^ (n:IDENT)? p:parameters b:block
  +        {#function = #([FUNCTION, "function"], n, #([PARAMS], p), b);}
  +    ;
  +
  +parameters!
  +    :   LPAREN!
  +          (funParam (COMMA! funParam)*)?
  +          (v:"*args" {#parameters.addChild(#[VARARGS, "*args"]);})? 
  +        RPAREN!
       ;
   
  -parameters
  -    :   LPAREN (IDENT)* RPAREN
  +funParam
  +    :   IDENT (ASSIGN^ (IDENT|constant))?
       ;
   
   // A sequence of expressions. The value of the block is the value of
   // the last expression evaluated inside the block.
   block
  -    :   LCURLY exprs RCURLY
  +    :   LCURLY! exprs RCURLY!
       ;
   
   // Variable declaration
   varDecl
  -    :   "var" exprList
  +    :   "var"^ exprList
       ;
   
   casesGroup
  -        :       (       // CONFLICT: to which case group do the statements bind?
  -                        //           ANTLR generates proper code: it groups the
  -                        //           many "case"/"default" labels together then
  -                        //           follows them with the statements
  -                        options {
  -                                warnWhenFollowAmbig = false;
  -                        }
  -                        :
  -                        aCase
  -                )+
  -                caseSList
  -        ;
  +    :   (   // CONFLICT: to which case group do the exprs bind?
  +            //           ANTLR generates proper code: it groups the
  +            //           many "case"/"default" labels together then
  +            //           follows them with the exprs
  +            options {
  +                warnWhenFollowAmbig = false;
  +            }
  +        :
  +            aCase
  +        )+
  +        caseSList
  +    ;
   
   aCase
  -        :       ("case" expr | "default") COLON
  -        ;
  +    :   ("case" expr | "default") COLON!
  +    ;
   
   caseSList
  -        :       exprs
  -        ;
  +    :   exprs
  +    ;
   
   // Handler for a try expression
   handler
  -    :   "catch" LPAREN expr IDENT RPAREN expr
  +    :   "catch" LPAREN! expr IDENT RPAREN! expr
       |   "finally" expr
       ;
   
   identifierStar
       :   IDENT
  -        (DOT (IDENT|STAR))*
  +        (DOT! (IDENT|STAR))*
       ;
   
   assignment
       :   logicalOr
  -        (   (   ASSIGN
  -            |   PLUS_ASSIGN
  -            |   MINUS_ASSIGN
  -            |   STAR_ASSIGN
  -            |   DIV_ASSIGN
  -            |   MOD_ASSIGN
  -            |   BAND_ASSIGN
  -            |   BXOR_ASSIGN
  -            |   BOR_ASSIGN
  +        (   ( ASSIGN^
  +            | PLUS_ASSIGN^
  +            | MINUS_ASSIGN^
  +            | STAR_ASSIGN^
  +            | DIV_ASSIGN^
  +            | MOD_ASSIGN^
  +            | BAND_ASSIGN^
  +            | BXOR_ASSIGN^
  +            | BOR_ASSIGN^
               )
               assignment
           )?
       ;
   
   logicalOr
  -    :   logicalAnd (LOR logicalAnd)*
  +    :   logicalAnd (LOR^ logicalAnd)*
       ;
   
   logicalAnd
  -    :   inclusiveOr (LAND inclusiveOr)*
  +    :   inclusiveOr (LAND^ inclusiveOr)*
       ;
   
   inclusiveOr
  -    :   exclusiveOr (BOR exclusiveOr)*
  +    :   exclusiveOr (BOR^ exclusiveOr)*
       ;
   
   exclusiveOr
  -    :   and (BXOR and)*
  +    :   and (BXOR^ and)*
       ;
   
   and
  -    :   equality (BAND equality)*
  +    :   equality (BAND^ equality)*
       ;
   
   equality
  -    :   relational ((NOT_EQUAL | EQUAL) relational)*
  +    :   relational ((NOT_EQUAL^ | EQUAL^) relational)*
       ;
   
   relational
       :   additive
  -        (   (   (   LT
  -                |   GT
  -                |   LE
  -                |   GE
  +        (   (   ( LT^
  +                | GT^
  +                | LE^
  +                | GE^
                   )
                   additive
               )*
  @@ -175,24 +195,25 @@
       ;
   
   additive
  -    :   multiplicative ((PLUS | MINUS) multiplicative)*
  +    :   multiplicative ((PLUS^ | MINUS^) multiplicative)*
       ;
   
   multiplicative
  -    :   unary ((STAR | DIV | MOD) unary)*
  +    :   unary ((STAR^ | DIV^ | MOD^) unary)*
       ;
   
   unary
  -    :   INC unary
  -    |   DEC unary
  -    |   MINUS unary
  -    |   PLUS unary
  +    :   INC^ unary
  +    |   DEC^ unary
  +    |   MINUS^ unary
  +    |   PLUS^ unary
       |   unaryNotPlusMinus
  +    |   arrayOrDict
       ;
   
   unaryNotPlusMinus
  -    :   BNOT unary
  -    |   LNOT unary
  +    :   BNOT^ unary
  +    |   LNOT^ unary
       |   postfix
       ;
   
  @@ -200,40 +221,45 @@
       :   primary
           (
               // Array indexing
  -            LBRACK assignment RBRACK
  +            LBRACK! a:assignment RBRACK!
  +            {#postfix = #([ARRAYIDX], a);}
   
               // Method invocation
  -        |   DOT LPAREN exprList RPAREN
  +        |   DOT! LPAREN! ma:exprList RPAREN!
  +            {#postfix = #([MTHINVOKE], ma);}
   
               // Function invocation
  -        |   LPAREN exprList RPAREN
  +        |   LPAREN! fa:exprList RPAREN!
  +            {#postfix = #([FUNCALL], fa);}
           )*
       ;
   
   primary
       :   IDENT
       |   constant
  -    |   arrayOrDict
  -    |   "true"
  -    |   "false"
  -    |   "null"
  -    |   LPAREN assignment RPAREN
  +    |   LPAREN! assignment RPAREN!
       ;
   
   constant
       :   NUMBER
       |   CHAR_LITERAL
       |   STRING_LITERAL
  +    |   "true"
  +    |   "false"
  +    |   "null"
       ;
   
   // An array or a dictionary:
   //   [a, b, c] -> array
   //   [a: 1, b: 2, c: 3] -> dictionary
   // Use a syntactic predicate to disambiguate on ':'
  -arrayOrDict
  -    :   (LBRACK expr COLON)=>
  -        LBRACK expr COLON expr (COMMA expr COLON expr)* RBRACK
  -    |   LBRACK exprList RBRACK
  +arrayOrDict!
  +    :   (LBRACK! expr COLON!)=>
  +        LBRACK! key:expr COLON! value:expr
  +        (COMMA! keys:expr COLON! values:expr)* RBRACK!
  +        {#arrayOrDict = #([DICT, "dict"], key, value, ([DICT], keys, values));}
  +    |   LBRACK! elems:exprList RBRACK!
  +        {#arrayOrDict = #([ARRAY, "array"], elems);}
       ;
   
   
  @@ -242,56 +268,62 @@
   
   options {
       k = 2;
  +    exportVocab=jWeave;    // Call its vocabulary "jWeave"
       testLiterals=false;    // don't automatically test for literals
   }
   
  -QUESTION                :       '?'             ;
  -LPAREN                  :       '('             ;
  -RPAREN                  :       ')'             ;
  -LBRACK                  :       '['             ;
  -RBRACK                  :       ']'             ;
  -LCURLY                  :       '{'             ;
  -RCURLY                  :       '}'             ;
  -COLON                   :       ':'             ;
  -COMMA                   :       ','             ;
  -ASSIGN                  :       '='             ;
  +QUESTION                :       '?'     ;
  +LPAREN                  :       '('     ;
  +RPAREN                  :       ')'     ;
  +LBRACK                  :       '['     ;
  +RBRACK                  :       ']'     ;
  +LCURLY                  :       '{'     ;
  +RCURLY                  :       '}'     ;
  +COLON                   :       ':'     ;
  +COMMA                   :       ','     ;
  +ASSIGN                  :       '='     ;
   EQUAL                   :       "=="    ;
  -LNOT                    :       '!'             ;
  -BNOT                    :       '~'             ;
  +LNOT                    :       '!'     ;
  +BNOT                    :       '~'     ;
   NOT_EQUAL               :       "!="    ;
  -DIV                             :       '/'             ;
  +DIV                     :       '/'     ;
   DIV_ASSIGN              :       "/="    ;
  -PLUS                    :       '+'             ;
  +PLUS                    :       '+'     ;
   PLUS_ASSIGN             :       "+="    ;
  -INC                             :       "++"    ;
  -MINUS                   :       '-'             ;
  -MINUS_ASSIGN    :       "-="    ;
  -DEC                             :       "--"    ;
  -STAR                    :       '*'             ;
  +INC                     :       "++"    ;
  +MINUS                   :       '-'     ;
  +MINUS_ASSIGN            :       "-="    ;
  +DEC                     :       "--"    ;
  +STAR                    :       '*'     ;
   STAR_ASSIGN             :       "*="    ;
  -MOD                             :       '%'             ;
  +MOD                     :       '%'     ;
   MOD_ASSIGN              :       "%="    ;
  -GE                              :       ">="    ;
  -GT                              :       ">"             ;
  -LE                              :       "<="    ;
  -LT                              :       '<'             ;
  -BXOR                    :       '^'             ;
  +GE                      :       ">="    ;
  +GT                      :       ">"     ;
  +LE                      :       "<="    ;
  +LT                      :       '<'     ;
  +BXOR                    :       '^'     ;
   BXOR_ASSIGN             :       "^="    ;
  -BOR                             :       '|'             ;
  +BOR                     :       '|'     ;
   BOR_ASSIGN              :       "|="    ;
  -LOR                             :       "||"    ;
  -BAND                    :       '&'             ;
  +LOR                     :       "||"    ;
  +BAND                    :       '&'     ;
   BAND_ASSIGN             :       "&="    ;
   LAND                    :       "&&"    ;
  -SEMI                    :       ';'             ;
  +SEMI                    :       ';'     ;
   
   protected
  -PANYS   :   ('a'..'z'|'A'..'Z'|'@'|'#'|'$'|'_'|'?');
  +PANY    :   ('a'..'z'|'A'..'Z'|'_');
   
   protected
  -ANY     :   (PANYS|COLON|'0'..'9'|'!');
  +SPECIAL :   ('@'|'#'|'$');
   
  -IDENT   :   PANYS (ANY)* PANYS;
  +protected
  +ANY     :   (PANY|COLON|'0'..'9');
  +
  +IDENT
  +     options {testLiterals=true;}
  +        :   (PANY (ANY)*) | (SPECIAL (ANY)+);
   
   //
   // The following are stolen from java.g in the ANTLR distribution.
  @@ -299,14 +331,15 @@
   WS  :   (   ' '
           |   '\t'
           |   '\f'
  -        // handle newlines
  -        |   (   "\r\n"  // Evil DOS
  +            // handle newlines
  +        |   (   options {generateAmbigWarnings=false;}
  +            :   "\r\n"  // Evil DOS
               |   '\r'    // Macintosh
               |   '\n'    // Unix (the right way)
               )
               { newline(); }
  -        )
  -        { $setType(Token.SKIP); }
  +        )+
  +        { _ttype = Token.SKIP;}
       ;
   
   // Single-line comments
  @@ -412,7 +445,7 @@
   
   
   // a numeric literal
  -NUM_INT
  +NUMBER
       {boolean isDecimal=false;}
       :   '.' {_ttype = DOT;}
               (('0'..'9')+ (EXPONENT)? (FLOAT_SUFFIX)? { _ttype = NUMBER; })?
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to