aboutsummaryrefslogtreecommitdiffgithub
path: root/generate-parse-table.sh
blob: c60f59f1209c09de8e50fbe2672a3c4c9c3d9eec (plain)
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
#!/bin/bash
set -e

[[ $# -eq 1 ]] || {
    printf 'usage: %s <parser>\n' "$0"
    printf '\n'
    printf 'will generate an LR(1) parse table for parser.ts\n'
    exit 1
} >&2

parser=$1

[[ -f novice/assembler/parsers/$parser.ts ]] || {
    printf "error: unknown parser \`%s', sorry bud\n" "$parser" >&2
    exit 1
}

{
    printf '/* tslint:disable */\n'
    printf '// WARNING: GENERATED CODE by generate-parse-table.sh\n'
    printf "import { ParseTable } from '../../lr1';\n"
    printf "import { NT, T } from '../grammars/%s';\n" "$parser"
    printf 'const table: ParseTable<NT, T> = '
    node novice/main.js tablegen "$parser"
    printf ';\n'
    printf 'export default table;\n'
} >"novice/assembler/parsers/tables/$parser.ts"