All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javacc-7.0.4.grammars.ExpressParser.jj Maven / Gradle / Ivy

The newest version!
/***************************************************************************************************************************************
** DESCRIPTION: EXPRESS Grammar and Scanner to be used with JavaCC
** FILENAME:    ExpressParser.jj
** DATE:        MAR 1998 -                 (Initial grammar)
** UPDATE:	OCT 1998 -   (Production 294 correction)
** 
** Contributed by Jason Goodman - [email protected]
*************************************************************************************************************************************/

options {
        LOOKAHEAD = 2;
        STATIC = false;
}

PARSER_BEGIN(ExpressParser)

public class ExpressParser{

        
        // 
        // MAIN class used for command line parsing
        //
        public static void main(String args[]) {
                
                ExpressParser parser;
                                
                if (args.length == 0) {
                        System.out.println("ExpressParser:  Reading from standard input . . .");
                        parser = new ExpressParser(System.in);
                } 
                else if (args.length == 1) {
                        System.out.println("ExpressParser:  Reading from file " + args[0] + " . . .");
                        try {
                                parser = new ExpressParser(new java.io.FileInputStream(args[0]));
                        } 
                        catch (java.io.FileNotFoundException e) {
                                System.out.println("Express Parser:  File " + args[0] + " not found.");
                                return;
                        }                       
                } 
                else {
                        System.out.println("ExpressParser:  Usage is one of:");
                        System.out.println("         java ExpressParser < inputfile");
                        System.out.println("OR");
                        System.out.println("         java ExpressParser inputfile");
                        return;
                }
                try {
                        
                        parser.syntax();
                                System.out.println("ExpressParser: source parsed successfully.");
                } 
                catch (ParseException e) {
                        System.out.println(e.getMessage());
                        System.out.println("ExpressParser:  Encountered errors during parse.");
                }
        } // end main

} // end class ExpressParser

PARSER_END(ExpressParser)



/************************************************
*************************************************
** Tokens
*************************************************
************************************************/

SKIP : /* WHITE SPACE */
{
  " "
| "\t"
| "\n"
| "\r"
| "\f"
}



SPECIAL_TOKEN : /* COMMENTS */
{
  
| 
}


TOKEN : {
        
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
|       
}


TOKEN : {
   
|  <#HEX_LITERAL: "0" ["x","X"] ()+>
|  <#HEX_DIGIT: ["0"-"9","a"-"f","A"-"F"]>
|  <#OCTAL_LITERAL: "0" (["0"-"7"])*>
|  )? >
|  <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+>
|   |  |  |  | " " )*  "\'" >
|  <#ESCAPED_CHAR: "\\" (["n","t","b","r","f","\\","\'","\""]) >
|  <#PRINT_CHAR: "~" | "!" | "@" | "#" | "$" | "%" | "^" |"&" | "*" | "(" |  | "_" | "-" | "+" | "=" | "|" | "{" | "}" | "[" | "]" | ":" | ";" | "," | "." | "<" | ">" | "/" | "?" | "~" | "`" >
|  )+ "\"">
|  
|      >
|  <#ENCODED_CHARACTER:     >
|   ( |  | "_")*>
|  <#LETTER: ["A"-"Z", "a"-"z"]>
|  <#DIGIT: ["0"-"9"]>
}

TOKEN :
{
  < LPAREN: "(" >
| < RPAREN: ")" >
| < LBRACE: "{" >
| < RBRACE: "}" >
| < LBRACKET: "[" >
| < RBRACKET: "]" >
| < SEMICOLON: ";" >
| < COLON: ":" >
| < COMMA: "," >
| < DOT: "."  >
}

TOKEN :
{
  < ASSIGN: ":=" >
| < GT: ">" >
| < LT: "<" >
| < LTE: "<=" >
| < GTE: ">=" >
| < QMARK: "?" >
| < POWER: "**" >
| < BSLASH: "\\" >
| < NE: "<>" >
| < EQ: "=" >
| < ASSIGN_NE: ":<>:">
| < ASSIGN_EQ: ":=:">
| < PLUS: "+" >
| < MINUS: "-" >
| < STAR: "*">
| < SLASH: "/">
| < SC_OR: "||" >
| < SRS: "<*" >
| < BIT_OR: "|" >
}

