mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
style: rename semanticVal as value
* data/skeletons/README-D.txt: Remove, now useless and obsolete. * data/skeletons/glr2.cc, examples/d/calc/calc.y, * tests/calc.at, tests/d.at, tests/scanner.at (semanticVal): Replace with... (value): this.
This commit is contained in:
2
TODO
2
TODO
@@ -786,7 +786,7 @@ Equip the parser with a means to create the (visual) parse tree.
|
|||||||
# LocalWords: nterm bitsetv ielr ritem nstates nrules nritems yysymbol EQ
|
# LocalWords: nterm bitsetv ielr ritem nstates nrules nritems yysymbol EQ
|
||||||
# LocalWords: SymbolKind YYEMPTY YYUNDEF YYTNAME NUM yyntokens yytname sed
|
# LocalWords: SymbolKind YYEMPTY YYUNDEF YYTNAME NUM yyntokens yytname sed
|
||||||
# LocalWords: nonterminals yykind yycode YYNAMES yynames init getName conv
|
# LocalWords: nonterminals yykind yycode YYNAMES yynames init getName conv
|
||||||
# LocalWords: TokenKind semanticVal ival yychar yylval yylexer Tolmer hoc
|
# LocalWords: TokenKind ival yychar yylval yylexer Tolmer hoc
|
||||||
# LocalWords: Sobisch YYPTRDIFF ptrdiff Autotest YYPRINT toknum yytoknum
|
# LocalWords: Sobisch YYPTRDIFF ptrdiff Autotest YYPRINT toknum yytoknum
|
||||||
# LocalWords: sym Wother stderr FP fixits xgettext fdiagnostics Graphviz
|
# LocalWords: sym Wother stderr FP fixits xgettext fdiagnostics Graphviz
|
||||||
# LocalWords: graphviz VCG bitset xml bw maint yytoken YYABORT deps
|
# LocalWords: graphviz VCG bitset xml bw maint yytoken YYABORT deps
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ dist_skeletons_DATA = \
|
|||||||
|
|
||||||
# Experimental support for the D language.
|
# Experimental support for the D language.
|
||||||
dist_skeletons_DATA += \
|
dist_skeletons_DATA += \
|
||||||
data/skeletons/README-D.txt \
|
|
||||||
data/skeletons/d-skel.m4 \
|
data/skeletons/d-skel.m4 \
|
||||||
data/skeletons/d.m4 \
|
data/skeletons/d.m4 \
|
||||||
data/skeletons/lalr1.d
|
data/skeletons/lalr1.d
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
Some usage notes for the D Parser:
|
|
||||||
|
|
||||||
- it is a port of the Java parser, so interface is very similar.
|
|
||||||
|
|
||||||
- the lexer class needs to implement the interface 'Lexer' (similar to
|
|
||||||
java). It typically (depending on options) looks like this:
|
|
||||||
|
|
||||||
public interface Lexer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Method to retrieve the beginning position of the last scanned token.
|
|
||||||
* @return the position at which the last scanned token starts. */
|
|
||||||
@property YYPosition startPos ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to retrieve the ending position of the last scanned token.
|
|
||||||
* @return the first position beyond the last scanned token. */
|
|
||||||
@property YYPosition endPos ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to retrieve the semantic value of the last scanned token.
|
|
||||||
* @return the semantic value of the last scanned token. */
|
|
||||||
@property YYSemanticType semanticVal ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Entry point for the scanner. Returns the token identifier corresponding
|
|
||||||
* to the next token and prepares to return the semantic value
|
|
||||||
* and beginning/ending positions of the token.
|
|
||||||
* @return the token identifier corresponding to the next token. */
|
|
||||||
TokenKind yylex ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Entry point for error reporting. Emits an error
|
|
||||||
* referring to the given location in a user-defined way.
|
|
||||||
*
|
|
||||||
* @param loc The location of the element to which the
|
|
||||||
* error message is related
|
|
||||||
* @param s The string for the error message. */
|
|
||||||
void yyerror (YYLocation loc, string s);
|
|
||||||
}
|
|
||||||
|
|
||||||
- semantic types are handled by D unions (same as for C/C++ parsers)
|
|
||||||
|
|
||||||
- the following (non-standard) %defines are supported:
|
|
||||||
|
|
||||||
%define package "<package_name>"
|
|
||||||
%define api.parser.class "my_class_name>"
|
|
||||||
%define position_type "my_position_type"
|
|
||||||
%define location_type "my_location_type"
|
|
||||||
|
|
||||||
- the following declarations basically work like in C/C++:
|
|
||||||
|
|
||||||
%locations
|
|
||||||
%error-verbose
|
|
||||||
%parse-param
|
|
||||||
%initial-action
|
|
||||||
%code
|
|
||||||
%union
|
|
||||||
|
|
||||||
- %destructor is not yet supported
|
|
||||||
@@ -344,7 +344,7 @@ m4_define([b4_rhs_data],
|
|||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
|
# Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
|
||||||
m4_define([b4_rhs_value],
|
m4_define([b4_rhs_value],
|
||||||
[b4_symbol_value([b4_rhs_data([$1], [$2]).semanticVal()], [$3], [$4])])
|
[b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -767,7 +767,7 @@ public:
|
|||||||
{
|
{
|
||||||
setPred (other.pred ());
|
setPred (other.pred ());
|
||||||
if (other.yyresolved)
|
if (other.yyresolved)
|
||||||
new (&yysval) value_type (other.semanticVal ());
|
new (&yysval) value_type (other.value ());
|
||||||
else
|
else
|
||||||
setFirstVal (other.firstVal ());]b4_parse_assert_if([[
|
setFirstVal (other.firstVal ());]b4_parse_assert_if([[
|
||||||
check_();]])[
|
check_();]])[
|
||||||
@@ -792,7 +792,7 @@ public:
|
|||||||
yyposn = other.yyposn;
|
yyposn = other.yyposn;
|
||||||
setPred (other.pred ());
|
setPred (other.pred ());
|
||||||
if (other.yyresolved)
|
if (other.yyresolved)
|
||||||
semanticVal () = other.semanticVal ();
|
value () = other.value ();
|
||||||
else
|
else
|
||||||
setFirstVal (other.firstVal ());]b4_locations_if([[
|
setFirstVal (other.firstVal ());]b4_locations_if([[
|
||||||
yyloc = other.yyloc;]])[
|
yyloc = other.yyloc;]])[
|
||||||
@@ -818,13 +818,13 @@ public:
|
|||||||
const semantic_option* firstVal () const;
|
const semantic_option* firstVal () const;
|
||||||
void setFirstVal (const semantic_option* option);
|
void setFirstVal (const semantic_option* option);
|
||||||
|
|
||||||
value_type& semanticVal ()
|
value_type& value ()
|
||||||
{]b4_parse_assert_if([[
|
{]b4_parse_assert_if([[
|
||||||
check_ ();]])[
|
check_ ();]])[
|
||||||
return yysval;
|
return yysval;
|
||||||
}
|
}
|
||||||
|
|
||||||
const value_type& semanticVal () const
|
const value_type& value () const
|
||||||
{]b4_parse_assert_if([[
|
{]b4_parse_assert_if([[
|
||||||
check_ ();]])[
|
check_ ();]])[
|
||||||
return yysval;
|
return yysval;
|
||||||
@@ -1119,12 +1119,12 @@ public:
|
|||||||
else if (yys0->yyresolved)
|
else if (yys0->yyresolved)
|
||||||
{
|
{
|
||||||
yys1->yyresolved = true;
|
yys1->yyresolved = true;
|
||||||
yys1->semanticVal() = yys0->semanticVal();
|
yys1->value () = yys0->value ();
|
||||||
}
|
}
|
||||||
else if (yys1->yyresolved)
|
else if (yys1->yyresolved)
|
||||||
{
|
{
|
||||||
yys0->yyresolved = true;
|
yys0->yyresolved = true;
|
||||||
yys0->semanticVal() = yys1->semanticVal();
|
yys0->value () = yys1->value ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1407,7 +1407,7 @@ void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class
|
|||||||
check_ ();]])[
|
check_ ();]])[
|
||||||
if (yyresolved)
|
if (yyresolved)
|
||||||
yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState),
|
yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState),
|
||||||
&semanticVal()]b4_locations_if([, &yyloc])[);
|
&value ()]b4_locations_if([, &yyloc])[);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
YY_SYMBOL_PRINT (yymsg << (firstVal() ? " unresolved" : " incomplete"),
|
YY_SYMBOL_PRINT (yymsg << (firstVal() ? " unresolved" : " incomplete"),
|
||||||
@@ -1700,10 +1700,10 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
yys.yyresolved = s->yyresolved;
|
yys.yyresolved = s->yyresolved;
|
||||||
if (s->yyresolved)
|
if (s->yyresolved)
|
||||||
new (&yys.semanticVal ()) value_type (s->semanticVal ());
|
new (&yys.value ()) value_type (s->value ());
|
||||||
else
|
else
|
||||||
/* The effect of using semanticVal or yyloc (in an immediate rule) is
|
/* The effect of using yysval or yyloc (in an immediate
|
||||||
* undefined. */
|
* rule) is undefined. */
|
||||||
yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[
|
yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[
|
||||||
yys.yyloc = s->yyloc;]])[
|
yys.yyloc = s->yyloc;]])[
|
||||||
yys.setPred(s->pred());
|
yys.setPred(s->pred());
|
||||||
@@ -1740,7 +1740,7 @@ public:
|
|||||||
std::cerr << " $" << yyi + 1 << " = ";
|
std::cerr << " $" << yyi + 1 << " = ";
|
||||||
yyparser.yy_symbol_print_
|
yyparser.yy_symbol_print_
|
||||||
(yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
|
(yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState),
|
||||||
&yyvsp[yyi - yynrhs + 1].getState().semanticVal()]b4_locations_if([[,
|
&yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[,
|
||||||
&]b4_rhs_location(yynrhs, yyi + 1)])[);
|
&]b4_rhs_location(yynrhs, yyi + 1)])[);
|
||||||
if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
|
if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved)
|
||||||
std::cerr << " (unresolved)";
|
std::cerr << " (unresolved)";
|
||||||
@@ -2296,7 +2296,7 @@ public:
|
|||||||
if (yyrhslen == 0)
|
if (yyrhslen == 0)
|
||||||
*yyvalp = yyval_default;
|
*yyvalp = yyval_default;
|
||||||
else
|
else
|
||||||
*yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().semanticVal();]b4_locations_if([[
|
*yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]b4_locations_if([[
|
||||||
/* Default location. */
|
/* Default location. */
|
||||||
YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
|
YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
|
||||||
yyerror_range[1].getState().yyloc = *yylocp;
|
yyerror_range[1].getState().yyloc = *yylocp;
|
||||||
@@ -2657,7 +2657,7 @@ private:
|
|||||||
{
|
{
|
||||||
yys.yyresolved = true;
|
yys.yyresolved = true;
|
||||||
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
||||||
new (&yys.semanticVal ()) value_type (yysval);
|
new (&yys.value ()) value_type (yysval);
|
||||||
YY_IGNORE_MAYBE_UNINITIALIZED_END
|
YY_IGNORE_MAYBE_UNINITIALIZED_END
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
|||||||
stderr.writeln(loc.toString(), ": ", s);
|
stderr.writeln(loc.toString(), ": ", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value semanticVal_;
|
Value value_;
|
||||||
|
|
||||||
Symbol yylex()
|
Symbol yylex()
|
||||||
{
|
{
|
||||||
@@ -129,7 +129,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
|||||||
int lenChars = 0;
|
int lenChars = 0;
|
||||||
auto copy = input;
|
auto copy = input;
|
||||||
import std.conv : parse;
|
import std.conv : parse;
|
||||||
semanticVal_.ival = input.parse!int;
|
value_.ival = input.parse!int;
|
||||||
while (!input.empty && copy.front != input.front)
|
while (!input.empty && copy.front != input.front)
|
||||||
{
|
{
|
||||||
lenChars++;
|
lenChars++;
|
||||||
@@ -137,7 +137,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
|||||||
}
|
}
|
||||||
location.begin = location.end;
|
location.begin = location.end;
|
||||||
location.end.column += lenChars;
|
location.end.column += lenChars;
|
||||||
return Symbol(TokenKind.NUM, semanticVal_.ival, location);
|
return Symbol(TokenKind.NUM, value_.ival, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Individual characters
|
// Individual characters
|
||||||
|
|||||||
@@ -563,7 +563,7 @@ class CalcLexer(R) : Lexer
|
|||||||
|
|
||||||
]AT_YYERROR_DEFINE[
|
]AT_YYERROR_DEFINE[
|
||||||
|
|
||||||
Value semanticVal_;]AT_LOCATION_IF([[
|
Value value_;]AT_LOCATION_IF([[
|
||||||
Location location;
|
Location location;
|
||||||
]])[
|
]])[
|
||||||
int parseInt ()
|
int parseInt ()
|
||||||
@@ -600,8 +600,8 @@ class CalcLexer(R) : Lexer
|
|||||||
// Numbers.
|
// Numbers.
|
||||||
if (input.front.isNumber)
|
if (input.front.isNumber)
|
||||||
{
|
{
|
||||||
semanticVal_.ival = parseInt;
|
value_.ival = parseInt;
|
||||||
return Symbol(TokenKind.]AT_TOKEN_PREFIX[NUM, semanticVal_.ival]AT_LOCATION_IF([[, location]])[);
|
return Symbol(TokenKind.]AT_TOKEN_PREFIX[NUM, value_.ival]AT_LOCATION_IF([[, location]])[);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Individual characters
|
// Individual characters
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ class CalcLexer(R) : Lexer
|
|||||||
|
|
||||||
void yyerror(string s) {}
|
void yyerror(string s) {}
|
||||||
|
|
||||||
Value semanticVal_;
|
|
||||||
|
|
||||||
Symbol yylex()
|
Symbol yylex()
|
||||||
{
|
{
|
||||||
$2
|
$2
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class YYLexer(R) : Lexer
|
|||||||
|
|
||||||
]AT_YYERROR_DEFINE[
|
]AT_YYERROR_DEFINE[
|
||||||
|
|
||||||
Value semanticVal_;
|
Value value_;
|
||||||
|
|
||||||
Symbol yylex ()
|
Symbol yylex ()
|
||||||
{
|
{
|
||||||
@@ -131,8 +131,8 @@ class YYLexer(R) : Lexer
|
|||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||||
semanticVal_.val = c - '0';
|
value_.val = c - '0';
|
||||||
return Symbol(TokenKind.NUM, semanticVal_.val);
|
return Symbol(TokenKind.NUM, value_.val);
|
||||||
case '+': return Symbol(TokenKind.PLUS);
|
case '+': return Symbol(TokenKind.PLUS);
|
||||||
case '-': return Symbol(TokenKind.MINUS);
|
case '-': return Symbol(TokenKind.MINUS);
|
||||||
case '*': return Symbol(TokenKind.STAR);
|
case '*': return Symbol(TokenKind.STAR);
|
||||||
|
|||||||
Reference in New Issue
Block a user