diff --git a/src/Driver.mli b/src/Driver.mli index 1d8c654c8c0780ee4193001f489bb9e61b0647c2..9da0d3749ee8a296a234787362563774eae052fc 100644 --- a/src/Driver.mli +++ b/src/Driver.mli @@ -2,4 +2,4 @@ which could be produced by either ocamlyacc or Menhir. *) val grammar : - (Lexing.lexbuf -> Parser.token) -> Lexing.lexbuf -> Syntax.grammar + (Lexing.lexbuf -> Parser.token) -> Lexing.lexbuf -> Syntax.partial_grammar diff --git a/src/fancy-parser.mly b/src/fancy-parser.mly index 2cd866f6ed19fb74c2470aa9e390c1837287d3e2..854c21292abc1d99247ad51dd0cdc136865990de 100644 --- a/src/fancy-parser.mly +++ b/src/fancy-parser.mly @@ -29,7 +29,7 @@ open Positions /* ------------------------------------------------------------------------- */ /* Start symbol. */ -%start grammar +%start grammar /* ------------------------------------------------------------------------- */ /* Priorities. */ diff --git a/src/internalSyntax.mli b/src/internalSyntax.mli deleted file mode 100644 index bb3ce8810b47ab00c4b1aa38f6d48e59a0443fe5..0000000000000000000000000000000000000000 --- a/src/internalSyntax.mli +++ /dev/null @@ -1,11 +0,0 @@ -type grammar = - { - p_preludes : Stretch.t list; - p_postludes : Syntax.trailer list; - p_parameters : Stretch.t list; - p_start_symbols : Positions.t StringMap.t; - p_types : (Syntax.parameter * Stretch.ocamltype Positions.located) list; - p_tokens : Syntax.token_properties StringMap.t; - p_rules : Syntax.parameterized_rule StringMap.t; - p_on_error_reduce : Syntax.parameter list; - } diff --git a/src/parameterizedGrammar.ml b/src/parameterizedGrammar.ml index 213bea2bdcf228b8b9f676a826f80ce89e467228..7a036a868ddf45b0d9efb4f4e03f865646e6ee57 100644 --- a/src/parameterizedGrammar.ml +++ b/src/parameterizedGrammar.ml @@ -1,7 +1,6 @@ open Positions open Syntax open UnparameterizedSyntax -open InternalSyntax open Misc (* Inference for non terminals. *) @@ -249,7 +248,7 @@ let rec parameter_type env = function [Star] otherwise it is the flexible variable. *) star_variable -let check_grammar p_grammar = +let check_grammar (p_grammar : Syntax.grammar) = (* [n] is the grammar size. *) let n = StringMap.cardinal p_grammar.p_rules in diff --git a/src/parameterizedGrammar.mli b/src/parameterizedGrammar.mli index d43fcc11a7d8360b05a30ca418351100e31cfb3f..3a8580859e05c09978fc9c6c7f36e980f57a33ed 100644 --- a/src/parameterizedGrammar.mli +++ b/src/parameterizedGrammar.mli @@ -10,6 +10,4 @@ sanitized via [Misc.normalize] when printed in a context where a valid identifier is expected. *) -val expand : InternalSyntax.grammar -> UnparameterizedSyntax.grammar - - +val expand : Syntax.grammar -> UnparameterizedSyntax.grammar diff --git a/src/partialGrammar.ml b/src/partialGrammar.ml index e5c3f475b58d8240bac53aa4955223c8061e49fa..02605ffea61df502fbf11be2cd661906320cd5b3 100644 --- a/src/partialGrammar.ml +++ b/src/partialGrammar.ml @@ -1,6 +1,5 @@ open Misc open Syntax -open InternalSyntax open Positions (* ------------------------------------------------------------------------- *) @@ -432,7 +431,7 @@ let iter_on_only_used_symbols f t = | _ -> ()) t -let symbols_of grammar (pgrammar : Syntax.grammar) = +let symbols_of grammar (pgrammar : Syntax.partial_grammar) = let tokens = grammar.p_tokens in let symbols_of_rule symbols prule = let rec store_except_rule_parameters = diff --git a/src/partialGrammar.mli b/src/partialGrammar.mli index a5a9adcdbe61c882cd115e099379a0d5c8898b32..0ee56580b6db35ace54e44a0d87e5a9c469473fa 100644 --- a/src/partialGrammar.mli +++ b/src/partialGrammar.mli @@ -1,2 +1,4 @@ +open Syntax + val join_partial_grammars : - Syntax.grammar list -> InternalSyntax.grammar + partial_grammar list -> grammar diff --git a/src/syntax.mli b/src/syntax.mli index 7ddcbdb5698cdf97e3ec179be4ecb14488c4ad96..783e9c2c73817ea3831be32b33d3a3bcfbde1a62 100644 --- a/src/syntax.mli +++ b/src/syntax.mli @@ -1,3 +1,13 @@ +(* The type [partial_grammar] describes the abstract syntax that is produced + by the parsers (yacc-parser and fancy-parser). + + The type [grammar] describes the abstract syntax that is obtained after one + or more partial grammars are joined (see [PartialGrammar]). It differs in + that declarations are organized in a more useful way and a number of + well-formedness checks have been performed. *) + +(* ------------------------------------------------------------------------ *) + (* Terminals and nonterminal symbols are strings. Identifiers (which are used to refer to a symbol's semantic value) are strings. A file name is a string. *) @@ -17,16 +27,24 @@ type identifier = type filename = string +(* ------------------------------------------------------------------------ *) + (* A trailer is a source file fragment. *) type trailer = Stretch.t +(* ------------------------------------------------------------------------ *) + (* OCaml semantic actions are represented as stretches. *) type action = Action.t +(* ------------------------------------------------------------------------ *) + +(* Information about tokens. *) + type token_associativity = LeftAssoc | RightAssoc @@ -52,6 +70,8 @@ type token_properties = mutable tk_is_declared : bool; } +(* ------------------------------------------------------------------------ *) + type parameter = | ParameterVar of symbol Positions.located | ParameterApp of symbol Positions.located * parameters @@ -123,10 +143,22 @@ type parameterized_rule = pr_branches : parameterized_branch list; } -type grammar = +type partial_grammar = { pg_filename : filename; pg_declarations : declaration Positions.located list; pg_rules : parameterized_rule list; pg_trailer : trailer option; } + +type grammar = + { + p_preludes : Stretch.t list; + p_postludes : trailer list; + p_parameters : Stretch.t list; + p_start_symbols : Positions.t StringMap.t; + p_types : (parameter * Stretch.ocamltype Positions.located) list; + p_tokens : token_properties StringMap.t; + p_rules : parameterized_rule StringMap.t; + p_on_error_reduce : parameter list; + } diff --git a/src/yacc-parser.mly b/src/yacc-parser.mly index 8ed78f05fe13228737bfad09adc87cd6dcca480f..0a3105606fb6d06f28a65bcd74b67a69184fa6be 100644 --- a/src/yacc-parser.mly +++ b/src/yacc-parser.mly @@ -20,7 +20,7 @@ open Positions %token PERCENTPERCENT %token Syntax.action> ACTION %start grammar -%type grammar +%type grammar /* These declarations solve a shift-reduce conflict in favor of shifting: when the declaration of a non-terminal symbol begins with