/************************************************
*************************************************
** Grammar
*************************************************
************************************************/


/********** PRODUCTION 140 **********/
void simple_id() : {}
{
        
}


/********** PRODUCTION 145 **********/

void attribute_ref() : {}
{
        attribute_id()
}

/********** PRODUCTION 146 **********/

void constant_ref() : {}
{
        constant_id()
}

/********** PRODUCTION 147 **********/

void entity_ref() : {}
{
        entity_id()
}


/********** PRODUCTION 148 **********/

void enumeration_ref() : {}
{
        enumeration_id()
}

/********** PRODUCTION 149 **********/

void function_ref() : {}
{
        function_id()
}


/********** PRODUCTION 150 **********/

void parameter_ref() : {}
{
        parameter_id()
}

/********** PRODUCTION 151 **********/

void procedure_ref() : {}
{
        procedure_id()
}

/********** PRODUCTION 152 **********/

void schema_ref() : {}
{
        schema_id()
}

/********** PRODUCTION 153 **********/

void type_label_ref() : {}
{
        type_label_id()
}


/********** PRODUCTION 154 **********/

void type_ref() : {}
{
        type_id()
}

/********** PRODUCTION 155 **********/

void variable_ref() : {}
{
        variable_id()
}

/********** PRODUCTION 156 **********/

void abstract_supertype_declaration() : {}
{
          (subtype_constraint())?
}

/********** PRODUCTION 157 **********/

void actual_parameter_list() : {}
{
         parameter() ( parameter())* 
}

/********** PRODUCTION 158 **********/
void add_like_op() : {}
{
         |  |  | 
}

/********** PRODUCTION 159 **********/
void aggregate_initializer() : {}
{
         (element() ( element())*)?  
}

/********** PRODUCTION 160 **********/
void aggregate_source() : {}
{
        simple_expression()
}

/********** PRODUCTION 161 **********/
void aggregate_type() : {}
{
         ( type_label())?  parameter_type() 
}

/********** PRODUCTION 162 **********/
void aggregation_types() : {}
{
        array_type() 
        | bag_type()  
        | list_type() 
        | set_type() 
}

/********** PRODUCTION 163 **********/
void algorithm_head() : {}
{
        (declaration())* (constant_decl())? (local_decl()) 
}

/********** PRODUCTION 164 **********/
void alias_stmt() : {}
{
         variable_id()  general_ref() (qualifier())*  (stmt())+  
}

/********** PRODUCTION 165 **********/
void array_type() : {}
{
         bound_spec()  ()? ()? base_type() 
} 

/********** PRODUCTION 166 **********/
void assignment_stmt() : {}
{
        general_ref() (qualifier())*  expression()  
}

/********** PRODUCTION 167 **********/
void attribute_decl() : {}
{
        attribute_id() | qualified_attribute() 
}

/********** PRODUCTION 168 **********/
void attribute_id() : {}
{
        simple_id()
}
/********** PRODUCTION 169 **********/
void attribute_qualifier() : {}
{
         attribute_ref() 
}

/********** PRODUCTION 170 **********/
void bag_type() : {}
{
         (bound_spec())?  base_type()
}

/********** PRODUCTION 171 **********/
void base_type() : {}
{
        aggregation_types() 
        | simple_types() 
        | named_types() 


}


/********** PRODUCTION 172 **********/
void binary_type() : {}
{
         (width_spec())?
}

/********** PRODUCTION 173 **********/
void boolean_type() : {}
{
         
}

/********** PRODUCTION 174 **********/
void bound_1() : {}
{
        numeric_expression()
}

/********** PRODUCTION 175 **********/
void bound_2() : {}     
{
        numeric_expression()
}

/********** PRODUCTION 176 **********/
void bound_spec() : {}
{
         bound_1()  bound_2()  
}

/********** PRODUCTION 177 **********/
void built_in_constant() : {}
{
         |  |  |  
}

