1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
/*
* ocamlweb - A WEB-like tool for ocaml
* Copyright (C) 1999-2001 Jean-Christophe FILLITRE and Claude MARCH
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2, as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU Library General Public License version 2 for more details
* (enclosed in the file LGPL).
*/
/*i $Id: yacc_parser.mly,v 1.10 2004/10/12 12:29:19 filliatr Exp $ i*/
/*s In actions, we reuse the location type for lex files. */
%{
open Lex_syntax
open Yacc_syntax
let dummy_loc =
{ start_pos = Lexing.dummy_pos;
end_pos = Lexing.dummy_pos;
start_line = 0 ;
start_col = 0 }
%}
/*s Yacc tokens. */
%token Ttoken Tstart Ttype Tleft Tright Tnonassoc Tprec Terror
%token <Yacc_syntax.ident> Tident
%token <Yacc_syntax.location> Taction Ttypedecl
%token Tor Tsemicolon Tcolon Tmark
%token EOF
%start yacc_definitions
%type <Yacc_syntax.yacc_definitions> yacc_definitions
%%
/*s Start symbol for yacc description files */
yacc_definitions:
| header tokendecls Tmark rules header EOF
{ { header = $1 ;
decls = $2;
rules = $4;
trailer = $5 } }
;
header :
| Taction
{ $1 }
| /* $\varepsilon$ */
{ dummy_loc }
;
/*s Token declarations. */
tokendecls :
| tokendecl tokendecls
{ $1::$2 }
| /*epsilon*/
{ [] }
;
tokendecl :
| Ttoken Ttypedecl idlist
{ Typed_tokens($2,$3) }
| Ttoken idlist
{ Untyped_tokens($2) }
| Ttype Ttypedecl idlist
{ Non_terminals_type($2,$3) }
| Tstart idlist
{ Start_symbols($2) }
| Tleft idlist
{ Tokens_assoc($2) }
| Tnonassoc idlist
{ Tokens_assoc($2) }
| Tright idlist
{ Tokens_assoc($2) }
;
idlist:
| Tident
{ [$1] }
| Tident idlist
{ $1 :: $2 }
;
/*s Parsing of rules. */
rules:
| /* $\varepsilon$ */
{ [] }
| general_rule rules
{ $1 :: $2 }
;
/*
Ocamlyacc manual asks for a semicolon at end of each rules. But ocamlyacc
accepts if they are missing. We issue a warning for non conformity to
ocamlyacc documentation.
*/
general_rule:
| rule Tsemicolon
{ $1 }
| rule
{ Yacc_syntax.issue_warning "ocamlyacc documentation recommends adding a semicolon at end of each grammar rules";
$1 }
;
rule :
| Tident Tcolon right_part
{ ($1,$3) }
| Tident Tcolon Tor right_part
{ ($1,$4) }
;
right_part :
| word Taction
{ [($1,$2)] }
| word Taction Tor right_part
{ ($1,$2) :: $4 }
;
word :
| /* $\varepsilon$ */
{ [] }
| Tident word
{ $1 :: $2 }
| Tprec Tident word
{ $2 :: $3 }
| Terror word
{ $2 }
;
|