summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAdela Vais <adela.vais99@gmail.com>2021-04-18 12:56:47 +0300
committerAkim Demaille <akim.demaille@gmail.com>2021-06-06 08:10:46 +0200
commit5c554ea8a3b647be281bc7b49d76bedf7c73b292 (patch)
tree5e2d6314c30f4d0da3d067e6708de0d21fcb3c84 /examples
parent7eee2ccbd282dc528c44770f8fc58a1a49061eef (diff)
downloadbison-5c554ea8a3b647be281bc7b49d76bedf7c73b292.tar.gz
d: demonstrate the token constructors
* examples/d/calc/calc.y: Use the token constructors in the 'calc' example.
Diffstat (limited to 'examples')
-rw-r--r--examples/d/calc/calc.y19
1 files changed, 10 insertions, 9 deletions
diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y
index 6e062a69..7273d16c 100644
--- a/examples/d/calc/calc.y
+++ b/examples/d/calc/calc.y
@@ -23,6 +23,7 @@
%define parse.error detailed
%define parse.trace
%define api.push-pull push
+%define api.token.constructor
%locations
@@ -122,7 +123,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
location.step();
if (input.empty)
- return Symbol(TokenKind.YYEOF, location);
+ return Symbol.YYEOF(location);
// Numbers.
if (input.front.isNumber)
@@ -149,7 +150,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
copy.popFront;
}
}
- return Symbol(TokenKind.NUM, ival, location);
+ return Symbol.NUM(ival, location);
}
// Individual characters
@@ -158,17 +159,17 @@ if (isInputRange!R && is(ElementType!R : dchar))
location.end.column++;
switch (ch)
{
- case '+': return Symbol(TokenKind.PLUS, location);
- case '-': return Symbol(TokenKind.MINUS, location);
- case '*': return Symbol(TokenKind.STAR, location);
- case '/': return Symbol(TokenKind.SLASH, location);
- case '(': return Symbol(TokenKind.LPAR, location);
- case ')': return Symbol(TokenKind.RPAR, location);
+ case '+': return Symbol.PLUS(location);
+ case '-': return Symbol.MINUS(location);
+ case '*': return Symbol.STAR(location);
+ case '/': return Symbol.SLASH(location);
+ case '(': return Symbol.LPAR(location);
+ case ')': return Symbol.RPAR(location);
case '\n':
{
location.end.line++;
location.end.column = 1;
- return Symbol(TokenKind.EOL, location);
+ return Symbol.EOL(location);
}
default: assert(0);
}