/********** PRODUCTION 178 **********/
void built_in_function() : {}
{
         |  |  |  |  |   |
         |  |  |  |  |
         |  |  |  |    | 
         |  |  |  |  |  |
         |  |  |  |  |
         |  
}

/********** PRODUCTION 179 **********/
void built_in_procedure() : {}
{
         | 
}

/********** PRODUCTION 180 **********/
void case_action() : {}
{
        case_label() ( case_label())*  stmt() 
}

/********** PRODUCTION 181 **********/
void case_label() : {}
{
        expression() 
}

/********** PRODUCTION 182 **********/
void case_stmt() : {}
{
         selector()  (case_action())* (  stmt())?   
}

/********** PRODUCTION 183 **********/
void compound_stmt() : {}
{
         (stmt())+   
}

/********** PRODUCTION 184 **********/
void constant_body() : {}
{
        constant_id()  base_type()  expression()  
}

/********** PRODUCTION 185 **********/
void constant_decl() : {}
{
         (constant_body())+   
}

/********** PRODUCTION 186 **********/
void constant_factor() : {}
{
        built_in_constant() | constant_ref() 
}

/********** PRODUCTION 187 **********/
void constant_id() : {}
{
        simple_id()
}

/********** PRODUCTION 188 **********/
void constructed_types() : {}
{
        enumeration_type() | select_type() 
}

/********** PRODUCTION 189 **********/
void declaration() : {}
{
        entity_decl() | function_decl() | procedure_decl() | type_decl() 
}

/********** PRODUCTION 190 **********/
void derived_attr() : {}
{
        attribute_decl()  base_type()  expression()  
}

/********** PRODUCTION 191 **********/
void derive_clause() : {}
{
         (derived_attr())+
}

/********** PRODUCTION 192 **********/
void domain_rule() : {}
{
        (label() )? expression()
}

/********** PRODUCTION 193 **********/
void element() : {}
{
        expression() ( repetition())? 
}

/********** PRODUCTION 194 **********/
void entity_body() : {}
{
        (explicit_attr())* (derive_clause())? (inverse_clause())? (unique_clause())? (where_clause())?
}

/********** PRODUCTION 195 **********/
void entity_constructor() : {}
{
        entity_ref()  (expression() ( expression())*)?  
}

/********** PRODUCTION 196 **********/
void entity_decl() : { }
{
        entity_head() entity_body()   
}

/********** PRODUCTION 197 **********/
void entity_head() : { }
{
         entity_id() (subsuper())? 
}

/********** PRODUCTION 198 **********/
void entity_id() : {}
{
        simple_id()
}

/********** PRODUCTION 199 **********/
void enumeration_id() : {}
{
        simple_id()
}

/********** PRODUCTION 200 **********/
void enumeration_reference() : {}
{
        (type_ref() )? enumeration_ref() 
}    

/********** PRODUCTION 201 **********/
void enumeration_type() : {}
{
           enumeration_id() ( enumeration_id())*  
}

/********** PRODUCTION 202 **********/
void escape_stmt() : {}
{
          
}

/********** PRODUCTION 203 **********/
void explicit_attr() : {}
{

        attribute_decl() 
        ( attribute_decl())*
         ()? 
        base_type()                     
        

}

/********** PRODUCTION 204 **********/
void expression() : {}
{
        simple_expression() (rel_op_extended() simple_expression())? 
}

/********** PRODUCTION 205 **********/
void factor() : {}
{
        simple_factor() ( simple_factor())?
}

/********** PRODUCTION 206 **********/
void formal_parameter() : {}
{
        parameter_id() ( parameter_id())*  parameter_type() 
}

/********** PRODUCTION 207 **********/
void function_call() : {}
{
        (built_in_function() | function_ref()) (actual_parameter_list())? 
}

/********** PRODUCTION 208 **********/
void function_decl() : {}
{
        function_head() (algorithm_head())? (stmt())+   
}

/********** PRODUCTION 209 **********/
void function_head() : {}
{
         function_id() ( formal_parameter() ( formal_parameter())* )?  parameter_type()   
}

/********** PRODUCTION 210 **********/
void function_id() : {}
{
        simple_id()
}

/********** PRODUCTION 211 **********/
void generalized_types() : {}
{
        aggregate_type() 
        | general_aggregation_types() 
        | generic_type() 
}

