1#!/bin/sh 2 3# yyacc - yacc wrapper 4# 5# Allows tokens to be written as `literal` and then automatically 6# substituted with #defined tokens. 7# 8# Usage: 9# yyacc file.y filetab.h file.yy 10# 11# inputs: 12# file.yy yacc grammar with ` literals 13# 14# outputs: 15# file.y yacc grammar 16# filetab.h array of string <-> token mappings 17# 18# 03-13-93 - Documented and p moved in sed command (for some reason, 19# s/x/y/p doesn't work). 20# 10-12-93 - Take basename as second argument. 21# 12-31-96 - reversed order of args to be compatible with GenFile rule 22# 03/19/02 (seiwald) - suffix symbols with _t to avoid conflicts 23# 24 25outy=${1?} 26outh=${2?} 27in=${3?} 28out=`basename $in .yy` 29 30T=/tmp/yy$$ 31trap 'rm -f $T.*' 0 32 33sed ' 34 : 1 35 /`/{ 36 h 37 s/[^`]*`\([^`]*\)`.*/\1/ 38 p 39 g 40 s/[^`]*`[^`]*`// 41 b 1 42 } 43 d 44' $in | sort -u | sed ' 45 h 46 y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ 47 s/:/_COLON/ 48 s/!/_BANG/ 49 s/&&/_AMPERAMPER/ 50 s/&/_AMPER/ 51 s/+/_PLUS/ 52 s/||/_BARBAR/ 53 s/|/_BAR/ 54 s/;/_SEMIC/ 55 s/-/_MINUS/ 56 s/</_LANGLE/ 57 s/>/_RANGLE/ 58 s/\./_PERIOD/ 59 s/?/_QUESTION/ 60 s/=/_EQUALS/ 61 s/,/_COMMA/ 62 s/\[/_LBRACKET/ 63 s/]/_RBRACKET/ 64 s/{/_LBRACE/ 65 s/}/_RBRACE/ 66 s/(/_LPAREN/ 67 s/)/_RPAREN/ 68 s/.*/&_t/ 69 G 70 s/\n/ / 71' > $T.1 72 73sed ' 74 s:^\(.*\) \(.*\)$:s/`\2`/\1/g: 75 s:\.:\\.:g 76 s:\[:\\[:g 77' $T.1 > $T.s 78 79rm -f $outy $outh 80 81( 82 sed 's:^\(.*\) \(.*\)$:%token \1:' $T.1 83 sed -f $T.s $in 84) > $outy 85 86( 87 sed 's:^\(.*\) \(.*\)$: { "\2", \1 },:' $T.1 88) > $outh 89