Hoje imagino que os steps do LR parser ser茫o desta maneira:
Action | Stack | Remaining |
---|---|---|
Shift | ( |
位x.位y.x y) z |
Shift | (位 |
x.位y.x y) z |
Shift | (位x |
.位y.x y) z |
Shift | (位x. |
位y.x y) z |
Shift | (位x.位 |
y.x y) z |
Shift | (位x.位y |
.x y) z |
name: Tests | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master |
const assert = require('assert'); | |
/** | |
* @param {string} str | |
*/ | |
const asb = ([fst, scd, ...tail]) => { | |
if (fst === 'a' && scd === 'a') return asb([fst, ...tail]); | |
if (fst === 'b' && !scd) return true; | |
if (fst === 'a' && scd === 'b') return true; |
const assert = require('assert'); | |
/** | |
* @param {string} str | |
*/ | |
const asb = ([head, ...tail]) => { | |
if (head === 'a') return asb(tail); | |
if (head === 'b' && !tail.length) return true; | |
return false; |
// Or just get the last element! | |
type GetLast<XS extends unknown[]> | |
= [never, ...XS][XS['length']]; | |
// => never | |
type Empty = TakeLast<[]>; | |
// => 1 | |
type OneEl = TakeLast<[1]>; |
Hoje imagino que os steps do LR parser ser茫o desta maneira:
Action | Stack | Remaining |
---|---|---|
Shift | ( |
位x.位y.x y) z |
Shift | (位 |
x.位y.x y) z |
Shift | (位x |
.位y.x y) z |
Shift | (位x. |
位y.x y) z |
Shift | (位x.位 |
y.x y) z |
Shift | (位x.位y |
.x y) z |
const assert = require('assert'); | |
const Value = (n) => ({ type: 'value', n }); | |
const Sum = (a, b) => ({ type: 'sum', a, b }); | |
const Prod = (a, b) => ({ type: 'prod', a, b }); | |
const Div = (a, b) => ({ type: 'div', a, b }); | |
const Sub = (a, b) => ({ type: 'sub', a, b }); | |
const sliceLast = (a, n) => a.slice(n > a.length ? 0 : a.length - n, a.length); |
Trying to parse: 位x.位y.x x
Tokens: [Lambda, 'x', Dot, Lambda, 'y', Dot, 'x', Space, 'x']
Step | Op | State | Tokens |
---|---|---|---|
1 | Start | [] |
[Lambda, 'x', Dot, Lambda, 'y', Dot, 'x', Space, 'x'] |
2 | Shift | [Lambda] |
['x', Dot, Lambda, 'y', Dot, 'x', Space, 'x'] |
3 | Reduce | [Lambda] |
['x', Dot, Lambda, 'y', Dot, 'x', Space, 'x'] |
4 | Shift | [Lambda, 'x'] |
[Dot, Lambda, 'y', Dot, 'x', Space, 'x'] |
#!/usr/bin/env bash | |
set -e | |
# complain to STDERR and exit with error | |
die() | |
{ | |
echo "$*" >&2 | |
print_usage | |
exit 2 |