/********** PRODUCTION 212 **********/
void general_aggregation_types() : {}
{
          general_array_type() 
        | general_bag_type() 
        | general_list_type() 
        | general_set_type() 
}

/********** PRODUCTION 213 **********/
void general_array_type() : {}
{
          (bound_spec())?  ( )? ()? parameter_type() 

}

/********** PRODUCTION 214 **********/
void general_bag_type() : {}
{
         (bound_spec())?  parameter_type() 
}

/********** PRODUCTION 215 **********/
void general_list_type() : {}
{
         (bound_spec())?  ()? parameter_type() 
}

/********** PRODUCTION 216 **********/
void general_ref() : {}
{
          parameter_ref() 
        | variable_ref() 
}

/********** PRODUCTION 217 **********/
void general_set_type() : {}
{
         (bound_spec())?  parameter_type() 
}

/********** PRODUCTION 218 **********/
void generic_type() : {}
{
         ( type_label())? 
}

/********** PRODUCTION 219 **********/
void group_qualifier() : {}
{
         entity_ref() 
}

/********** PRODUCTION 220 **********/
void if_stmt() : {}
{
         expression()  (stmt())+ ( (stmt())+)?   
}

/********** PRODUCTION 221 **********/
void increment() : {}
{
        numeric_expression() 
}

/********** PRODUCTION 222 **********/
void increment_control() : {}
{
        variable_id()  bound_1()  bound_2() ( increment())?
}

/********** PRODUCTION 223 **********/
void index() : {}
{
        numeric_expression() 
}

/********** PRODUCTION 224 **********/
void index_1() : {}
{
        index() 
}

/********** PRODUCTION 225 **********/
void index_2() : {}
{
        index() 
}

/********** PRODUCTION 226 **********/
void index_qualifier() : {}
{
         index_1() ( index_2())?  
}

/********** PRODUCTION 227 **********/
void integer_type() : {}
{
         
}

/********** PRODUCTION 228 **********/
void interface_specification() : {}
{
          reference_clause() 
        | use_clause() 
}

/********** PRODUCTION 229 **********/
void interval() : {}
{
         interval_low() interval_op() interval_item() interval_op() interval_high()  
}

/********** PRODUCTION 230 **********/
void interval_high() : {}
{
        simple_expression() 
}

/********** PRODUCTION 231 **********/
void interval_item() : {}
{
        simple_expression() 
}

/********** PRODUCTION 232 **********/
void interval_low() : {}
{
        simple_expression() 
}


/********** PRODUCTION 233 **********/
void interval_op() : {}
{
         | 
}

/********** PRODUCTION 234 **********/
void inverse_attr() : {}
{
        attribute_decl()  ((|) (bound_spec())? )? entity_ref()  attribute_ref()  
}

/********** PRODUCTION 235 **********/
void inverse_clause() : {}
{
         (inverse_attr())+
}

/********** PRODUCTION 236 **********/
void label() : {}
{
        simple_id()
}

/********** PRODUCTION 237 **********/
void list_type() : {}
{
          (bound_spec())?  ()? base_type() 
}

/********** PRODUCTION 238 **********/
void literal() : {}
{
         |  | logical_literal() |  | string_literal()
}

/********** PRODUCTION 239 **********/
void local_decl() : {}
{
         local_variable() (local_variable())*   
}

/********** PRODUCTION 240 **********/
void local_variable() : {}
{
        variable_id() ( variable_id())*  parameter_type() ( expression())?  
}

/********** PRODUCTION 241 **********/
void logical_expression() : {}
{
        expression() 
}

/********** PRODUCTION 242 **********/
void logical_literal() : {}
{
         |  |  
}

/********** PRODUCTION 243 **********/
void logical_type() : {}
{
        
}

