1 # Licensed to the .NET Foundation under one or more agreements.
2 # The .NET Foundation licenses this file to you under the MIT license.
3 # See the LICENSE file in the project root for more information.
5 # a simple script that extracts the grammar from a yacc file
7 undef $/; # read in the whole file
9 $file =~ /^(.*)%%(.*)%%/s || die "Could not find %% markers";
14 #foreach $line (split /\n/s, $prefix) {
15 # if ($line =~ /^\s*%token/) {
16 # $line =~ s/\s*<.*>//g;
21 # remove any text in {}
22 while ($grammar =~ s/\s*([^']){[^{}]*}/$1/sg) {}
24 # change keyword identifiers into the string they represent
25 $grammar =~ s/\b([A-Z0-9_]+)_\b/'\L$1\E'/sg;
27 # change assembler directives into their string
28 $grammar =~ s/\b_([A-Z0-9]+)\b/'\L.$1\E'/sg;
30 # do the special punctuation by hand
31 $grammar =~ s/\bELIPSIS\b/'...'/sg;
32 $grammar =~ s/\bDCOLON\b/'::'/sg;
35 # remove TODO comments
36 $grammar =~ s/\n\s*\/\*[^\n]*TODO[^\n]*\*\/\s*\n/\n/sg;
39 print "Lexical tokens\n";
40 print " ID - C style alphaNumeric identifier (e.g. Hello_There2)\n";
41 print " DOTTEDNAME - Sequence of dot-separated IDs (e.g. System.Object)\n";
42 print " QSTRING - C style quoted string (e.g. \"hi\\n\")\n";
43 print " SQSTRING - C style singlely quoted string(e.g. 'hi')\n";
44 print " INT32 - C style 32 bit integer (e.g. 235, 03423, 0x34FFF)\n";
45 print " INT64 - C style 64 bit integer (e.g. -2353453636235234, 0x34FFFFFFFFFF)\n";
46 print " FLOAT64 - C style floating point number (e.g. -0.2323, 354.3423, 3435.34E-5)\n";
47 print " INSTR_* - IL instructions of a particular class (see opcode.def).\n";
48 print " HEXBYTE - 1- or 2-digit hexadecimal number (e.g., A2, F0).\n";
49 print "Auxiliary lexical tokens\n";
50 print " TYPEDEF_T - Aliased class (TypeDef or TypeRef).\n";
51 print " TYPEDEF_M - Aliased method.\n";
52 print " TYPEDEF_F - Aliased field.\n";
53 print " TYPEDEF_TS - Aliased type specification (TypeSpec).\n";
54 print " TYPEDEF_MR - Aliased field/method reference (MemberRef).\n";
55 print " TYPEDEF_CA - Aliased Custom Attribute.\n";
56 print "----------------------------------------------------------------------------------\n";
57 print "START : decls\n";