/********** PRODUCTION 244 **********/
void multiplication_like_op() : {}
{
         |  | 
| | | } /********** PRODUCTION 245 **********/ void named_types() : {} { entity_ref() | type_ref() } /********** PRODUCTION 246 **********/ void named_type_or_rename() : {} { named_types() ( (entity_id() | type_id()))? } /********** PRODUCTION 247 **********/ void null_stmt() : {} { } /********** PRODUCTION 248 **********/ void number_type() : {} { } /********** PRODUCTION 249 **********/ void numeric_expression() : {} { simple_expression() } /********** PRODUCTION 250 **********/ void one_of() : {} { supertype_expression() ( supertype_expression())* } /********** PRODUCTION 251 **********/ void parameter() : {} { expression() } /********** PRODUCTION 252 **********/ void parameter_id() : {} { simple_id() } /********** PRODUCTION 253 **********/ void parameter_type() : {} { generalized_types() | named_types() | simple_types() } /********** PRODUCTION 254 **********/ void population() : {} { entity_ref() } /********** PRODUCTION 255 **********/ void precision_spec() : {} { numeric_expression() } /********** PRODUCTION 256 **********/ void primary() : {} { literal() | (qualifiable_factor() (qualifier())*) } /********** PRODUCTION 257 **********/ void procedure_call_stmt() : {} { (built_in_procedure() | procedure_ref()) (actual_parameter_list())? } /********** PRODUCTION 258 **********/ void procedure_decl() : {} { procedure_head() (algorithm_head())? (stmt())* } /********** PRODUCTION 259 **********/ void procedure_head() : {} { procedure_id() ( ()? formal_parameter() ( ()? formal_parameter())* )? } /********** PRODUCTION 260 **********/ void procedure_id() : {} { simple_id() } /********** PRODUCTION 261 **********/ void qualifiable_factor() : {} { attribute_ref() | constant_factor() | function_call() | general_ref() | population() } /********** PRODUCTION 262 **********/ void qualified_attribute() : {} { group_qualifier() attribute_qualifier() } /********** PRODUCTION 263 **********/ void qualifier() : {} { attribute_qualifier() | group_qualifier() | index_qualifier() } /********** PRODUCTION 264 **********/ void query_expression() : {} { variable_id() aggregate_source() logical_expression() } /********** PRODUCTION 265 **********/ void real_type() : {} { ( precision_spec() )? } /********** PRODUCTION 266 **********/ void referenced_attribute() : {} { attribute_ref() | qualified_attribute() } /********** PRODUCTION 267 **********/ void reference_clause() : {} { schema_ref() ( resource_or_rename() ( resource_or_rename())* )? } /********** PRODUCTION 268 **********/ void rel_op() : {} { | | | | | | | } /********** PRODUCTION 269 **********/ void rel_op_extended() : {} { rel_op() | | } /********** PRODUCTION 270 **********/ void rename_id() : {} { constant_id() | entity_id() | function_id() | procedure_id() | type_id() } /********** PRODUCTION 271 **********/ void repeat_control() : {} { (increment_control())? (while_control())? (until_control())? } /********** PRODUCTION 272 **********/ void repeat_stmt() : {} { repeat_control() (stmt())+ } /********** PRODUCTION 273 **********/ void repetition() : {} { numeric_expression() } /********** PRODUCTION 274 **********/ void resource_or_rename() : {} { resource_ref() ( rename_id())? } /********** PRODUCTION 275 **********/ void resource_ref() : {} { constant_ref() | entity_ref() | function_ref() | procedure_ref() | type_ref() } /********** PRODUCTION 276 **********/ void return_stmt() : {} { ( expression() )? } /********** PRODUCTION 277 **********/ void rule_decl() : {} { rule_head() (algorithm_head())? (stmt())* where_clause() } /********** PRODUCTION 278 **********/ void rule_head() : {} { rule_id() entity_ref() ( entity_ref())* } /********** PRODUCTION 279 **********/ void rule_id() : {} { simple_id() } /********** PRODUCTION 280 **********/ void schema_body() : {} { (interface_specification())* (constant_decl())? ( declaration() | rule_decl() )* } /********** PRODUCTION 281 **********/ void schema_decl() : {} { schema_id() schema_body() } /********** PRODUCTION 282 **********/ void schema_id() : {} { simple_id() } /********** PRODUCTION 283 **********/ void selector() : {} { expression() } /********** PRODUCTION 284 **********/ void select_type() : {} {