├── Documents ├── PA1.pdf ├── PA2.pdf ├── PA3.pdf ├── PA4.pdf └── cool-manual.pdf ├── Final_Project ├── AST.h ├── syntax.h ├── Debug.rar ├── Final_Project.exe ├── KelukinSupport.h ├── Others │ ├── syntax - 副本.h │ ├── syntax - 副本 (2).h │ ├── lexer_result - 副本.txt │ ├── lexer_result - 副本 (3).txt │ ├── lexer_result - 副本 (4).txt │ ├── result.txt │ └── lexer_result - 副本 (2).txt ├── Final_Project.layout ├── Final_Project.depend ├── Final_Project.cbp ├── Symbol_table.txt ├── main.cpp └── lexer_result.txt ├── syntax12270.00.txt ├── CoolLexer ├── CoolLexer.exe ├── PT.txt ├── KT.txt ├── tmp.txt ├── lexer_result.txt └── CoolLexer.cpp ├── CoolParser ├── CoolParser │ ├── syntax12270.00.txt │ ├── PT.txt │ ├── KT.txt │ ├── AST.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── CoolParser.csproj │ ├── Program.cs │ ├── result.txt │ └── SubProgram.cs └── CoolParser.sln ├── QuadDefinition.txt ├── .gitignore └── README.md /Documents/PA1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Documents/PA1.pdf -------------------------------------------------------------------------------- /Documents/PA2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Documents/PA2.pdf -------------------------------------------------------------------------------- /Documents/PA3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Documents/PA3.pdf -------------------------------------------------------------------------------- /Documents/PA4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Documents/PA4.pdf -------------------------------------------------------------------------------- /Final_Project/AST.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Final_Project/AST.h -------------------------------------------------------------------------------- /syntax12270.00.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/syntax12270.00.txt -------------------------------------------------------------------------------- /Final_Project/syntax.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Final_Project/syntax.h -------------------------------------------------------------------------------- /CoolLexer/CoolLexer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/CoolLexer/CoolLexer.exe -------------------------------------------------------------------------------- /Final_Project/Debug.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Final_Project/Debug.rar -------------------------------------------------------------------------------- /Documents/cool-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Documents/cool-manual.pdf -------------------------------------------------------------------------------- /Final_Project/Final_Project.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Final_Project/Final_Project.exe -------------------------------------------------------------------------------- /Final_Project/KelukinSupport.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Final_Project/KelukinSupport.h -------------------------------------------------------------------------------- /Final_Project/Others/syntax - 副本.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Final_Project/Others/syntax - 副本.h -------------------------------------------------------------------------------- /Final_Project/Others/syntax - 副本 (2).h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/Final_Project/Others/syntax - 副本 (2).h -------------------------------------------------------------------------------- /CoolParser/CoolParser/syntax12270.00.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OscarXvita/CoolCompiler/HEAD/CoolParser/CoolParser/syntax12270.00.txt -------------------------------------------------------------------------------- /CoolLexer/PT.txt: -------------------------------------------------------------------------------- 1 | : 51 2 | ; 52 3 | <- 53 4 | . 54 5 | @ 55 6 | + 56 7 | - 57 8 | * 58 9 | / 59 10 | ~ 60 11 | < 61 12 | <= 62 13 | == 63 14 | = 64 15 | ( 65 16 | ) 66 17 | { 67 18 | } 68 19 | => 69 20 | , 72 21 | -------------------------------------------------------------------------------- /CoolParser/CoolParser/PT.txt: -------------------------------------------------------------------------------- 1 | : 51 2 | ; 52 3 | <- 53 4 | . 54 5 | @ 55 6 | + 56 7 | - 57 8 | * 58 9 | / 59 10 | ~ 60 11 | < 61 12 | <= 62 13 | == 63 14 | = 64 15 | ( 65 16 | ) 66 17 | { 67 18 | } 68 19 | => 69 20 | , 72 21 | -------------------------------------------------------------------------------- /CoolLexer/KT.txt: -------------------------------------------------------------------------------- 1 | class 09 2 | else 10 3 | false 11 4 | fi 12 5 | if 13 6 | in 14 7 | inherits 15 8 | isvoid 16 9 | let 17 10 | loop 18 11 | pool 19 12 | then 20 13 | while 21 14 | case 22 15 | esac 23 16 | new 24 17 | of 25 18 | not 26 19 | true 27 20 | self 29 21 | -------------------------------------------------------------------------------- /CoolParser/CoolParser/KT.txt: -------------------------------------------------------------------------------- 1 | class 09 2 | else 10 3 | false 11 4 | fi 12 5 | if 13 6 | in 14 7 | inherits 15 8 | isvoid 16 9 | let 17 10 | loop 18 11 | pool 19 12 | then 20 13 | while 21 14 | case 22 15 | esac 23 16 | new 24 17 | of 25 18 | not 26 19 | true 27 20 | self 29 21 | -------------------------------------------------------------------------------- /CoolParser/CoolParser/AST.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CoolParser 6 | { 7 | class AST 8 | { 9 | abstract class Node 10 | { 11 | private int lineNumber; 12 | } 13 | 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /QuadDefinition.txt: -------------------------------------------------------------------------------- 1 | 赋值语句 2 | 1:( <-, x, _ , y) 3 | ( <-, x, _ , y)将x的值赋值给y 4 | ( +, x, y, z) 5 | ( - , x, y, z) 6 | ( * , x, y, z) 7 | ( /, x, y, z) 8 | ( not, x, _, z)将x取非后的值付给z 9 | ( isvoid, x, _, y) 检查x是否为void, Bool型的结果赋值给y 用于case 10 | ( ~, x, _, y) 将x按位取反后的结果付给y 11 | 12 | 13 | ( j<, x, y, z) 当x 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /CoolParser/CoolParser.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoolParser", "CoolParser\CoolParser.csproj", "{5DDD7451-DEDB-4818-A6BD-6CE3767A7562}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5DDD7451-DEDB-4818-A6BD-6CE3767A7562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {5DDD7451-DEDB-4818-A6BD-6CE3767A7562}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {5DDD7451-DEDB-4818-A6BD-6CE3767A7562}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {5DDD7451-DEDB-4818-A6BD-6CE3767A7562}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /CoolParser/CoolParser/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("CoolParser")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CoolParser")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("5ddd7451-dedb-4818-a6bd-6ce3767a7562")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Final_Project/Final_Project.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1482940390 source:d:\my_college\compiler\final_project\main.cpp 3 | 4 | 5 | 6 | "syntax.h" 7 | 8 | 1482941805 d:\my_college\compiler\final_project\syntax.h 9 | 10 | 11 | 12 | "AST.h" 13 | "KelukinSupport.h" 14 | 15 | 1482905431 d:\my_college\compiler\final_project\ast.h 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 1482892917 d:\my_college\compiler\final_project\kelukinsupport.h 28 | 29 | 1482945397 source:c:\users\oscar\documents\github\coolcompiler\final_project\main.cpp 30 | 31 | 32 | 33 | "syntax.h" 34 | 35 | 1482945397 c:\users\oscar\documents\github\coolcompiler\final_project\syntax.h 36 | 37 | 38 | 39 | "AST.h" 40 | "KelukinSupport.h" 41 | 42 | 1482945397 c:\users\oscar\documents\github\coolcompiler\final_project\ast.h 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 1482945397 c:\users\oscar\documents\github\coolcompiler\final_project\kelukinsupport.h 55 | 56 | -------------------------------------------------------------------------------- /Final_Project/Final_Project.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 44 | 45 | -------------------------------------------------------------------------------- /Final_Project/Symbol_table.txt: -------------------------------------------------------------------------------- 1 | Class_name Father_class Width 2 | Object _____ 0 3 | Int Object 4 4 | String Object 256 5 | Bool Object 1 6 | IO Object 0 7 | Book IO 512 8 | Var_table 9 | Name Type Begin_offset 10 | author String 256 11 | title String 0 12 | Article Book 512 13 | Var_table 14 | Name Type Begin_offset 15 | author String 256 16 | per_title String 256 17 | title String 0 18 | BookList IO 0 19 | --------------------------- 20 | Const_value_table: 21 | Value Width 22 | --------------------------- 23 | Const_string_table: 24 | string Width 25 | "\n" 2 26 | "author: " 12 27 | "periodical: " 13 28 | "title: " 12 29 | --------------------------- 30 | Method_table: 31 | Name Type 32 | Object.abort Int 33 | Object.type_name String 34 | Object.copy SELF_TYPE 35 | String.length Int 36 | String.concat String 37 | parameter_table 38 | Name Type 39 | s String 40 | String.substr String 41 | parameter_table 42 | Name Type 43 | i Int 44 | l Int 45 | IO.out_string SELF_TYPE 46 | parameter_table 47 | Name Type 48 | x String 49 | IO.out_int SELF_TYPE 50 | parameter_table 51 | Name Type 52 | x Int 53 | IO.in_string String 54 | IO.in_int Int 55 | Book.initBook Book 56 | parameter_table 57 | Name Type 58 | title_p String 59 | author_p String 60 | Book.print Book 61 | Article.initArticle Article 62 | parameter_table 63 | Name Type 64 | title_p String 65 | author_p String 66 | per_title_p String 67 | Article.print Book 68 | BookList.isNil Bool 69 | BookList.cons SELF_TYPE 70 | parameter_table 71 | Name Type 72 | hd Book 73 | -------------------------------------------------------------------------------- /Final_Project/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "syntax.h" 5 | using namespace std; 6 | void Out_table() 7 | { 8 | freopen("Symbol_table.txt", "w",stdout); 9 | printf("Class_name\tFather_class\tWidth\n"); 10 | for(int i=0; iTname<<"\t\t"; 15 | else cout<<"_____\t\t"; 16 | cout<::iterator Ii=pool[i].attribute_table.begin(); 18 | map::iterator Is=pool[i].attribute_type_table.begin(); 19 | if(Ii != pool[i].attribute_table.end()) 20 | { 21 | cout<<"\tVar_table\n\tName\tType\tBegin_offset\n"; 22 | while(Ii!=pool[i].attribute_table.end()) 23 | { 24 | cout<<"\t"<first<<"\t"<second<<"\t"<second<::iterator It=Const_value.begin(); 32 | while(It != Const_value.end()) 33 | { 34 | cout<first<<"\t"<second<first<<"\t"<second<Tname<<"."<Tname<Tname<0) cout< 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5DDD7451-DEDB-4818-A6BD-6CE3767A7562} 8 | Exe 9 | Properties 10 | CoolParser 11 | CoolParser 12 | v2.0 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | Always 50 | 51 | 52 | 53 | 54 | 61 | -------------------------------------------------------------------------------- /CoolParser/CoolParser/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Net.Mime; 6 | using System.Runtime.CompilerServices; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using static CoolParser.SubProgram; 10 | 11 | namespace CoolParser 12 | { 13 | class Program 14 | { 15 | 16 | public static Stack SemanticStack=new Stack(); 17 | public static Queue TokenList=new Queue(); 18 | static void Main(string[] args) 19 | { 20 | FileInfo info = new FileInfo("result.txt"); 21 | var tokens=info.OpenText(); 22 | int i = 0;//line counter 23 | try 24 | { 25 | while (!tokens.EndOfStream) 26 | { 27 | string lineNow = tokens.ReadLine(); 28 | 29 | 30 | i++; 31 | if (lineNow.Trim().Length != 0) 32 | ParseAddTokens(lineNow); 33 | 34 | } 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine("Error! " + ex.Message); 39 | return; 40 | 41 | } 42 | 43 | 44 | try 45 | { 46 | SubProgram sub = new SubProgram(); 47 | sub.ProP(); 48 | } 49 | catch (ParserException e) 50 | { 51 | Console.WriteLine(e.Message); 52 | } 53 | 54 | Console.ReadLine(); 55 | } 56 | 57 | static void ParseAddTokens(string line) 58 | { 59 | 60 | var space1 = line.IndexOf(" "); 61 | var space2 = line.IndexOf(" ", space1 + 1); 62 | Token token = new Token(); 63 | token.LineNum = Convert.ToInt32(line.Substring(0, space1).Remove(0, 1)); 64 | 65 | if (space2 != -1) 66 | { 67 | //# 68 | 69 | token.tokens = Convert.ToInt32(line.Substring(space1 + 1, space2 - space1 - 1)); 70 | token.SetValue(line.Substring(space2 + 1, line.Length - space2 - 1)); 71 | } 72 | else 73 | { 74 | token.tokens = Convert.ToInt32(line.Substring(space1 + 1, line.Length - space1 - 1)); 75 | } 76 | 77 | Debug.WriteLine("Line"+token.LineNum+"\tToken:"+token.tokens+"\tValue:"+token.GetValue()); 78 | TokenList.Enqueue(token); 79 | } 80 | 81 | 82 | 83 | public class Token 84 | { 85 | private string _value; 86 | private int _tokens; 87 | private int _lineNum; 88 | 89 | public int LineNum 90 | { 91 | get { return _lineNum; } 92 | set { _lineNum = value; } 93 | } 94 | 95 | public int tokens 96 | { 97 | get { return _tokens; } 98 | set 99 | { 100 | if (value < 0) 101 | throw new FormatException("ILLEGAL TOKEN"); 102 | else 103 | _tokens = value; 104 | } 105 | } 106 | 107 | 108 | public void SetValue(string value) 109 | { 110 | 111 | _value = value; 112 | 113 | } 114 | 115 | public string GetValue() 116 | { 117 | return _value; 118 | } 119 | 120 | } 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /CoolLexer/tmp.txt: -------------------------------------------------------------------------------- 1 | -- example of static and dynamic type differing for a dispatch 2 | 3 | class Book inherits IO { 4 | title : String; 5 | author : String; 6 | 7 | initBook(title_p : String, author_p : String) : Book { 8 | { 9 | title <- title_p; 10 | author <- author_p; 11 | self; 12 | } 13 | }; 14 | 15 | print() : Book { 16 | { 17 | out_string("title: ").out_string(title).out_string("\n"); 18 | out_string("author: ").out_string(author).out_string("\n"); 19 | self; 20 | } 21 | }; 22 | }; 23 | 24 | class Article inherits Book { 25 | per_title : String; 26 | 27 | initArticle(title_p : String, author_p : String, 28 | per_title_p : String) : Article { 29 | { 30 | initBook(title_p, author_p); 31 | per_title <- per_title_p; 32 | self; 33 | } 34 | }; 35 | 36 | print() : Book { 37 | { 38 | self@Book.print(); 39 | out_string("periodical: ").out_string(per_title).out_string("\n"); 40 | self; 41 | } 42 | }; 43 | }; 44 | 45 | class BookList inherits IO { 46 | (* Since abort "returns" type Object, we have to add 47 | an expression of type Bool here to satisfy the typechecker. 48 | This code is unreachable, since abort() halts the program. 49 | *) 50 | isNil() : Bool { { abort(); true; } }; 51 | 52 | cons(hd : Book) : Cons { 53 | (let new_cell : Cons <- new Cons in 54 | new_cell.init(hd,self) 55 | ) 56 | }; 57 | 58 | (* Since abort "returns" type Object, we have to add 59 | an expression of type Book here to satisfy the typechecker. 60 | This code is unreachable, since abort() halts the program. 61 | *) 62 | car() : Book { { abort(); new Book; } }; 63 | 64 | (* Since abort "returns" type Object, we have to add 65 | an expression of type BookList here to satisfy the typechecker. 66 | This code is unreachable, since abort() halts the program. 67 | *) 68 | cdr() : BookList { { abort(); new BookList; } }; 69 | 70 | print_list() : Object { abort() }; 71 | }; 72 | 73 | class Cons inherits BookList { 74 | xcar : Book; -- We keep the car and cdr in attributes. 75 | xcdr : BookList; -- Because methods and features must have different names, 76 | -- we use xcar and xcdr for the attributes and reserve 77 | -- car and cdr for the features. 78 | 79 | isNil() : Bool { false }; 80 | 81 | init(hd : Book, tl : BookList) : Cons { 82 | { 83 | xcar <- hd; 84 | xcdr <- tl; 85 | self; 86 | } 87 | }; 88 | 89 | car() : Book { xcar }; 90 | 91 | cdr() : BookList { xcdr }; 92 | 93 | print_list() : Object { 94 | { 95 | case xcar.print() of 96 | dummy : Book => out_string("- dynamic type was Book -\n"); 97 | dummy : Article => out_string("- dynamic type was Article -\n"); 98 | esac; 99 | xcdr.print_list(); 100 | } 101 | }; 102 | }; 103 | 104 | class Nil inherits BookList { 105 | isNil() : Bool { true }; 106 | 107 | print_list() : Object { true }; 108 | }; 109 | 110 | 111 | class Main { 112 | 113 | books : BookList; 114 | 115 | main() : Object { 116 | (let a_book : Book <- 117 | (new Book).initBook("Compilers, Principles, Techniques, and Tools", 118 | "Aho, Sethi, and Ullman") 119 | in 120 | (let an_article : Article <- 121 | (new Article).initArticle("The Top 100 CD_ROMs", 122 | "Ulanoff", 123 | "PC Magazine") 124 | in 125 | { 126 | books <- (new Nil).cons(a_book).cons(an_article); 127 | books.print_list(); 128 | } 129 | ) -- end let an_article 130 | ) -- end let a_book 131 | }; 132 | }; 133 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | *.vcxproj.filters 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # .NET Core 47 | project.lock.json 48 | project.fragment.lock.json 49 | artifacts/ 50 | **/Properties/launchSettings.json 51 | 52 | *_i.c 53 | *_p.c 54 | *_i.h 55 | *.ilk 56 | *.meta 57 | *.obj 58 | *.pch 59 | *.pdb 60 | *.pgc 61 | *.pgd 62 | *.rsp 63 | *.sbr 64 | *.tlb 65 | *.tli 66 | *.tlh 67 | *.tmp 68 | *.tmp_proj 69 | *.log 70 | *.vspscc 71 | *.vssscc 72 | .builds 73 | *.pidb 74 | *.svclog 75 | *.scc 76 | 77 | # Chutzpah Test files 78 | _Chutzpah* 79 | 80 | # Visual C++ cache files 81 | ipch/ 82 | *.aps 83 | *.ncb 84 | *.opendb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | *.VC.db 89 | *.VC.VC.opendb 90 | 91 | # Visual Studio profiler 92 | *.psess 93 | *.vsp 94 | *.vspx 95 | *.sap 96 | 97 | # TFS 2012 Local Workspace 98 | $tf/ 99 | 100 | # Guidance Automation Toolkit 101 | *.gpState 102 | 103 | # ReSharper is a .NET coding add-in 104 | _ReSharper*/ 105 | *.[Rr]e[Ss]harper 106 | *.DotSettings.user 107 | 108 | # JustCode is a .NET coding add-in 109 | .JustCode 110 | 111 | # TeamCity is a build add-in 112 | _TeamCity* 113 | 114 | # DotCover is a Code Coverage Tool 115 | *.dotCover 116 | 117 | # Visual Studio code coverage results 118 | *.coverage 119 | *.coveragexml 120 | 121 | # NCrunch 122 | _NCrunch_* 123 | .*crunch*.local.xml 124 | nCrunchTemp_* 125 | 126 | # MightyMoose 127 | *.mm.* 128 | AutoTest.Net/ 129 | 130 | # Web workbench (sass) 131 | .sass-cache/ 132 | 133 | # Installshield output folder 134 | [Ee]xpress/ 135 | 136 | # DocProject is a documentation generator add-in 137 | DocProject/buildhelp/ 138 | DocProject/Help/*.HxT 139 | DocProject/Help/*.HxC 140 | DocProject/Help/*.hhc 141 | DocProject/Help/*.hhk 142 | DocProject/Help/*.hhp 143 | DocProject/Help/Html2 144 | DocProject/Help/html 145 | 146 | # Click-Once directory 147 | publish/ 148 | 149 | # Publish Web Output 150 | *.[Pp]ublish.xml 151 | *.azurePubxml 152 | # TODO: Comment the next line if you want to checkin your web deploy settings 153 | # but database connection strings (with potential passwords) will be unencrypted 154 | *.pubxml 155 | *.publishproj 156 | 157 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 158 | # checkin your Azure Web App publish settings, but sensitive information contained 159 | # in these scripts will be unencrypted 160 | PublishScripts/ 161 | 162 | # NuGet Packages 163 | *.nupkg 164 | # The packages folder can be ignored because of Package Restore 165 | **/packages/* 166 | # except build/, which is used as an MSBuild target. 167 | !**/packages/build/ 168 | # Uncomment if necessary however generally it will be regenerated when needed 169 | #!**/packages/repositories.config 170 | # NuGet v3's project.json files produces more ignoreable files 171 | *.nuget.props 172 | *.nuget.targets 173 | 174 | # Microsoft Azure Build Output 175 | csx/ 176 | *.build.csdef 177 | 178 | # Microsoft Azure Emulator 179 | ecf/ 180 | rcf/ 181 | 182 | # Windows Store app package directories and files 183 | AppPackages/ 184 | BundleArtifacts/ 185 | Package.StoreAssociation.xml 186 | _pkginfo.txt 187 | 188 | # Visual Studio cache files 189 | # files ending in .cache can be ignored 190 | *.[Cc]ache 191 | # but keep track of directories ending in .cache 192 | !*.[Cc]ache/ 193 | 194 | # Others 195 | ClientBin/ 196 | ~$* 197 | *~ 198 | *.dbmdl 199 | *.dbproj.schemaview 200 | *.jfm 201 | *.pfx 202 | *.publishsettings 203 | node_modules/ 204 | orleans.codegen.cs 205 | 206 | # Since there are multiple workflows, uncomment next line to ignore bower_components 207 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 208 | #bower_components/ 209 | 210 | # RIA/Silverlight projects 211 | Generated_Code/ 212 | 213 | # Backup & report files from converting an old project file 214 | # to a newer Visual Studio version. Backup files are not needed, 215 | # because we have git ;-) 216 | _UpgradeReport_Files/ 217 | Backup*/ 218 | UpgradeLog*.XML 219 | UpgradeLog*.htm 220 | 221 | # SQL Server files 222 | *.mdf 223 | *.ldf 224 | 225 | # Business Intelligence projects 226 | *.rdl.data 227 | *.bim.layout 228 | *.bim_*.settings 229 | 230 | # Microsoft Fakes 231 | FakesAssemblies/ 232 | 233 | # GhostDoc plugin setting file 234 | *.GhostDoc.xml 235 | 236 | # Node.js Tools for Visual Studio 237 | .ntvs_analysis.dat 238 | 239 | # Visual Studio 6 build log 240 | *.plg 241 | 242 | # Visual Studio 6 workspace options file 243 | *.opt 244 | 245 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 246 | *.vbw 247 | 248 | # Visual Studio LightSwitch build output 249 | **/*.HTMLClient/GeneratedArtifacts 250 | **/*.DesktopClient/GeneratedArtifacts 251 | **/*.DesktopClient/ModelManifest.xml 252 | **/*.Server/GeneratedArtifacts 253 | **/*.Server/ModelManifest.xml 254 | _Pvt_Extensions 255 | 256 | # Paket dependency manager 257 | .paket/paket.exe 258 | paket-files/ 259 | 260 | # FAKE - F# Make 261 | .fake/ 262 | 263 | # JetBrains Rider 264 | .idea/ 265 | *.sln.iml 266 | 267 | # CodeRush 268 | .cr/ 269 | 270 | # Python Tools for Visual Studio (PTVS) 271 | __pycache__/ 272 | *.pyc 273 | 274 | # Cake - Uncomment if you are using it 275 | # tools/ 276 | Final_Project/Symbol_table.txt -------------------------------------------------------------------------------- /Final_Project/Others/lexer_result - 副本.txt: -------------------------------------------------------------------------------- 1 | #13 9 2 | #13 4 A2I 3 | #13 67 4 | #15 0 c2i 5 | #15 65 6 | #15 0 char 7 | #15 51 8 | #15 4 String 9 | #15 66 10 | #15 51 11 | #15 4 Int 12 | #15 67 13 | #16 13 14 | #16 0 char 15 | #16 64 16 | #16 2 "0" 17 | #16 20 18 | #16 3 0 19 | #16 10 20 | #17 13 21 | #17 0 char 22 | #17 64 23 | #17 2 "1" 24 | #17 20 25 | #17 3 1 26 | #17 10 27 | #18 13 28 | #18 0 char 29 | #18 64 30 | #18 2 "2" 31 | #18 20 32 | #18 3 2 33 | #18 10 34 | #19 13 35 | #19 0 char 36 | #19 64 37 | #19 2 "3" 38 | #19 20 39 | #19 3 3 40 | #19 10 41 | #20 13 42 | #20 0 char 43 | #20 64 44 | #20 2 "4" 45 | #20 20 46 | #20 3 4 47 | #20 10 48 | #21 13 49 | #21 0 char 50 | #21 64 51 | #21 2 "5" 52 | #21 20 53 | #21 3 5 54 | #21 10 55 | #22 13 56 | #22 0 char 57 | #22 64 58 | #22 2 "6" 59 | #22 20 60 | #22 3 6 61 | #22 10 62 | #23 13 63 | #23 0 char 64 | #23 64 65 | #23 2 "7" 66 | #23 20 67 | #23 3 7 68 | #23 10 69 | #24 13 70 | #24 0 char 71 | #24 64 72 | #24 2 "8" 73 | #24 20 74 | #24 3 8 75 | #24 10 76 | #25 13 77 | #25 0 char 78 | #25 64 79 | #25 2 "9" 80 | #25 20 81 | #25 3 9 82 | #25 10 83 | #26 67 84 | #26 0 abort 85 | #26 65 86 | #26 66 87 | #26 52 88 | #26 3 0 89 | #26 52 90 | #26 68 91 | #27 12 92 | #27 12 93 | #27 12 94 | #27 12 95 | #27 12 96 | #27 12 97 | #27 12 98 | #27 12 99 | #27 12 100 | #27 12 101 | #28 68 102 | #28 52 103 | #33 0 i2c 104 | #33 65 105 | #33 0 i 106 | #33 51 107 | #33 4 Int 108 | #33 66 109 | #33 51 110 | #33 4 String 111 | #33 67 112 | #34 13 113 | #34 0 i 114 | #34 64 115 | #34 3 0 116 | #34 20 117 | #34 2 "0" 118 | #34 10 119 | #35 13 120 | #35 0 i 121 | #35 64 122 | #35 3 1 123 | #35 20 124 | #35 2 "1" 125 | #35 10 126 | #36 13 127 | #36 0 i 128 | #36 64 129 | #36 3 2 130 | #36 20 131 | #36 2 "2" 132 | #36 10 133 | #37 13 134 | #37 0 i 135 | #37 64 136 | #37 3 3 137 | #37 20 138 | #37 2 "3" 139 | #37 10 140 | #38 13 141 | #38 0 i 142 | #38 64 143 | #38 3 4 144 | #38 20 145 | #38 2 "4" 146 | #38 10 147 | #39 13 148 | #39 0 i 149 | #39 64 150 | #39 3 5 151 | #39 20 152 | #39 2 "5" 153 | #39 10 154 | #40 13 155 | #40 0 i 156 | #40 64 157 | #40 3 6 158 | #40 20 159 | #40 2 "6" 160 | #40 10 161 | #41 13 162 | #41 0 i 163 | #41 64 164 | #41 3 7 165 | #41 20 166 | #41 2 "7" 167 | #41 10 168 | #42 13 169 | #42 0 i 170 | #42 64 171 | #42 3 8 172 | #42 20 173 | #42 2 "8" 174 | #42 10 175 | #43 13 176 | #43 0 i 177 | #43 64 178 | #43 3 9 179 | #43 20 180 | #43 2 "9" 181 | #43 10 182 | #44 67 183 | #44 0 abort 184 | #44 65 185 | #44 66 186 | #44 52 187 | #44 2 "" 188 | #44 52 189 | #44 68 190 | #45 12 191 | #45 12 192 | #45 12 193 | #45 12 194 | #45 12 195 | #45 12 196 | #45 12 197 | #45 12 198 | #45 12 199 | #45 12 200 | #46 68 201 | #46 52 202 | #58 0 a2i_aux 203 | #58 65 204 | #58 0 s 205 | #58 51 206 | #58 4 String 207 | #58 66 208 | #58 51 209 | #58 4 Int 210 | #58 67 211 | #59 65 212 | #59 17 213 | #59 0 int 214 | #59 51 215 | #59 4 Int 216 | #59 53 217 | #59 3 0 218 | #59 14 219 | #60 67 220 | #61 65 221 | #61 17 222 | #61 0 j 223 | #61 51 224 | #61 4 Int 225 | #61 53 226 | #61 0 s 227 | #61 54 228 | #61 0 length 229 | #61 65 230 | #61 66 231 | #61 14 232 | #62 65 233 | #62 17 234 | #62 0 i 235 | #62 51 236 | #62 4 Int 237 | #62 53 238 | #62 3 0 239 | #62 14 240 | #63 21 241 | #63 0 i 242 | #63 61 243 | #63 0 j 244 | #63 18 245 | #64 67 246 | #65 0 int 247 | #65 53 248 | #65 0 int 249 | #65 58 250 | #65 3 10 251 | #65 56 252 | #65 0 c2i 253 | #65 65 254 | #65 0 s 255 | #65 54 256 | #65 0 substr 257 | #65 65 258 | #65 0 i 259 | #65 72 260 | #65 3 1 261 | #65 66 262 | #65 66 263 | #65 52 264 | #66 0 i 265 | #66 53 266 | #66 0 i 267 | #66 56 268 | #66 3 1 269 | #66 52 270 | #67 68 271 | #68 19 272 | #69 66 273 | #70 66 274 | #70 52 275 | #71 0 int 276 | #71 52 277 | #72 68 278 | #73 66 279 | #74 68 280 | #74 52 281 | #76 0 a2i 282 | #76 65 283 | #76 0 s 284 | #76 51 285 | #76 4 String 286 | #76 66 287 | #76 51 288 | #76 4 Int 289 | #76 67 290 | #77 13 291 | #77 0 s 292 | #77 54 293 | #77 0 length 294 | #77 65 295 | #77 66 296 | #77 64 297 | #77 3 0 298 | #77 20 299 | #77 3 0 300 | #77 10 301 | #78 13 302 | #78 0 s 303 | #78 54 304 | #78 0 substr 305 | #78 65 306 | #78 3 0 307 | #78 72 308 | #78 3 1 309 | #78 66 310 | #78 64 311 | #78 2 "-" 312 | #78 20 313 | #78 60 314 | #78 0 a2i_aux 315 | #78 65 316 | #78 0 s 317 | #78 54 318 | #78 0 substr 319 | #78 65 320 | #78 3 1 321 | #78 72 322 | #78 0 s 323 | #78 54 324 | #78 0 length 325 | #78 65 326 | #78 66 327 | #78 57 328 | #78 3 1 329 | #78 66 330 | #78 66 331 | #78 10 332 | #79 13 333 | #79 0 s 334 | #79 54 335 | #79 0 substr 336 | #79 65 337 | #79 3 0 338 | #79 72 339 | #79 3 1 340 | #79 66 341 | #79 64 342 | #79 2 "+" 343 | #79 20 344 | #79 0 a2i_aux 345 | #79 65 346 | #79 0 s 347 | #79 54 348 | #79 0 substr 349 | #79 65 350 | #79 3 1 351 | #79 72 352 | #79 0 s 353 | #79 54 354 | #79 0 length 355 | #79 65 356 | #79 66 357 | #79 57 358 | #79 3 1 359 | #79 66 360 | #79 66 361 | #79 10 362 | #80 0 a2i_aux 363 | #80 65 364 | #80 0 s 365 | #80 66 366 | #81 12 367 | #81 12 368 | #81 12 369 | #82 68 370 | #82 52 371 | #94 0 i2a_aux 372 | #94 65 373 | #94 0 i 374 | #94 51 375 | #94 4 Int 376 | #94 66 377 | #94 51 378 | #94 4 String 379 | #94 67 380 | #95 13 381 | #95 0 i 382 | #95 64 383 | #95 3 0 384 | #95 20 385 | #95 2 "" 386 | #95 10 387 | #96 65 388 | #96 17 389 | #96 0 next 390 | #96 51 391 | #96 4 Int 392 | #96 53 393 | #96 0 i 394 | #96 59 395 | #96 3 10 396 | #96 14 397 | #97 0 i2a_aux 398 | #97 65 399 | #97 0 next 400 | #97 66 401 | #97 54 402 | #97 0 concat 403 | #97 65 404 | #97 0 i2c 405 | #97 65 406 | #97 0 i 407 | #97 57 408 | #97 0 next 409 | #97 58 410 | #97 3 10 411 | #97 66 412 | #97 66 413 | #98 66 414 | #99 12 415 | #100 68 416 | #100 52 417 | #102 0 i2a 418 | #102 65 419 | #102 0 i 420 | #102 51 421 | #102 4 Int 422 | #102 66 423 | #102 51 424 | #102 4 String 425 | #102 67 426 | #103 13 427 | #103 0 i 428 | #103 64 429 | #103 3 0 430 | #103 20 431 | #103 2 "0" 432 | #103 10 433 | #104 13 434 | #104 3 0 435 | #104 61 436 | #104 0 i 437 | #104 20 438 | #104 0 i2a_aux 439 | #104 65 440 | #104 0 i 441 | #104 66 442 | #104 10 443 | #105 2 "-" 444 | #105 54 445 | #105 0 concat 446 | #105 65 447 | #105 0 i2a_aux 448 | #105 65 449 | #105 0 i 450 | #105 58 451 | #105 60 452 | #105 3 1 453 | #105 66 454 | #105 66 455 | #106 12 456 | #106 12 457 | #107 68 458 | #107 52 459 | #114 68 460 | #114 52 461 | #115 10086 -------------------------------------------------------------------------------- /Final_Project/Others/lexer_result - 副本 (3).txt: -------------------------------------------------------------------------------- 1 | #13 9 2 | #13 4 A2I 3 | #13 67 4 | #15 0 c2i 5 | #15 65 6 | #15 0 char 7 | #15 51 8 | #15 4 String 9 | #15 66 10 | #15 51 11 | #15 4 Int 12 | #15 67 13 | #16 13 14 | #16 0 char 15 | #16 64 16 | #16 2 "0" 17 | #16 20 18 | #16 3 0 19 | #16 10 20 | #17 13 21 | #17 0 char 22 | #17 64 23 | #17 2 "1" 24 | #17 20 25 | #17 3 1 26 | #17 10 27 | #18 13 28 | #18 0 char 29 | #18 64 30 | #18 2 "2" 31 | #18 20 32 | #18 3 2 33 | #18 10 34 | #19 13 35 | #19 0 char 36 | #19 64 37 | #19 2 "3" 38 | #19 20 39 | #19 3 3 40 | #19 10 41 | #20 13 42 | #20 0 char 43 | #20 64 44 | #20 2 "4" 45 | #20 20 46 | #20 3 4 47 | #20 10 48 | #21 13 49 | #21 0 char 50 | #21 64 51 | #21 2 "5" 52 | #21 20 53 | #21 3 5 54 | #21 10 55 | #22 13 56 | #22 0 char 57 | #22 64 58 | #22 2 "6" 59 | #22 20 60 | #22 3 6 61 | #22 10 62 | #23 13 63 | #23 0 char 64 | #23 64 65 | #23 2 "7" 66 | #23 20 67 | #23 3 7 68 | #23 10 69 | #24 13 70 | #24 0 char 71 | #24 64 72 | #24 2 "8" 73 | #24 20 74 | #24 3 8 75 | #24 10 76 | #25 13 77 | #25 0 char 78 | #25 64 79 | #25 2 "9" 80 | #25 20 81 | #25 3 9 82 | #25 10 83 | #26 67 84 | #26 0 abort 85 | #26 65 86 | #26 66 87 | #26 52 88 | #26 3 0 89 | #26 52 90 | #26 68 91 | #27 12 92 | #27 12 93 | #27 12 94 | #27 12 95 | #27 12 96 | #27 12 97 | #27 12 98 | #27 12 99 | #27 12 100 | #27 12 101 | #28 68 102 | #28 52 103 | #33 0 i2c 104 | #33 65 105 | #33 0 i 106 | #33 51 107 | #33 4 Int 108 | #33 66 109 | #33 51 110 | #33 4 String 111 | #33 67 112 | #34 13 113 | #34 0 i 114 | #34 64 115 | #34 3 0 116 | #34 20 117 | #34 2 "0" 118 | #34 10 119 | #35 13 120 | #35 0 i 121 | #35 64 122 | #35 3 1 123 | #35 20 124 | #35 2 "1" 125 | #35 10 126 | #36 13 127 | #36 0 i 128 | #36 64 129 | #36 3 2 130 | #36 20 131 | #36 2 "2" 132 | #36 10 133 | #37 13 134 | #37 0 i 135 | #37 64 136 | #37 3 3 137 | #37 20 138 | #37 2 "3" 139 | #37 10 140 | #38 13 141 | #38 0 i 142 | #38 64 143 | #38 3 4 144 | #38 20 145 | #38 2 "4" 146 | #38 10 147 | #39 13 148 | #39 0 i 149 | #39 64 150 | #39 3 5 151 | #39 20 152 | #39 2 "5" 153 | #39 10 154 | #40 13 155 | #40 0 i 156 | #40 64 157 | #40 3 6 158 | #40 20 159 | #40 2 "6" 160 | #40 10 161 | #41 13 162 | #41 0 i 163 | #41 64 164 | #41 3 7 165 | #41 20 166 | #41 2 "7" 167 | #41 10 168 | #42 13 169 | #42 0 i 170 | #42 64 171 | #42 3 8 172 | #42 20 173 | #42 2 "8" 174 | #42 10 175 | #43 13 176 | #43 0 i 177 | #43 64 178 | #43 3 9 179 | #43 20 180 | #43 2 "9" 181 | #43 10 182 | #44 67 183 | #44 0 abort 184 | #44 65 185 | #44 66 186 | #44 52 187 | #44 2 "" 188 | #44 52 189 | #44 68 190 | #45 12 191 | #45 12 192 | #45 12 193 | #45 12 194 | #45 12 195 | #45 12 196 | #45 12 197 | #45 12 198 | #45 12 199 | #45 12 200 | #46 68 201 | #46 52 202 | #58 0 a2i_aux 203 | #58 65 204 | #58 0 s 205 | #58 51 206 | #58 4 String 207 | #58 66 208 | #58 51 209 | #58 4 Int 210 | #58 67 211 | #59 65 212 | #59 17 213 | #59 0 int 214 | #59 51 215 | #59 4 Int 216 | #59 53 217 | #59 3 0 218 | #59 14 219 | #60 67 220 | #61 65 221 | #61 17 222 | #61 0 j 223 | #61 51 224 | #61 4 Int 225 | #61 53 226 | #61 0 s 227 | #61 54 228 | #61 0 length 229 | #61 65 230 | #61 66 231 | #61 14 232 | #62 65 233 | #62 17 234 | #62 0 i 235 | #62 51 236 | #62 4 Int 237 | #62 53 238 | #62 3 0 239 | #62 14 240 | #63 21 241 | #63 0 i 242 | #63 61 243 | #63 0 j 244 | #63 18 245 | #64 67 246 | #65 0 int 247 | #65 53 248 | #65 0 int 249 | #65 58 250 | #65 3 10 251 | #65 56 252 | #65 0 c2i 253 | #65 65 254 | #65 0 s 255 | #65 54 256 | #65 0 substr 257 | #65 65 258 | #65 0 i 259 | #65 72 260 | #65 3 1 261 | #65 66 262 | #65 66 263 | #65 52 264 | #66 0 i 265 | #66 53 266 | #66 0 i 267 | #66 56 268 | #66 3 1 269 | #66 52 270 | #67 68 271 | #68 19 272 | #69 66 273 | #70 66 274 | #70 52 275 | #71 0 int 276 | #71 52 277 | #72 68 278 | #73 66 279 | #74 68 280 | #74 52 281 | #76 0 a2i 282 | #76 65 283 | #76 0 s 284 | #76 51 285 | #76 4 String 286 | #76 66 287 | #76 51 288 | #76 4 Int 289 | #76 67 290 | #77 13 291 | #77 0 s 292 | #77 54 293 | #77 0 length 294 | #77 65 295 | #77 66 296 | #77 64 297 | #77 3 0 298 | #77 20 299 | #77 3 0 300 | #77 10 301 | #78 13 302 | #78 0 s 303 | #78 54 304 | #78 0 substr 305 | #78 65 306 | #78 3 0 307 | #78 72 308 | #78 3 1 309 | #78 66 310 | #78 64 311 | #78 2 "-" 312 | #78 20 313 | #78 60 314 | #78 0 a2i_aux 315 | #78 65 316 | #78 0 s 317 | #78 54 318 | #78 0 substr 319 | #78 65 320 | #78 3 1 321 | #78 72 322 | #78 0 s 323 | #78 54 324 | #78 0 length 325 | #78 65 326 | #78 66 327 | #78 57 328 | #78 3 1 329 | #78 66 330 | #78 66 331 | #78 10 332 | #79 13 333 | #79 0 s 334 | #79 54 335 | #79 0 substr 336 | #79 65 337 | #79 3 0 338 | #79 72 339 | #79 3 1 340 | #79 66 341 | #79 64 342 | #79 2 "+" 343 | #79 20 344 | #79 0 a2i_aux 345 | #79 65 346 | #79 0 s 347 | #79 54 348 | #79 0 substr 349 | #79 65 350 | #79 3 1 351 | #79 72 352 | #79 0 s 353 | #79 54 354 | #79 0 length 355 | #79 65 356 | #79 66 357 | #79 57 358 | #79 3 1 359 | #79 66 360 | #79 66 361 | #79 10 362 | #80 0 a2i_aux 363 | #80 65 364 | #80 0 s 365 | #80 66 366 | #81 12 367 | #81 12 368 | #81 12 369 | #82 68 370 | #82 52 371 | #94 0 i2a_aux 372 | #94 65 373 | #94 0 i 374 | #94 51 375 | #94 4 Int 376 | #94 66 377 | #94 51 378 | #94 4 String 379 | #94 67 380 | #95 13 381 | #95 0 i 382 | #95 64 383 | #95 3 0 384 | #95 20 385 | #95 2 "" 386 | #95 10 387 | #96 65 388 | #96 17 389 | #96 0 next 390 | #96 51 391 | #96 4 Int 392 | #96 53 393 | #96 0 i 394 | #96 59 395 | #96 3 10 396 | #96 14 397 | #97 0 i2a_aux 398 | #97 65 399 | #97 0 next 400 | #97 66 401 | #97 54 402 | #97 0 concat 403 | #97 65 404 | #97 0 i2c 405 | #97 65 406 | #97 0 i 407 | #97 57 408 | #97 0 next 409 | #97 58 410 | #97 3 10 411 | #97 66 412 | #97 66 413 | #98 66 414 | #99 12 415 | #100 68 416 | #100 52 417 | #102 0 i2a 418 | #102 65 419 | #102 0 i 420 | #102 51 421 | #102 4 Int 422 | #102 66 423 | #102 51 424 | #102 4 String 425 | #102 67 426 | #103 13 427 | #103 0 i 428 | #103 64 429 | #103 3 0 430 | #103 20 431 | #103 2 "0" 432 | #103 10 433 | #104 13 434 | #104 3 0 435 | #104 61 436 | #104 0 i 437 | #104 20 438 | #104 0 i2a_aux 439 | #104 65 440 | #104 0 i 441 | #104 66 442 | #104 10 443 | #105 2 "-" 444 | #105 54 445 | #105 0 concat 446 | #105 65 447 | #105 0 i2a_aux 448 | #105 65 449 | #105 0 i 450 | #105 58 451 | #105 60 452 | #105 3 1 453 | #105 66 454 | #105 66 455 | #106 12 456 | #106 12 457 | #107 68 458 | #107 52 459 | #114 68 460 | #114 52 461 | #115 10086 -------------------------------------------------------------------------------- /Final_Project/Others/lexer_result - 副本 (4).txt: -------------------------------------------------------------------------------- 1 | #3 9 2 | #3 4 Book 3 | #3 15 4 | #3 4 IO 5 | #3 67 6 | #4 0 title 7 | #4 51 8 | #4 4 String 9 | #4 52 10 | #5 0 author 11 | #5 51 12 | #5 4 String 13 | #5 52 14 | #7 0 initBook 15 | #7 65 16 | #7 0 title_p 17 | #7 51 18 | #7 4 String 19 | #7 72 20 | #7 0 author_p 21 | #7 51 22 | #7 4 String 23 | #7 66 24 | #7 51 25 | #7 4 Book 26 | #7 67 27 | #8 67 28 | #9 0 title 29 | #9 53 30 | #9 0 title_p 31 | #9 52 32 | #10 0 author 33 | #10 53 34 | #10 0 author_p 35 | #10 52 36 | #11 29 37 | #11 52 38 | #12 68 39 | #13 68 40 | #13 52 41 | #15 0 print 42 | #15 65 43 | #15 66 44 | #15 51 45 | #15 4 Book 46 | #15 67 47 | #16 67 48 | #17 0 out_string 49 | #17 65 50 | #17 2 "title: " 51 | #17 66 52 | #17 54 53 | #17 0 out_string 54 | #17 65 55 | #17 0 title 56 | #17 66 57 | #17 54 58 | #17 0 out_string 59 | #17 65 60 | #17 2 "\n" 61 | #17 66 62 | #17 52 63 | #18 0 out_string 64 | #18 65 65 | #18 2 "author: " 66 | #18 66 67 | #18 54 68 | #18 0 out_string 69 | #18 65 70 | #18 0 author 71 | #18 66 72 | #18 54 73 | #18 0 out_string 74 | #18 65 75 | #18 2 "\n" 76 | #18 66 77 | #18 52 78 | #19 29 79 | #19 52 80 | #20 68 81 | #21 68 82 | #21 52 83 | #22 68 84 | #22 52 85 | #24 9 86 | #24 4 Article 87 | #24 15 88 | #24 4 Book 89 | #24 67 90 | #25 0 per_title 91 | #25 51 92 | #25 4 String 93 | #25 52 94 | #27 0 initArticle 95 | #27 65 96 | #27 0 title_p 97 | #27 51 98 | #27 4 String 99 | #27 72 100 | #27 0 author_p 101 | #27 51 102 | #27 4 String 103 | #27 72 104 | #28 0 per_title_p 105 | #28 51 106 | #28 4 String 107 | #28 66 108 | #28 51 109 | #28 4 Article 110 | #28 67 111 | #29 67 112 | #30 0 initBook 113 | #30 65 114 | #30 0 title_p 115 | #30 72 116 | #30 0 author_p 117 | #30 66 118 | #30 52 119 | #31 0 per_title 120 | #31 53 121 | #31 0 per_title_p 122 | #31 52 123 | #32 29 124 | #32 52 125 | #33 68 126 | #34 68 127 | #34 52 128 | #36 0 print 129 | #36 65 130 | #36 66 131 | #36 51 132 | #36 4 Book 133 | #36 67 134 | #37 67 135 | #38 29 136 | #38 55 137 | #38 4 Book 138 | #38 54 139 | #38 0 print 140 | #38 65 141 | #38 66 142 | #38 52 143 | #39 0 out_string 144 | #39 65 145 | #39 2 "periodical: " 146 | #39 66 147 | #39 54 148 | #39 0 out_string 149 | #39 65 150 | #39 0 per_title 151 | #39 66 152 | #39 54 153 | #39 0 out_string 154 | #39 65 155 | #39 2 "\n" 156 | #39 66 157 | #39 52 158 | #40 29 159 | #40 52 160 | #41 68 161 | #42 68 162 | #42 52 163 | #43 68 164 | #43 52 165 | #45 9 166 | #45 4 BookList 167 | #45 15 168 | #45 4 IO 169 | #45 67 170 | #50 0 isNil 171 | #50 65 172 | #50 66 173 | #50 51 174 | #50 4 Bool 175 | #50 67 176 | #50 67 177 | #50 0 abort 178 | #50 65 179 | #50 66 180 | #50 52 181 | #50 27 182 | #50 52 183 | #50 68 184 | #50 68 185 | #50 52 186 | #56 0 car 187 | #56 65 188 | #56 66 189 | #56 51 190 | #56 4 Book 191 | #56 67 192 | #56 67 193 | #56 0 abort 194 | #56 65 195 | #56 66 196 | #56 52 197 | #56 24 198 | #56 4 Book 199 | #56 52 200 | #56 68 201 | #56 68 202 | #56 52 203 | #62 0 cdr 204 | #62 65 205 | #62 66 206 | #62 51 207 | #62 4 BookList 208 | #62 67 209 | #62 67 210 | #62 0 abort 211 | #62 65 212 | #62 66 213 | #62 52 214 | #62 24 215 | #62 4 BookList 216 | #62 52 217 | #62 68 218 | #62 68 219 | #62 52 220 | #64 0 print_list 221 | #64 65 222 | #64 66 223 | #64 51 224 | #64 4 Object 225 | #64 67 226 | #64 0 abort 227 | #64 65 228 | #64 66 229 | #64 68 230 | #64 52 231 | #65 68 232 | #65 52 233 | #67 9 234 | #67 4 Nil 235 | #67 15 236 | #67 4 BookList 237 | #67 67 238 | #68 0 isNil 239 | #68 65 240 | #68 66 241 | #68 51 242 | #68 4 Bool 243 | #68 67 244 | #68 27 245 | #68 68 246 | #68 52 247 | #70 0 print_list 248 | #70 65 249 | #70 66 250 | #70 51 251 | #70 4 Object 252 | #70 67 253 | #70 27 254 | #70 68 255 | #70 52 256 | #71 68 257 | #71 52 258 | #73 9 259 | #73 4 Cons 260 | #73 15 261 | #73 4 BookList 262 | #73 67 263 | #74 0 xcar 264 | #74 51 265 | #74 4 Book 266 | #74 52 267 | #75 0 xcdr 268 | #75 51 269 | #75 4 BookList 270 | #75 52 271 | #79 0 isNil 272 | #79 65 273 | #79 66 274 | #79 51 275 | #79 4 Bool 276 | #79 67 277 | #79 11 278 | #79 68 279 | #79 52 280 | #81 0 init 281 | #81 65 282 | #81 0 hd 283 | #81 51 284 | #81 4 Book 285 | #81 72 286 | #81 0 tl 287 | #81 51 288 | #81 4 BookList 289 | #81 66 290 | #81 51 291 | #81 4 Cons 292 | #81 67 293 | #82 67 294 | #83 0 xcar 295 | #83 53 296 | #83 0 hd 297 | #83 52 298 | #84 0 xcdr 299 | #84 53 300 | #84 0 tl 301 | #84 52 302 | #85 29 303 | #85 52 304 | #86 68 305 | #87 68 306 | #87 52 307 | #89 0 car 308 | #89 65 309 | #89 66 310 | #89 51 311 | #89 4 Book 312 | #89 67 313 | #89 0 xcar 314 | #89 68 315 | #89 52 316 | #91 0 cdr 317 | #91 65 318 | #91 66 319 | #91 51 320 | #91 4 BookList 321 | #91 67 322 | #91 0 xcdr 323 | #91 68 324 | #91 52 325 | #93 0 print_list 326 | #93 65 327 | #93 66 328 | #93 51 329 | #93 4 Object 330 | #93 67 331 | #94 67 332 | #95 22 333 | #95 0 xcar 334 | #95 54 335 | #95 0 print 336 | #95 65 337 | #95 66 338 | #95 25 339 | #96 0 dummy 340 | #96 51 341 | #96 4 Book 342 | #96 69 343 | #96 0 out_string 344 | #96 65 345 | #96 2 "- dynamic type was Book -\n" 346 | #96 66 347 | #96 52 348 | #97 0 dummy 349 | #97 51 350 | #97 4 Article 351 | #97 69 352 | #97 0 out_string 353 | #97 65 354 | #97 2 "- dynamic type was Article -\n" 355 | #97 66 356 | #97 52 357 | #98 23 358 | #98 52 359 | #99 68 360 | #100 68 361 | #100 52 362 | #101 68 363 | #101 52 364 | #104 9 365 | #104 4 Main 366 | #104 67 367 | #106 0 books 368 | #106 51 369 | #106 4 BookList 370 | #106 52 371 | #108 0 main 372 | #108 65 373 | #108 66 374 | #108 51 375 | #108 4 Object 376 | #108 67 377 | #109 65 378 | #109 17 379 | #109 0 a_book 380 | #109 51 381 | #109 4 Book 382 | #109 53 383 | #110 65 384 | #110 24 385 | #110 4 Book 386 | #110 66 387 | #110 54 388 | #110 0 initBook 389 | #110 65 390 | #110 2 "Compilers, Principles, Techniques, and Tools" 391 | #110 72 392 | #111 2 "Aho, Sethi, and Ullman" 393 | #111 66 394 | #112 14 395 | #113 65 396 | #113 17 397 | #113 0 an_article 398 | #113 51 399 | #113 4 Article 400 | #113 53 401 | #114 65 402 | #114 24 403 | #114 4 Article 404 | #114 66 405 | #114 54 406 | #114 0 initArticle 407 | #114 65 408 | #114 2 "The Top 100 CD_ROMs" 409 | #114 72 410 | #115 2 "Ulanoff" 411 | #115 72 412 | #116 2 "PC Magazine" 413 | #116 66 414 | #117 14 415 | #118 67 416 | #119 0 books 417 | #119 54 418 | #119 0 print_list 419 | #119 65 420 | #119 66 421 | #119 52 422 | #120 68 423 | #121 66 424 | #122 66 425 | #123 68 426 | #123 52 427 | #124 68 428 | #124 52 429 | -------------------------------------------------------------------------------- /CoolLexer/lexer_result.txt: -------------------------------------------------------------------------------- 1 | #3 9 2 | #3 4 Book 3 | #3 15 4 | #3 4 IO 5 | #3 67 6 | #4 0 title 7 | #4 51 8 | #4 4 String 9 | #4 52 10 | #5 0 author 11 | #5 51 12 | #5 4 String 13 | #5 52 14 | #7 0 initBook 15 | #7 65 16 | #7 0 title_p 17 | #7 51 18 | #7 4 String 19 | #7 72 20 | #7 0 author_p 21 | #7 51 22 | #7 4 String 23 | #7 66 24 | #7 51 25 | #7 4 Book 26 | #7 67 27 | #8 67 28 | #9 0 title 29 | #9 53 30 | #9 0 title_p 31 | #9 52 32 | #10 0 author 33 | #10 53 34 | #10 0 author_p 35 | #10 52 36 | #11 29 37 | #11 52 38 | #12 68 39 | #13 68 40 | #13 52 41 | #15 0 print 42 | #15 65 43 | #15 66 44 | #15 51 45 | #15 4 Book 46 | #15 67 47 | #16 67 48 | #17 0 out_string 49 | #17 65 50 | #17 2 "title: " 51 | #17 66 52 | #17 54 53 | #17 0 out_string 54 | #17 65 55 | #17 0 title 56 | #17 66 57 | #17 54 58 | #17 0 out_string 59 | #17 65 60 | #17 2 "\n" 61 | #17 66 62 | #17 52 63 | #18 0 out_string 64 | #18 65 65 | #18 2 "author: " 66 | #18 66 67 | #18 54 68 | #18 0 out_string 69 | #18 65 70 | #18 0 author 71 | #18 66 72 | #18 54 73 | #18 0 out_string 74 | #18 65 75 | #18 2 "\n" 76 | #18 66 77 | #18 52 78 | #19 29 79 | #19 52 80 | #20 68 81 | #21 68 82 | #21 52 83 | #22 68 84 | #22 52 85 | #24 9 86 | #24 4 Article 87 | #24 15 88 | #24 4 Book 89 | #24 67 90 | #25 0 per_title 91 | #25 51 92 | #25 4 String 93 | #25 52 94 | #27 0 initArticle 95 | #27 65 96 | #27 0 title_p 97 | #27 51 98 | #27 4 String 99 | #27 72 100 | #27 0 author_p 101 | #27 51 102 | #27 4 String 103 | #27 72 104 | #28 0 per_title_p 105 | #28 51 106 | #28 4 String 107 | #28 66 108 | #28 51 109 | #28 4 Article 110 | #28 67 111 | #29 67 112 | #30 0 initBook 113 | #30 65 114 | #30 0 title_p 115 | #30 72 116 | #30 0 author_p 117 | #30 66 118 | #30 52 119 | #31 0 per_title 120 | #31 53 121 | #31 0 per_title_p 122 | #31 52 123 | #32 29 124 | #32 52 125 | #33 68 126 | #34 68 127 | #34 52 128 | #36 0 print 129 | #36 65 130 | #36 66 131 | #36 51 132 | #36 4 Book 133 | #36 67 134 | #37 67 135 | #38 29 136 | #38 55 137 | #38 4 Book 138 | #38 54 139 | #38 0 print 140 | #38 65 141 | #38 66 142 | #38 52 143 | #39 0 out_string 144 | #39 65 145 | #39 2 "periodical: " 146 | #39 66 147 | #39 54 148 | #39 0 out_string 149 | #39 65 150 | #39 0 per_title 151 | #39 66 152 | #39 54 153 | #39 0 out_string 154 | #39 65 155 | #39 2 "\n" 156 | #39 66 157 | #39 52 158 | #40 29 159 | #40 52 160 | #41 68 161 | #42 68 162 | #42 52 163 | #43 68 164 | #43 52 165 | #45 9 166 | #45 4 BookList 167 | #45 15 168 | #45 4 IO 169 | #45 67 170 | #50 0 isNil 171 | #50 65 172 | #50 66 173 | #50 51 174 | #50 4 Bool 175 | #50 67 176 | #50 67 177 | #50 0 abort 178 | #50 65 179 | #50 66 180 | #50 52 181 | #50 27 182 | #50 52 183 | #50 68 184 | #50 68 185 | #50 52 186 | #52 0 cons 187 | #52 65 188 | #52 0 hd 189 | #52 51 190 | #52 4 Book 191 | #52 66 192 | #52 51 193 | #52 4 Cons 194 | #52 67 195 | #53 65 196 | #53 17 197 | #53 0 new_cell 198 | #53 51 199 | #53 4 Cons 200 | #53 53 201 | #53 24 202 | #53 4 Cons 203 | #53 14 204 | #54 0 new_cell 205 | #54 54 206 | #54 0 init 207 | #54 65 208 | #54 0 hd 209 | #54 72 210 | #54 29 211 | #54 66 212 | #55 66 213 | #56 68 214 | #56 52 215 | #62 0 car 216 | #62 65 217 | #62 66 218 | #62 51 219 | #62 4 Book 220 | #62 67 221 | #62 67 222 | #62 0 abort 223 | #62 65 224 | #62 66 225 | #62 52 226 | #62 24 227 | #62 4 Book 228 | #62 52 229 | #62 68 230 | #62 68 231 | #62 52 232 | #68 0 cdr 233 | #68 65 234 | #68 66 235 | #68 51 236 | #68 4 BookList 237 | #68 67 238 | #68 67 239 | #68 0 abort 240 | #68 65 241 | #68 66 242 | #68 52 243 | #68 24 244 | #68 4 BookList 245 | #68 52 246 | #68 68 247 | #68 68 248 | #68 52 249 | #70 0 print_list 250 | #70 65 251 | #70 66 252 | #70 51 253 | #70 4 Object 254 | #70 67 255 | #70 0 abort 256 | #70 65 257 | #70 66 258 | #70 68 259 | #70 52 260 | #71 68 261 | #71 52 262 | #73 9 263 | #73 4 Cons 264 | #73 15 265 | #73 4 BookList 266 | #73 67 267 | #74 0 xcar 268 | #74 51 269 | #74 4 Book 270 | #74 52 271 | #75 0 xcdr 272 | #75 51 273 | #75 4 BookList 274 | #75 52 275 | #79 0 isNil 276 | #79 65 277 | #79 66 278 | #79 51 279 | #79 4 Bool 280 | #79 67 281 | #79 11 282 | #79 68 283 | #79 52 284 | #81 0 init 285 | #81 65 286 | #81 0 hd 287 | #81 51 288 | #81 4 Book 289 | #81 72 290 | #81 0 tl 291 | #81 51 292 | #81 4 BookList 293 | #81 66 294 | #81 51 295 | #81 4 Cons 296 | #81 67 297 | #82 67 298 | #83 0 xcar 299 | #83 53 300 | #83 0 hd 301 | #83 52 302 | #84 0 xcdr 303 | #84 53 304 | #84 0 tl 305 | #84 52 306 | #85 29 307 | #85 52 308 | #86 68 309 | #87 68 310 | #87 52 311 | #89 0 car 312 | #89 65 313 | #89 66 314 | #89 51 315 | #89 4 Book 316 | #89 67 317 | #89 0 xcar 318 | #89 68 319 | #89 52 320 | #91 0 cdr 321 | #91 65 322 | #91 66 323 | #91 51 324 | #91 4 BookList 325 | #91 67 326 | #91 0 xcdr 327 | #91 68 328 | #91 52 329 | #93 0 print_list 330 | #93 65 331 | #93 66 332 | #93 51 333 | #93 4 Object 334 | #93 67 335 | #94 67 336 | #95 22 337 | #95 0 xcar 338 | #95 54 339 | #95 0 print 340 | #95 65 341 | #95 66 342 | #95 25 343 | #96 0 dummy 344 | #96 51 345 | #96 4 Book 346 | #96 69 347 | #96 0 out_string 348 | #96 65 349 | #96 2 "- dynamic type was Book -\n" 350 | #96 66 351 | #96 52 352 | #97 0 dummy 353 | #97 51 354 | #97 4 Article 355 | #97 69 356 | #97 0 out_string 357 | #97 65 358 | #97 2 "- dynamic type was Article -\n" 359 | #97 66 360 | #97 52 361 | #98 23 362 | #98 52 363 | #99 0 xcdr 364 | #99 54 365 | #99 0 print_list 366 | #99 65 367 | #99 66 368 | #99 52 369 | #100 68 370 | #101 68 371 | #101 52 372 | #102 68 373 | #102 52 374 | #104 9 375 | #104 4 Nil 376 | #104 15 377 | #104 4 BookList 378 | #104 67 379 | #105 0 isNil 380 | #105 65 381 | #105 66 382 | #105 51 383 | #105 4 Bool 384 | #105 67 385 | #105 27 386 | #105 68 387 | #105 52 388 | #107 0 print_list 389 | #107 65 390 | #107 66 391 | #107 51 392 | #107 4 Object 393 | #107 67 394 | #107 27 395 | #107 68 396 | #107 52 397 | #108 68 398 | #108 52 399 | #111 9 400 | #111 4 Main 401 | #111 67 402 | #113 0 books 403 | #113 51 404 | #113 4 BookList 405 | #113 52 406 | #115 0 main 407 | #115 65 408 | #115 66 409 | #115 51 410 | #115 4 Object 411 | #115 67 412 | #116 65 413 | #116 17 414 | #116 0 a_book 415 | #116 51 416 | #116 4 Book 417 | #116 53 418 | #117 65 419 | #117 24 420 | #117 4 Book 421 | #117 66 422 | #117 54 423 | #117 0 initBook 424 | #117 65 425 | #117 2 "Compilers, Principles, Techniques, and Tools" 426 | #117 72 427 | #118 2 "Aho, Sethi, and Ullman" 428 | #118 66 429 | #119 14 430 | #120 65 431 | #120 17 432 | #120 0 an_article 433 | #120 51 434 | #120 4 Article 435 | #120 53 436 | #121 65 437 | #121 24 438 | #121 4 Article 439 | #121 66 440 | #121 54 441 | #121 0 initArticle 442 | #121 65 443 | #121 2 "The Top 100 CD_ROMs" 444 | #121 72 445 | #122 2 "Ulanoff" 446 | #122 72 447 | #123 2 "PC Magazine" 448 | #123 66 449 | #124 14 450 | #125 67 451 | #126 0 books 452 | #126 53 453 | #126 65 454 | #126 24 455 | #126 4 Nil 456 | #126 66 457 | #126 54 458 | #126 0 cons 459 | #126 65 460 | #126 0 a_book 461 | #126 66 462 | #126 54 463 | #126 0 cons 464 | #126 65 465 | #126 0 an_article 466 | #126 66 467 | #126 52 468 | #127 0 books 469 | #127 54 470 | #127 0 print_list 471 | #127 65 472 | #127 66 473 | #127 52 474 | #128 68 475 | #129 66 476 | #130 66 477 | #131 68 478 | #131 52 479 | #132 68 480 | #132 52 481 | -------------------------------------------------------------------------------- /Final_Project/lexer_result.txt: -------------------------------------------------------------------------------- 1 | #3 9 2 | #3 4 Book 3 | #3 15 4 | #3 4 IO 5 | #3 67 6 | #4 0 title 7 | #4 51 8 | #4 4 String 9 | #4 52 10 | #5 0 author 11 | #5 51 12 | #5 4 String 13 | #5 52 14 | #7 0 initBook 15 | #7 65 16 | #7 0 title_p 17 | #7 51 18 | #7 4 String 19 | #7 72 20 | #7 0 author_p 21 | #7 51 22 | #7 4 String 23 | #7 66 24 | #7 51 25 | #7 4 Book 26 | #7 67 27 | #8 67 28 | #9 0 title 29 | #9 53 30 | #9 0 title_p 31 | #9 52 32 | #10 0 author 33 | #10 53 34 | #10 0 author_p 35 | #10 52 36 | #11 29 37 | #11 52 38 | #12 68 39 | #13 68 40 | #13 52 41 | #15 0 print 42 | #15 65 43 | #15 66 44 | #15 51 45 | #15 4 Book 46 | #15 67 47 | #16 67 48 | #17 0 out_string 49 | #17 65 50 | #17 2 "title: " 51 | #17 66 52 | #17 54 53 | #17 0 out_string 54 | #17 65 55 | #17 0 title 56 | #17 66 57 | #17 54 58 | #17 0 out_string 59 | #17 65 60 | #17 2 "\n" 61 | #17 66 62 | #17 52 63 | #18 0 out_string 64 | #18 65 65 | #18 2 "author: " 66 | #18 66 67 | #18 54 68 | #18 0 out_string 69 | #18 65 70 | #18 0 author 71 | #18 66 72 | #18 54 73 | #18 0 out_string 74 | #18 65 75 | #18 2 "\n" 76 | #18 66 77 | #18 52 78 | #19 29 79 | #19 52 80 | #20 68 81 | #21 68 82 | #21 52 83 | #22 68 84 | #22 52 85 | #24 9 86 | #24 4 Article 87 | #24 15 88 | #24 4 Book 89 | #24 67 90 | #25 0 per_title 91 | #25 51 92 | #25 4 String 93 | #25 52 94 | #27 0 initArticle 95 | #27 65 96 | #27 0 title_p 97 | #27 51 98 | #27 4 String 99 | #27 72 100 | #27 0 author_p 101 | #27 51 102 | #27 4 String 103 | #27 72 104 | #28 0 per_title_p 105 | #28 51 106 | #28 4 String 107 | #28 66 108 | #28 51 109 | #28 4 Article 110 | #28 67 111 | #29 67 112 | #30 0 initBook 113 | #30 65 114 | #30 0 title_p 115 | #30 72 116 | #30 0 author_p 117 | #30 66 118 | #30 52 119 | #31 0 per_title 120 | #31 53 121 | #31 0 per_title_p 122 | #31 52 123 | #32 29 124 | #32 52 125 | #33 68 126 | #34 68 127 | #34 52 128 | #36 0 print 129 | #36 65 130 | #36 66 131 | #36 51 132 | #36 4 Book 133 | #36 67 134 | #37 67 135 | #38 29 136 | #38 55 137 | #38 4 Book 138 | #38 54 139 | #38 0 print 140 | #38 65 141 | #38 66 142 | #38 52 143 | #39 0 out_string 144 | #39 65 145 | #39 2 "periodical: " 146 | #39 66 147 | #39 54 148 | #39 0 out_string 149 | #39 65 150 | #39 0 per_title 151 | #39 66 152 | #39 54 153 | #39 0 out_string 154 | #39 65 155 | #39 2 "\n" 156 | #39 66 157 | #39 52 158 | #40 29 159 | #40 52 160 | #41 68 161 | #42 68 162 | #42 52 163 | #43 68 164 | #43 52 165 | #45 9 166 | #45 4 BookList 167 | #45 15 168 | #45 4 IO 169 | #45 67 170 | #50 0 isNil 171 | #50 65 172 | #50 66 173 | #50 51 174 | #50 4 Bool 175 | #50 67 176 | #50 67 177 | #50 0 abort 178 | #50 65 179 | #50 66 180 | #50 52 181 | #50 27 182 | #50 52 183 | #50 68 184 | #50 68 185 | #50 52 186 | #52 0 cons 187 | #52 65 188 | #52 0 hd 189 | #52 51 190 | #52 4 Book 191 | #52 66 192 | #52 51 193 | #52 4 Cons 194 | #52 67 195 | #53 65 196 | #53 17 197 | #53 0 new_cell 198 | #53 51 199 | #53 4 Cons 200 | #53 53 201 | #53 24 202 | #53 4 Cons 203 | #53 14 204 | #54 0 new_cell 205 | #54 54 206 | #54 0 init 207 | #54 65 208 | #54 0 hd 209 | #54 72 210 | #54 29 211 | #54 66 212 | #55 66 213 | #56 68 214 | #56 52 215 | #62 0 car 216 | #62 65 217 | #62 66 218 | #62 51 219 | #62 4 Book 220 | #62 67 221 | #62 67 222 | #62 0 abort 223 | #62 65 224 | #62 66 225 | #62 52 226 | #62 24 227 | #62 4 Book 228 | #62 52 229 | #62 68 230 | #62 68 231 | #62 52 232 | #68 0 cdr 233 | #68 65 234 | #68 66 235 | #68 51 236 | #68 4 BookList 237 | #68 67 238 | #68 67 239 | #68 0 abort 240 | #68 65 241 | #68 66 242 | #68 52 243 | #68 24 244 | #68 4 BookList 245 | #68 52 246 | #68 68 247 | #68 68 248 | #68 52 249 | #70 0 print_list 250 | #70 65 251 | #70 66 252 | #70 51 253 | #70 4 Object 254 | #70 67 255 | #70 0 abort 256 | #70 65 257 | #70 66 258 | #70 68 259 | #70 52 260 | #71 68 261 | #71 52 262 | #73 9 263 | #73 4 Cons 264 | #73 15 265 | #73 4 BookList 266 | #73 67 267 | #74 0 xcar 268 | #74 51 269 | #74 4 Book 270 | #74 52 271 | #75 0 xcdr 272 | #75 51 273 | #75 4 BookList 274 | #75 52 275 | #79 0 isNil 276 | #79 65 277 | #79 66 278 | #79 51 279 | #79 4 Bool 280 | #79 67 281 | #79 11 282 | #79 68 283 | #79 52 284 | #81 0 init 285 | #81 65 286 | #81 0 hd 287 | #81 51 288 | #81 4 Book 289 | #81 72 290 | #81 0 tl 291 | #81 51 292 | #81 4 BookList 293 | #81 66 294 | #81 51 295 | #81 4 Cons 296 | #81 67 297 | #82 67 298 | #83 0 xcar 299 | #83 53 300 | #83 0 hd 301 | #83 52 302 | #84 0 xcdr 303 | #84 53 304 | #84 0 tl 305 | #84 52 306 | #85 29 307 | #85 52 308 | #86 68 309 | #87 68 310 | #87 52 311 | #89 0 car 312 | #89 65 313 | #89 66 314 | #89 51 315 | #89 4 Book 316 | #89 67 317 | #89 0 xcar 318 | #89 68 319 | #89 52 320 | #91 0 cdr 321 | #91 65 322 | #91 66 323 | #91 51 324 | #91 4 BookList 325 | #91 67 326 | #91 0 xcdr 327 | #91 68 328 | #91 52 329 | #93 0 print_list 330 | #93 65 331 | #93 66 332 | #93 51 333 | #93 4 Object 334 | #93 67 335 | #94 67 336 | #95 22 337 | #95 0 xcar 338 | #95 54 339 | #95 0 print 340 | #95 65 341 | #95 66 342 | #95 25 343 | #96 0 dummy 344 | #96 51 345 | #96 4 Book 346 | #96 69 347 | #96 0 out_string 348 | #96 65 349 | #96 2 "- dynamic type was Book -\n" 350 | #96 66 351 | #96 52 352 | #97 0 dummy 353 | #97 51 354 | #97 4 Article 355 | #97 69 356 | #97 0 out_string 357 | #97 65 358 | #97 2 "- dynamic type was Article -\n" 359 | #97 66 360 | #97 52 361 | #98 23 362 | #98 52 363 | #99 0 xcdr 364 | #99 54 365 | #99 0 print_list 366 | #99 65 367 | #99 66 368 | #99 52 369 | #100 68 370 | #101 68 371 | #101 52 372 | #102 68 373 | #102 52 374 | #104 9 375 | #104 4 Nil 376 | #104 15 377 | #104 4 BookList 378 | #104 67 379 | #105 0 isNil 380 | #105 65 381 | #105 66 382 | #105 51 383 | #105 4 Bool 384 | #105 67 385 | #105 27 386 | #105 68 387 | #105 52 388 | #107 0 print_list 389 | #107 65 390 | #107 66 391 | #107 51 392 | #107 4 Object 393 | #107 67 394 | #107 27 395 | #107 68 396 | #107 52 397 | #108 68 398 | #108 52 399 | #111 9 400 | #111 4 Main 401 | #111 67 402 | #113 0 books 403 | #113 51 404 | #113 4 BookList 405 | #113 52 406 | #115 0 main 407 | #115 65 408 | #115 66 409 | #115 51 410 | #115 4 Object 411 | #115 67 412 | #116 65 413 | #116 17 414 | #116 0 a_book 415 | #116 51 416 | #116 4 Book 417 | #116 53 418 | #117 65 419 | #117 24 420 | #117 4 Book 421 | #117 66 422 | #117 54 423 | #117 0 initBook 424 | #117 65 425 | #117 2 "Compilers, Principles, Techniques, and Tools" 426 | #117 72 427 | #118 2 "Aho, Sethi, and Ullman" 428 | #118 66 429 | #119 14 430 | #120 65 431 | #120 17 432 | #120 0 an_article 433 | #120 51 434 | #120 4 Article 435 | #120 53 436 | #121 65 437 | #121 24 438 | #121 4 Article 439 | #121 66 440 | #121 54 441 | #121 0 initArticle 442 | #121 65 443 | #121 2 "The Top 100 CD_ROMs" 444 | #121 72 445 | #122 2 "Ulanoff" 446 | #122 72 447 | #123 2 "PC Magazine" 448 | #123 66 449 | #124 14 450 | #125 67 451 | #126 0 books 452 | #126 53 453 | #126 65 454 | #126 24 455 | #126 4 Nil 456 | #126 66 457 | #126 54 458 | #126 0 cons 459 | #126 65 460 | #126 0 a_book 461 | #126 66 462 | #126 54 463 | #126 0 cons 464 | #126 65 465 | #126 0 an_article 466 | #126 66 467 | #126 52 468 | #127 0 books 469 | #127 54 470 | #127 0 print_list 471 | #127 65 472 | #127 66 473 | #127 52 474 | #128 68 475 | #129 66 476 | #130 66 477 | #131 68 478 | #131 52 479 | #132 68 480 | #132 52 481 | -------------------------------------------------------------------------------- /CoolParser/CoolParser/result.txt: -------------------------------------------------------------------------------- 1 | #3 9 2 | #3 4 Book 3 | #3 15 4 | #3 4 IO 5 | #3 67 6 | #4 0 title 7 | #4 51 8 | #4 4 String 9 | #4 52 10 | #5 0 author 11 | #5 51 12 | #5 4 String 13 | #5 52 14 | #7 0 initBook 15 | #7 65 16 | #7 0 title_p 17 | #7 51 18 | #7 4 String 19 | #7 72 20 | #7 0 author_p 21 | #7 51 22 | #7 4 String 23 | #7 66 24 | #7 51 25 | #7 4 Book 26 | #7 67 27 | #8 67 28 | #9 0 title 29 | #9 53 30 | #9 0 title_p 31 | #9 52 32 | #10 0 author 33 | #10 53 34 | #10 0 author_p 35 | #10 52 36 | #11 29 37 | #11 52 38 | #12 68 39 | #13 68 40 | #13 52 41 | #15 0 print 42 | #15 65 43 | #15 66 44 | #15 51 45 | #15 4 Book 46 | #15 67 47 | #16 67 48 | #17 0 out_string 49 | #17 65 50 | #17 2 "title: " 51 | #17 66 52 | #17 54 53 | #17 0 out_string 54 | #17 65 55 | #17 0 title 56 | #17 66 57 | #17 54 58 | #17 0 out_string 59 | #17 65 60 | #17 2 "\n" 61 | #17 66 62 | #17 52 63 | #18 0 out_string 64 | #18 65 65 | #18 2 "author: " 66 | #18 66 67 | #18 54 68 | #18 0 out_string 69 | #18 65 70 | #18 0 author 71 | #18 66 72 | #18 54 73 | #18 0 out_string 74 | #18 65 75 | #18 2 "\n" 76 | #18 66 77 | #18 52 78 | #19 29 79 | #19 52 80 | #20 68 81 | #21 68 82 | #21 52 83 | #22 68 84 | #22 52 85 | #24 9 86 | #24 4 Article 87 | #24 15 88 | #24 4 Book 89 | #24 67 90 | #25 0 per_title 91 | #25 51 92 | #25 4 String 93 | #25 52 94 | #27 0 initArticle 95 | #27 65 96 | #27 0 title_p 97 | #27 51 98 | #27 4 String 99 | #27 72 100 | #27 0 author_p 101 | #27 51 102 | #27 4 String 103 | #27 72 104 | #28 0 per_title_p 105 | #28 51 106 | #28 4 String 107 | #28 66 108 | #28 51 109 | #28 4 Article 110 | #28 67 111 | #29 67 112 | #30 0 initBook 113 | #30 65 114 | #30 0 title_p 115 | #30 72 116 | #30 0 author_p 117 | #30 66 118 | #30 52 119 | #31 0 per_title 120 | #31 53 121 | #31 0 per_title_p 122 | #31 52 123 | #32 29 124 | #32 52 125 | #33 68 126 | #34 68 127 | #34 52 128 | #36 0 print 129 | #36 65 130 | #36 66 131 | #36 51 132 | #36 4 Book 133 | #36 67 134 | #37 67 135 | #38 29 136 | #38 55 137 | #38 4 Book 138 | #38 54 139 | #38 0 print 140 | #38 65 141 | #38 66 142 | #38 52 143 | #39 0 out_string 144 | #39 65 145 | #39 2 "periodical: " 146 | #39 66 147 | #39 54 148 | #39 0 out_string 149 | #39 65 150 | #39 0 per_title 151 | #39 66 152 | #39 54 153 | #39 0 out_string 154 | #39 65 155 | #39 2 "\n" 156 | #39 66 157 | #39 52 158 | #40 29 159 | #40 52 160 | #41 68 161 | #42 68 162 | #42 52 163 | #43 68 164 | #43 52 165 | #45 9 166 | #45 4 BookList 167 | #45 15 168 | #45 4 IO 169 | #45 67 170 | #50 0 isNil 171 | #50 65 172 | #50 66 173 | #50 51 174 | #50 4 Bool 175 | #50 67 176 | #50 67 177 | #50 0 abort 178 | #50 65 179 | #50 66 180 | #50 52 181 | #50 27 182 | #50 52 183 | #50 68 184 | #50 68 185 | #50 52 186 | #52 0 cons 187 | #52 65 188 | #52 0 hd 189 | #52 51 190 | #52 4 Book 191 | #52 66 192 | #52 51 193 | #52 4 Cons 194 | #52 67 195 | #53 65 196 | #53 17 197 | #53 0 new_cell 198 | #53 51 199 | #53 4 Cons 200 | #53 53 201 | #53 24 202 | #53 4 Cons 203 | #53 14 204 | #54 0 new_cell 205 | #54 54 206 | #54 0 init 207 | #54 65 208 | #54 0 hd 209 | #54 72 210 | #54 29 211 | #54 66 212 | #55 66 213 | #56 68 214 | #56 52 215 | #62 0 car 216 | #62 65 217 | #62 66 218 | #62 51 219 | #62 4 Book 220 | #62 67 221 | #62 67 222 | #62 0 abort 223 | #62 65 224 | #62 66 225 | #62 52 226 | #62 24 227 | #62 4 Book 228 | #62 52 229 | #62 68 230 | #62 68 231 | #62 52 232 | #68 0 cdr 233 | #68 65 234 | #68 66 235 | #68 51 236 | #68 4 BookList 237 | #68 67 238 | #68 67 239 | #68 0 abort 240 | #68 65 241 | #68 66 242 | #68 52 243 | #68 24 244 | #68 4 BookList 245 | #68 52 246 | #68 68 247 | #68 68 248 | #68 52 249 | #70 0 print_list 250 | #70 65 251 | #70 66 252 | #70 51 253 | #70 4 Object 254 | #70 67 255 | #70 0 abort 256 | #70 65 257 | #70 66 258 | #70 68 259 | #70 52 260 | #71 68 261 | #71 52 262 | #73 9 263 | #73 4 Cons 264 | #73 15 265 | #73 4 BookList 266 | #73 67 267 | #74 0 xcar 268 | #74 51 269 | #74 4 Book 270 | #74 52 271 | #75 0 xcdr 272 | #75 51 273 | #75 4 BookList 274 | #75 52 275 | #79 0 isNil 276 | #79 65 277 | #79 66 278 | #79 51 279 | #79 4 Bool 280 | #79 67 281 | #79 11 282 | #79 68 283 | #79 52 284 | #81 0 init 285 | #81 65 286 | #81 0 hd 287 | #81 51 288 | #81 4 Book 289 | #81 72 290 | #81 0 tl 291 | #81 51 292 | #81 4 BookList 293 | #81 66 294 | #81 51 295 | #81 4 Cons 296 | #81 67 297 | #82 67 298 | #83 0 xcar 299 | #83 53 300 | #83 0 hd 301 | #83 52 302 | #84 0 xcdr 303 | #84 53 304 | #84 0 tl 305 | #84 52 306 | #85 29 307 | #85 52 308 | #86 68 309 | #87 68 310 | #87 52 311 | #89 0 car 312 | #89 65 313 | #89 66 314 | #89 51 315 | #89 4 Book 316 | #89 67 317 | #89 0 xcar 318 | #89 68 319 | #89 52 320 | #91 0 cdr 321 | #91 65 322 | #91 66 323 | #91 51 324 | #91 4 BookList 325 | #91 67 326 | #91 0 xcdr 327 | #91 68 328 | #91 52 329 | #93 0 print_list 330 | #93 65 331 | #93 66 332 | #93 51 333 | #93 4 Object 334 | #93 67 335 | #94 67 336 | #95 22 337 | #95 0 xcar 338 | #95 54 339 | #95 0 print 340 | #95 65 341 | #95 66 342 | #95 25 343 | #96 0 dummy 344 | #96 51 345 | #96 4 Book 346 | #96 69 347 | #96 0 out_string 348 | #96 65 349 | #96 2 "- dynamic type was Book -\n" 350 | #96 66 351 | #96 52 352 | #97 0 dummy 353 | #97 51 354 | #97 4 Article 355 | #97 69 356 | #97 0 out_string 357 | #97 65 358 | #97 2 "- dynamic type was Article -\n" 359 | #97 66 360 | #97 52 361 | #98 23 362 | #98 52 363 | #99 0 xcdr 364 | #99 54 365 | #99 0 print_list 366 | #99 65 367 | #99 66 368 | #99 52 369 | #100 68 370 | #101 68 371 | #101 52 372 | #102 68 373 | #102 52 374 | #104 9 375 | #104 4 Nil 376 | #104 15 377 | #104 4 BookList 378 | #104 67 379 | #105 0 isNil 380 | #105 65 381 | #105 66 382 | #105 51 383 | #105 4 Bool 384 | #105 67 385 | #105 27 386 | #105 68 387 | #105 52 388 | #107 0 print_list 389 | #107 65 390 | #107 66 391 | #107 51 392 | #107 4 Object 393 | #107 67 394 | #107 27 395 | #107 68 396 | #107 52 397 | #108 68 398 | #108 52 399 | #111 9 400 | #111 4 Main 401 | #111 67 402 | #113 0 books 403 | #113 51 404 | #113 4 BookList 405 | #113 52 406 | #115 0 main 407 | #115 65 408 | #115 66 409 | #115 51 410 | #115 4 Object 411 | #115 67 412 | #116 65 413 | #116 17 414 | #116 0 a_book 415 | #116 51 416 | #116 4 Book 417 | #116 53 418 | #117 65 419 | #117 24 420 | #117 4 Book 421 | #117 66 422 | #117 54 423 | #117 0 initBook 424 | #117 65 425 | #117 2 "Compilers, Principles, Techniques, and Tools" 426 | #117 72 427 | #118 2 "Aho, Sethi, and Ullman" 428 | #118 66 429 | #119 14 430 | #120 65 431 | #120 17 432 | #120 0 an_article 433 | #120 51 434 | #120 4 Article 435 | #120 53 436 | #121 65 437 | #121 24 438 | #121 4 Article 439 | #121 66 440 | #121 54 441 | #121 0 initArticle 442 | #121 65 443 | #121 2 "The Top 100 CD_ROMs" 444 | #121 72 445 | #122 2 "Ulanoff" 446 | #122 72 447 | #123 2 "PC Magazine" 448 | #123 66 449 | #124 14 450 | #125 67 451 | #126 0 books 452 | #126 53 453 | #126 65 454 | #126 24 455 | #126 4 Nil 456 | #126 66 457 | #126 54 458 | #126 0 cons 459 | #126 65 460 | #126 0 a_book 461 | #126 66 462 | #126 54 463 | #126 0 cons 464 | #126 65 465 | #126 0 an_article 466 | #126 66 467 | #126 52 468 | #127 0 books 469 | #127 54 470 | #127 0 print_list 471 | #127 65 472 | #127 66 473 | #127 52 474 | #128 68 475 | #129 66 476 | #130 66 477 | #131 68 478 | #131 52 479 | #132 68 480 | #132 52 481 | -------------------------------------------------------------------------------- /Final_Project/Others/result.txt: -------------------------------------------------------------------------------- 1 | #3 9 2 | #3 4 Book 3 | #3 15 4 | #3 4 IO 5 | #3 67 6 | #4 0 title 7 | #4 51 8 | #4 4 String 9 | #4 52 10 | #5 0 author 11 | #5 51 12 | #5 4 String 13 | #5 52 14 | #7 0 initBook 15 | #7 65 16 | #7 0 title_p 17 | #7 51 18 | #7 4 String 19 | #7 72 20 | #7 0 author_p 21 | #7 51 22 | #7 4 String 23 | #7 66 24 | #7 51 25 | #7 4 Book 26 | #7 67 27 | #8 67 28 | #9 0 title 29 | #9 53 30 | #9 0 title_p 31 | #9 52 32 | #10 0 author 33 | #10 53 34 | #10 0 author_p 35 | #10 52 36 | #11 29 37 | #11 52 38 | #12 68 39 | #13 68 40 | #13 52 41 | #15 0 print 42 | #15 65 43 | #15 66 44 | #15 51 45 | #15 4 Book 46 | #15 67 47 | #16 67 48 | #17 0 out_string 49 | #17 65 50 | #17 2 "title: " 51 | #17 66 52 | #17 54 53 | #17 0 out_string 54 | #17 65 55 | #17 0 title 56 | #17 66 57 | #17 54 58 | #17 0 out_string 59 | #17 65 60 | #17 2 "\n" 61 | #17 66 62 | #17 52 63 | #18 0 out_string 64 | #18 65 65 | #18 2 "author: " 66 | #18 66 67 | #18 54 68 | #18 0 out_string 69 | #18 65 70 | #18 0 author 71 | #18 66 72 | #18 54 73 | #18 0 out_string 74 | #18 65 75 | #18 2 "\n" 76 | #18 66 77 | #18 52 78 | #19 29 79 | #19 52 80 | #20 68 81 | #21 68 82 | #21 52 83 | #22 68 84 | #22 52 85 | #24 9 86 | #24 4 Article 87 | #24 15 88 | #24 4 Book 89 | #24 67 90 | #25 0 per_title 91 | #25 51 92 | #25 4 String 93 | #25 52 94 | #27 0 initArticle 95 | #27 65 96 | #27 0 title_p 97 | #27 51 98 | #27 4 String 99 | #27 72 100 | #27 0 author_p 101 | #27 51 102 | #27 4 String 103 | #27 72 104 | #28 0 per_title_p 105 | #28 51 106 | #28 4 String 107 | #28 66 108 | #28 51 109 | #28 4 Article 110 | #28 67 111 | #29 67 112 | #30 0 initBook 113 | #30 65 114 | #30 0 title_p 115 | #30 72 116 | #30 0 author_p 117 | #30 66 118 | #30 52 119 | #31 0 per_title 120 | #31 53 121 | #31 0 per_title_p 122 | #31 52 123 | #32 29 124 | #32 52 125 | #33 68 126 | #34 68 127 | #34 52 128 | #36 0 print 129 | #36 65 130 | #36 66 131 | #36 51 132 | #36 4 Book 133 | #36 67 134 | #37 67 135 | #38 29 136 | #38 55 137 | #38 4 Book 138 | #38 54 139 | #38 0 print 140 | #38 65 141 | #38 66 142 | #38 52 143 | #39 0 out_string 144 | #39 65 145 | #39 2 "periodical: " 146 | #39 66 147 | #39 54 148 | #39 0 out_string 149 | #39 65 150 | #39 0 per_title 151 | #39 66 152 | #39 54 153 | #39 0 out_string 154 | #39 65 155 | #39 2 "\n" 156 | #39 66 157 | #39 52 158 | #40 29 159 | #40 52 160 | #41 68 161 | #42 68 162 | #42 52 163 | #43 68 164 | #43 52 165 | #45 9 166 | #45 4 BookList 167 | #45 15 168 | #45 4 IO 169 | #45 67 170 | #50 0 isNil 171 | #50 65 172 | #50 66 173 | #50 51 174 | #50 4 Bool 175 | #50 67 176 | #50 67 177 | #50 0 abort 178 | #50 65 179 | #50 66 180 | #50 52 181 | #50 27 182 | #50 52 183 | #50 68 184 | #50 68 185 | #50 52 186 | #52 0 cons 187 | #52 65 188 | #52 0 hd 189 | #52 51 190 | #52 4 Book 191 | #52 66 192 | #52 51 193 | #52 4 Cons 194 | #52 67 195 | #53 65 196 | #53 17 197 | #53 0 new_cell 198 | #53 51 199 | #53 4 Cons 200 | #53 53 201 | #53 24 202 | #53 4 Cons 203 | #53 14 204 | #54 0 new_cell 205 | #54 54 206 | #54 0 init 207 | #54 65 208 | #54 0 hd 209 | #54 72 210 | #54 29 211 | #54 66 212 | #55 66 213 | #56 68 214 | #56 52 215 | #62 0 car 216 | #62 65 217 | #62 66 218 | #62 51 219 | #62 4 Book 220 | #62 67 221 | #62 67 222 | #62 0 abort 223 | #62 65 224 | #62 66 225 | #62 52 226 | #62 24 227 | #62 4 Book 228 | #62 52 229 | #62 68 230 | #62 68 231 | #62 52 232 | #68 0 cdr 233 | #68 65 234 | #68 66 235 | #68 51 236 | #68 4 BookList 237 | #68 67 238 | #68 67 239 | #68 0 abort 240 | #68 65 241 | #68 66 242 | #68 52 243 | #68 24 244 | #68 4 BookList 245 | #68 52 246 | #68 68 247 | #68 68 248 | #68 52 249 | #70 0 print_list 250 | #70 65 251 | #70 66 252 | #70 51 253 | #70 4 Object 254 | #70 67 255 | #70 0 abort 256 | #70 65 257 | #70 66 258 | #70 68 259 | #70 52 260 | #71 68 261 | #71 52 262 | #73 9 263 | #73 4 Cons 264 | #73 15 265 | #73 4 BookList 266 | #73 67 267 | #74 0 xcar 268 | #74 51 269 | #74 4 Book 270 | #74 52 271 | #75 0 xcdr 272 | #75 51 273 | #75 4 BookList 274 | #75 52 275 | #79 0 isNil 276 | #79 65 277 | #79 66 278 | #79 51 279 | #79 4 Bool 280 | #79 67 281 | #79 11 282 | #79 68 283 | #79 52 284 | #81 0 init 285 | #81 65 286 | #81 0 hd 287 | #81 51 288 | #81 4 Book 289 | #81 72 290 | #81 0 tl 291 | #81 51 292 | #81 4 BookList 293 | #81 66 294 | #81 51 295 | #81 4 Cons 296 | #81 67 297 | #82 67 298 | #83 0 xcar 299 | #83 53 300 | #83 0 hd 301 | #83 52 302 | #84 0 xcdr 303 | #84 53 304 | #84 0 tl 305 | #84 52 306 | #85 29 307 | #85 52 308 | #86 68 309 | #87 68 310 | #87 52 311 | #89 0 car 312 | #89 65 313 | #89 66 314 | #89 51 315 | #89 4 Book 316 | #89 67 317 | #89 0 xcar 318 | #89 68 319 | #89 52 320 | #91 0 cdr 321 | #91 65 322 | #91 66 323 | #91 51 324 | #91 4 BookList 325 | #91 67 326 | #91 0 xcdr 327 | #91 68 328 | #91 52 329 | #93 0 print_list 330 | #93 65 331 | #93 66 332 | #93 51 333 | #93 4 Object 334 | #93 67 335 | #94 67 336 | #95 22 337 | #95 0 xcar 338 | #95 54 339 | #95 0 print 340 | #95 65 341 | #95 66 342 | #95 25 343 | #96 0 dummy 344 | #96 51 345 | #96 4 Book 346 | #96 69 347 | #96 0 out_string 348 | #96 65 349 | #96 2 "- dynamic type was Book -\n" 350 | #96 66 351 | #96 52 352 | #97 0 dummy 353 | #97 51 354 | #97 4 Article 355 | #97 69 356 | #97 0 out_string 357 | #97 65 358 | #97 2 "- dynamic type was Article -\n" 359 | #97 66 360 | #97 52 361 | #98 23 362 | #98 52 363 | #99 0 xcdr 364 | #99 54 365 | #99 0 print_list 366 | #99 65 367 | #99 66 368 | #99 52 369 | #100 68 370 | #101 68 371 | #101 52 372 | #102 68 373 | #102 52 374 | #104 9 375 | #104 4 Nil 376 | #104 15 377 | #104 4 BookList 378 | #104 67 379 | #105 0 isNil 380 | #105 65 381 | #105 66 382 | #105 51 383 | #105 4 Bool 384 | #105 67 385 | #105 27 386 | #105 68 387 | #105 52 388 | #107 0 print_list 389 | #107 65 390 | #107 66 391 | #107 51 392 | #107 4 Object 393 | #107 67 394 | #107 27 395 | #107 68 396 | #107 52 397 | #108 68 398 | #108 52 399 | #111 9 400 | #111 4 Main 401 | #111 67 402 | #113 0 books 403 | #113 51 404 | #113 4 BookList 405 | #113 52 406 | #115 0 main 407 | #115 65 408 | #115 66 409 | #115 51 410 | #115 4 Object 411 | #115 67 412 | #116 65 413 | #116 17 414 | #116 0 a_book 415 | #116 51 416 | #116 4 Book 417 | #116 53 418 | #117 65 419 | #117 24 420 | #117 4 Book 421 | #117 66 422 | #117 54 423 | #117 0 initBook 424 | #117 65 425 | #117 2 "Compilers, Principles, Techniques, and Tools" 426 | #117 72 427 | #118 2 "Aho, Sethi, and Ullman" 428 | #118 66 429 | #119 14 430 | #120 65 431 | #120 17 432 | #120 0 an_article 433 | #120 51 434 | #120 4 Article 435 | #120 53 436 | #121 65 437 | #121 24 438 | #121 4 Article 439 | #121 66 440 | #121 54 441 | #121 0 initArticle 442 | #121 65 443 | #121 2 "The Top 100 CD_ROMs" 444 | #121 72 445 | #122 2 "Ulanoff" 446 | #122 72 447 | #123 2 "PC Magazine" 448 | #123 66 449 | #124 14 450 | #125 67 451 | #126 0 books 452 | #126 53 453 | #126 65 454 | #126 24 455 | #126 4 Nil 456 | #126 66 457 | #126 54 458 | #126 0 cons 459 | #126 65 460 | #126 0 a_book 461 | #126 66 462 | #126 54 463 | #126 0 cons 464 | #126 65 465 | #126 0 an_article 466 | #126 66 467 | #126 52 468 | #127 0 books 469 | #127 54 470 | #127 0 print_list 471 | #127 65 472 | #127 66 473 | #127 52 474 | #128 68 475 | #129 66 476 | #130 66 477 | #131 68 478 | #131 52 479 | #132 68 480 | #132 52 481 | #133 10086 -------------------------------------------------------------------------------- /Final_Project/Others/lexer_result - 副本 (2).txt: -------------------------------------------------------------------------------- 1 | #3 9 2 | #3 4 Book 3 | #3 15 4 | #3 4 IO 5 | #3 67 6 | #4 0 title 7 | #4 51 8 | #4 4 String 9 | #4 52 10 | #5 0 author 11 | #5 51 12 | #5 4 String 13 | #5 52 14 | #7 0 initBook 15 | #7 65 16 | #7 0 title_p 17 | #7 51 18 | #7 4 String 19 | #7 72 20 | #7 0 author_p 21 | #7 51 22 | #7 4 String 23 | #7 66 24 | #7 51 25 | #7 4 Book 26 | #7 67 27 | #8 67 28 | #9 0 title 29 | #9 53 30 | #9 0 title_p 31 | #9 52 32 | #10 0 author 33 | #10 53 34 | #10 0 author_p 35 | #10 52 36 | #11 29 37 | #11 52 38 | #12 68 39 | #13 68 40 | #13 52 41 | #15 0 print 42 | #15 65 43 | #15 66 44 | #15 51 45 | #15 4 Book 46 | #15 67 47 | #16 67 48 | #17 0 out_string 49 | #17 65 50 | #17 2 "title: " 51 | #17 66 52 | #17 54 53 | #17 0 out_string 54 | #17 65 55 | #17 0 title 56 | #17 66 57 | #17 54 58 | #17 0 out_string 59 | #17 65 60 | #17 2 "\n" 61 | #17 66 62 | #17 52 63 | #18 0 out_string 64 | #18 65 65 | #18 2 "author: " 66 | #18 66 67 | #18 54 68 | #18 0 out_string 69 | #18 65 70 | #18 0 author 71 | #18 66 72 | #18 54 73 | #18 0 out_string 74 | #18 65 75 | #18 2 "\n" 76 | #18 66 77 | #18 52 78 | #19 29 79 | #19 52 80 | #20 68 81 | #21 68 82 | #21 52 83 | #22 68 84 | #22 52 85 | #24 9 86 | #24 4 Article 87 | #24 15 88 | #24 4 Book 89 | #24 67 90 | #25 0 per_title 91 | #25 51 92 | #25 4 String 93 | #25 52 94 | #27 0 initArticle 95 | #27 65 96 | #27 0 title_p 97 | #27 51 98 | #27 4 String 99 | #27 72 100 | #27 0 author_p 101 | #27 51 102 | #27 4 String 103 | #27 72 104 | #28 0 per_title_p 105 | #28 51 106 | #28 4 String 107 | #28 66 108 | #28 51 109 | #28 4 Article 110 | #28 67 111 | #29 67 112 | #30 0 initBook 113 | #30 65 114 | #30 0 title_p 115 | #30 72 116 | #30 0 author_p 117 | #30 66 118 | #30 52 119 | #31 0 per_title 120 | #31 53 121 | #31 0 per_title_p 122 | #31 52 123 | #32 29 124 | #32 52 125 | #33 68 126 | #34 68 127 | #34 52 128 | #36 0 print 129 | #36 65 130 | #36 66 131 | #36 51 132 | #36 4 Book 133 | #36 67 134 | #37 67 135 | #38 29 136 | #38 55 137 | #38 4 Book 138 | #38 54 139 | #38 0 print 140 | #38 65 141 | #38 66 142 | #38 52 143 | #39 0 out_string 144 | #39 65 145 | #39 2 "periodical: " 146 | #39 66 147 | #39 54 148 | #39 0 out_string 149 | #39 65 150 | #39 0 per_title 151 | #39 66 152 | #39 54 153 | #39 0 out_string 154 | #39 65 155 | #39 2 "\n" 156 | #39 66 157 | #39 52 158 | #40 29 159 | #40 52 160 | #41 68 161 | #42 68 162 | #42 52 163 | #43 68 164 | #43 52 165 | #45 9 166 | #45 4 BookList 167 | #45 15 168 | #45 4 IO 169 | #45 67 170 | #50 0 isNil 171 | #50 65 172 | #50 66 173 | #50 51 174 | #50 4 Bool 175 | #50 67 176 | #50 67 177 | #50 0 abort 178 | #50 65 179 | #50 66 180 | #50 52 181 | #50 27 182 | #50 52 183 | #50 68 184 | #50 68 185 | #50 52 186 | #52 0 cons 187 | #52 65 188 | #52 0 hd 189 | #52 51 190 | #52 4 Book 191 | #52 66 192 | #52 51 193 | #52 4 Cons 194 | #52 67 195 | #53 65 196 | #53 17 197 | #53 0 new_cell 198 | #53 51 199 | #53 4 Cons 200 | #53 53 201 | #53 24 202 | #53 4 Cons 203 | #53 14 204 | #54 0 new_cell 205 | #54 54 206 | #54 0 init 207 | #54 65 208 | #54 0 hd 209 | #54 72 210 | #54 29 211 | #54 66 212 | #55 66 213 | #56 68 214 | #56 52 215 | #62 0 car 216 | #62 65 217 | #62 66 218 | #62 51 219 | #62 4 Book 220 | #62 67 221 | #62 67 222 | #62 0 abort 223 | #62 65 224 | #62 66 225 | #62 52 226 | #62 24 227 | #62 4 Book 228 | #62 52 229 | #62 68 230 | #62 68 231 | #62 52 232 | #68 0 cdr 233 | #68 65 234 | #68 66 235 | #68 51 236 | #68 4 BookList 237 | #68 67 238 | #68 67 239 | #68 0 abort 240 | #68 65 241 | #68 66 242 | #68 52 243 | #68 24 244 | #68 4 BookList 245 | #68 52 246 | #68 68 247 | #68 68 248 | #68 52 249 | #70 0 print_list 250 | #70 65 251 | #70 66 252 | #70 51 253 | #70 4 Object 254 | #70 67 255 | #70 0 abort 256 | #70 65 257 | #70 66 258 | #70 68 259 | #70 52 260 | #71 68 261 | #71 52 262 | #73 9 263 | #73 4 Cons 264 | #73 15 265 | #73 4 BookList 266 | #73 67 267 | #74 0 xcar 268 | #74 51 269 | #74 4 Book 270 | #74 52 271 | #75 0 xcdr 272 | #75 51 273 | #75 4 BookList 274 | #75 52 275 | #79 0 isNil 276 | #79 65 277 | #79 66 278 | #79 51 279 | #79 4 Bool 280 | #79 67 281 | #79 11 282 | #79 68 283 | #79 52 284 | #81 0 init 285 | #81 65 286 | #81 0 hd 287 | #81 51 288 | #81 4 Book 289 | #81 72 290 | #81 0 tl 291 | #81 51 292 | #81 4 BookList 293 | #81 66 294 | #81 51 295 | #81 4 Cons 296 | #81 67 297 | #82 67 298 | #83 0 xcar 299 | #83 53 300 | #83 0 hd 301 | #83 52 302 | #84 0 xcdr 303 | #84 53 304 | #84 0 tl 305 | #84 52 306 | #85 29 307 | #85 52 308 | #86 68 309 | #87 68 310 | #87 52 311 | #89 0 car 312 | #89 65 313 | #89 66 314 | #89 51 315 | #89 4 Book 316 | #89 67 317 | #89 0 xcar 318 | #89 68 319 | #89 52 320 | #91 0 cdr 321 | #91 65 322 | #91 66 323 | #91 51 324 | #91 4 BookList 325 | #91 67 326 | #91 0 xcdr 327 | #91 68 328 | #91 52 329 | #93 0 print_list 330 | #93 65 331 | #93 66 332 | #93 51 333 | #93 4 Object 334 | #93 67 335 | #94 67 336 | #95 22 337 | #95 0 xcar 338 | #95 54 339 | #95 0 print 340 | #95 65 341 | #95 66 342 | #95 25 343 | #96 0 dummy 344 | #96 51 345 | #96 4 Book 346 | #96 69 347 | #96 0 out_string 348 | #96 65 349 | #96 2 "- dynamic type was Book -\n" 350 | #96 66 351 | #96 52 352 | #97 0 dummy 353 | #97 51 354 | #97 4 Article 355 | #97 69 356 | #97 0 out_string 357 | #97 65 358 | #97 2 "- dynamic type was Article -\n" 359 | #97 66 360 | #97 52 361 | #98 23 362 | #98 52 363 | #99 0 xcdr 364 | #99 54 365 | #99 0 print_list 366 | #99 65 367 | #99 66 368 | #99 52 369 | #100 68 370 | #101 68 371 | #101 52 372 | #102 68 373 | #102 52 374 | #104 9 375 | #104 4 Nil 376 | #104 15 377 | #104 4 BookList 378 | #104 67 379 | #105 0 isNil 380 | #105 65 381 | #105 66 382 | #105 51 383 | #105 4 Bool 384 | #105 67 385 | #105 27 386 | #105 68 387 | #105 52 388 | #107 0 print_list 389 | #107 65 390 | #107 66 391 | #107 51 392 | #107 4 Object 393 | #107 67 394 | #107 27 395 | #107 68 396 | #107 52 397 | #108 68 398 | #108 52 399 | #111 9 400 | #111 4 Main 401 | #111 67 402 | #113 0 books 403 | #113 51 404 | #113 4 BookList 405 | #113 52 406 | #115 0 main 407 | #115 65 408 | #115 66 409 | #115 51 410 | #115 4 Object 411 | #115 67 412 | #116 65 413 | #116 17 414 | #116 0 a_book 415 | #116 51 416 | #116 4 Book 417 | #116 53 418 | #117 65 419 | #117 24 420 | #117 4 Book 421 | #117 66 422 | #117 54 423 | #117 0 initBook 424 | #117 65 425 | #117 2 "Compilers, Principles, Techniques, and Tools" 426 | #117 72 427 | #118 2 "Aho, Sethi, and Ullman" 428 | #118 66 429 | #119 14 430 | #120 65 431 | #120 17 432 | #120 0 an_article 433 | #120 51 434 | #120 4 Article 435 | #120 53 436 | #121 65 437 | #121 24 438 | #121 4 Article 439 | #121 66 440 | #121 54 441 | #121 0 initArticle 442 | #121 65 443 | #121 2 "The Top 100 CD_ROMs" 444 | #121 72 445 | #122 2 "Ulanoff" 446 | #122 72 447 | #123 2 "PC Magazine" 448 | #123 66 449 | #124 14 450 | #125 67 451 | #126 0 books 452 | #126 53 453 | #126 65 454 | #126 24 455 | #126 4 Nil 456 | #126 66 457 | #126 54 458 | #126 0 cons 459 | #126 65 460 | #126 0 a_book 461 | #126 66 462 | #126 54 463 | #126 0 cons 464 | #126 65 465 | #126 0 an_article 466 | #126 66 467 | #126 52 468 | #127 0 books 469 | #127 54 470 | #127 0 print_list 471 | #127 65 472 | #127 66 473 | #127 52 474 | #128 68 475 | #129 66 476 | #130 66 477 | #131 68 478 | #131 52 479 | #132 68 480 | #132 52 481 | #133 10086 -------------------------------------------------------------------------------- /CoolLexer/CoolLexer.cpp: -------------------------------------------------------------------------------- 1 | // CoolLexer.cpp : 定义控制台应用程序的入口点。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #define Digital_Range Rfc('0'),Rfc('9') 10 | #define Up_char_Range Rfc('A'),Rfc('Z') 11 | #define Down_char_Range Rfc('a'),Rfc('z') 12 | #define All 0,99 13 | using namespace std; 14 | const int maxll = 512; 15 | const int maxm = 1e05; 16 | char cur[maxll]; 17 | int NUM = 0; 18 | bool st_comments; 19 | ofstream OUT; 20 | struct ele { 21 | ele *next[100]; 22 | int no;//记录状态 若为0则为非终止状态 为-2则为待判断是否是指定的关键词 23 | }pool[maxm]; 24 | int Rfc(char a)//对所读取的字符进行映射 25 | { 26 | if (a == ' ' || a == '\n' || a == '\0') return 0; 27 | return a - 31; 28 | } 29 | int tot = -1; 30 | struct AutoMachine { 31 | ele *root; 32 | char Buffer[260]; 33 | int ll_b = 0; 34 | AutoMachine()//初始化 35 | { 36 | 37 | root = &pool[++tot]; 38 | root->next[0] = root; 39 | memset(Buffer, 0, sizeof(Buffer)); 40 | } 41 | ele *newNode()//建立新的结点 42 | { 43 | ele *tem = &pool[++tot]; 44 | tem->next[0] = tem; 45 | return tem; 46 | } 47 | void default_link(ele *cur, int down, int up, ele *to) 48 | { 49 | for (int i = down; i <= up; i++) cur->next[i] = to; 50 | } 51 | void Build_up() 52 | { 53 | default_link(root, Digital_Range, root + 2);//建立标识符以及关键词的识别分支 54 | default_link(root, Down_char_Range, root + 1); 55 | default_link(root, Up_char_Range, root + 17); 56 | root->next[Rfc('_')] = root + 1; 57 | root->next[Rfc('\'')] = root + 8; 58 | root->next[Rfc('\"')] = root + 10; 59 | 60 | default_link(root + 1, Digital_Range, root + 1); 61 | default_link(root + 1, Up_char_Range, root + 1); 62 | default_link(root + 1, Down_char_Range, root + 1); 63 | (root + 1)->next[Rfc('_')] = root + 1; 64 | (root + 1)->no = -2; 65 | 66 | default_link(root + 2, Digital_Range, root + 2);//建立常数的判断分支 67 | (root + 2)->next[Rfc('.')] = root + 7; 68 | (root + 2)->no = 3; 69 | default_link(root + 7, Digital_Range, root + 6); 70 | (root + 7)->no = 3; 71 | default_link(root + 6, Digital_Range, root + 6); 72 | (root + 6)->no = 3; 73 | 74 | default_link(root + 8, All, root + 9);//转义字符的处理等待解决 建立普通字符的识别分支 75 | (root + 9)->next[Rfc('\'')] = root + 15; 76 | (root + 15)->no = 1; 77 | 78 | default_link(root + 10, All, root + 11);//ʶ±ð×Ö·û´´·ÖÖ§ 79 | default_link(root + 11, All, root + 11); 80 | (root + 10)->next[Rfc('\"')] = root + 16; 81 | (root + 11)->next[Rfc('\"')] = root + 16; 82 | (root + 16)->no = 2; 83 | 84 | default_link(root + 17, Digital_Range, root + 17); 85 | default_link(root + 17, Up_char_Range, root + 17); 86 | default_link(root + 17, Down_char_Range, root + 17); 87 | (root + 17)->no = 4; 88 | (root + 17)->next[Rfc('_')] = root + 17; 89 | 90 | tot += 20; 91 | } 92 | void Build(char *Word, int no)//对于给定的KT表与PT表 建立识别状态图 93 | { 94 | ele *tem = root; 95 | int ll = strlen(Word); 96 | for (int i = 0; i < ll; i++) 97 | { 98 | int x = Rfc(Word[i]); 99 | if (tem->next[x] == NULL) { 100 | tem->next[x] = newNode(); 101 | tem = &pool[tot]; 102 | } 103 | else tem = tem->next[x];; 104 | } 105 | tem->no = no; 106 | } 107 | int Find(char *Word)//-1 equal to fail 用于判断当前输入的字符串对应的是关键词或是iT标识符 108 | { 109 | ele *cur = root; 110 | int ll = strlen(Word); 111 | for (int i = 0; i < ll; i++) 112 | { 113 | if (cur->next[Rfc(Word[i])] == NULL) return 0; 114 | else cur = cur->next[Rfc(Word[i])]; 115 | } 116 | return cur->no; 117 | } 118 | int Working(char *Words, AutoMachine &Key)//工作的主函数 Words为输入的函数 Key为KT字符串识别所用的trie树 119 | { 120 | ele *cur = root; 121 | int ll_b = 0; 122 | int x = 0;; 123 | memset(Buffer, 0, sizeof(Buffer)); 124 | while (*Words != '\0' && (*Words == '\t' || *Words == ' ')) 125 | { 126 | Words++; 127 | x++; 128 | } 129 | if (*Words == '(' && *(Words + 1) == '*') 130 | { 131 | st_comments = true; 132 | x += 2; Words += 2; 133 | } 134 | while (st_comments == true && *Words != '\0') 135 | { 136 | if (*Words == '*' && *(Words + 1) == ')') 137 | { 138 | st_comments = false; 139 | Words += 2; 140 | x += 2; 141 | return x; 142 | } 143 | else 144 | { 145 | Words++; 146 | x++; 147 | } 148 | } 149 | if (strlen(Words) == 0 || st_comments) return x; 150 | if (*Words == '-' && *(Words + 1) == '-') 151 | { 152 | while (*Words != '\0') 153 | { 154 | Words++; 155 | x++; 156 | } 157 | return x; 158 | } 159 | while (1) 160 | { 161 | if (*Words== '\0' || cur->next[Rfc(*Words)] == NULL) { 162 | if (cur == root) { 163 | OUT << "#" << NUM << " "; 164 | OUT << "-1"; 165 | OUT.close(); 166 | exit(-1); 167 | } 168 | else { 169 | if (cur->no > 0) 170 | { 171 | OUT << "#" << NUM << " " << cur->no; 172 | Buffer[ll_b] = '\0'; 173 | if (cur->no <= 4) 174 | OUT << " " << Buffer; 175 | OUT << endl; 176 | } 177 | if (cur->no == -2) { 178 | while (Buffer[ll_b - 1] == '\t' || Buffer[ll_b - 1] == '\n' || Buffer[ll_b - 1] == ' ') ll_b--; 179 | Buffer[ll_b] = '\0'; 180 | int tmp_no = Key.Find(Buffer); 181 | OUT << "#" << NUM << " " << tmp_no; 182 | if (tmp_no == 0) 183 | OUT << " " << Buffer; 184 | OUT << endl; 185 | } 186 | if (cur->no == 0) { 187 | OUT << "#" << NUM << " "; 188 | OUT << "-1"; 189 | OUT.close(); 190 | exit(-2); 191 | } 192 | break; 193 | } 194 | } 195 | // cout<next[Rfc(*Words)]; 197 | // cout< 34 | ## 1. Know Before you start 35 | 36 | ### About Cool Language 37 | Cool the Classroom Object Oriented Language, is a small programming language for teaching the basics of compiler construction to undergraduate computer science majors. 38 | 39 | Cool is designed to be implemented by individuals or teams of two using C++ [Str91] in a Unix environment in a single semester. 40 | At Berkeley, 80% - 90% of the student teams complete the pro ject each semester. 41 | The project has been designed to be relatively easy to modify so shorter or longer pro jects are possible. 42 | 43 | In this paper, Cool refers both to the language and to the complete compiler project(of which the language is one part). 44 | 45 | ### About this project 46 | 47 | Compiler project usually are divided into 4 assignments: 48 | 49 | 1. Lexical analysis 50 | 2. Parsing 51 | 3. Semanic Analysis 52 | 4. Code Generation 53 | 54 | 55 | ## 2. Tools And Environment 56 | 57 | * FLex/JLex 58 | * Yacc 59 | 60 | 61 | ## Resources 62 | 63 | * [Cool Reference Manual](http://web.stanford.edu/class/cs143/materials/cool-manual.pdf) 64 | * [Tour of the Cool Support Code](http://web.stanford.edu/class/cs143/materials/cool-tour.pdf) 65 | * [Flex Manual](http://flex.sourceforge.net/manual/) 66 | * [JLex Manual](https://www.cs.princeton.edu/~appel/modern/java/JLex/current/manual.html) 67 | * [Bison Manual](http://www.gnu.org/software/bison/manual/html_node/index.html) 68 | * [CUP Manual](http://www2.cs.tum.edu/projects/cup/docs.php) 69 | * [CUP Javadoc](http://web.stanford.edu/class/cs143/javadoc/java_cup/index.html) 70 | * [Cool AST Javadoc](http://web.stanford.edu/class/cs143/javadoc/cool_ast/index.html) 71 | * [Cool Runtime](http://web.stanford.edu/class/cs143/materials/cool-runtime.pdf) 72 | * [SPIM Manual](http://web.stanford.edu/class/cs143/materials/SPIM_Manual.pdf) 73 | 74 | 75 | ### Download Preconfigured VM 76 | 77 | In order to use tools need for COOL. A Linux Environment is highly suggested. 78 | Due to the complexity of getting all the needed tools installed correctly, we provide a pre-configured Linux 79 | system via VirtualBox VM. 80 | 81 | [**Click here to downLoad Pre-configured VM.**](https://s3-us-west-1.amazonaws.com/prod-edx/Compilers/VM/compilers-vm.zip) 82 | 83 | [**Click here to downLoad VirtualBox.**](https://www.virtualbox.org/wiki/Downloads) 84 | 85 | VirtualBox allows you to install the VM on your own computer. 86 | 87 | 88 | ### Environment Test 89 | 90 | Once the VM is set up, you can compile the example programs. 91 | Once the assignments become available, you will be able to work on these inside the VM as well. 92 | 93 | To play around with the example cool programs, make a directory and copy over one or more examples from the /usr/class/cs143/examples directory. 94 | 95 | These examples are the same as the ones posted on the website. 96 | The coolc command will run the reference compiler to generate the assembly output (.s) file, which you can run using the spim simulator. 97 | 98 | For example, to compile and run "hello_world.cl", run in a terminal (where $ represents the prompt): 99 | 100 | $ mkdir examples 101 | $ cd examples 102 | $ cp /usr/class/cs143/examples/hello_world.cl . 103 | $ coolc hello_world.cl 104 | $ spim hello_world.s 105 | SPIM Version 6.5 of January 4, 2003 106 | Copyright 1990-2003 by James R. Larus (larus@cs.wisc.edu). 107 | All Rights Reserved. 108 | See the file README for a full copyright notice. 109 | Loaded: /usr/class/cs143/cool/lib/trap.handler 110 | Hello, World. 111 | COOL program successfully executed 112 | Stats -- #instructions : 152 113 | #reads : 27 #writes 22 #branches 28 #other 75 114 | 115 | 116 | ## 3. Appendix 117 | 118 | 119 | ### VirtualBox VM setup 120 | 121 | If you have not used a VM before, the idea is that you will be running an entire operating system inside a program (VirtualBox) that looks to the virtual guest operating system like real hardware. We provide a downloadable image of the guest OS with everything installed, so that you only need to do minimal setup to get started. 122 | 123 | Note that since a VM contains a whole second operating system, the system requirements are high. **The VM will take a bit over 512MB of ram (so you will probably want to have 2GB of total ram to keep Windows or Mac OS X running smoothly), plus a bit over 2GB of hard disk space.** 124 | 125 | 126 | **Getting VirtualBox** 127 | 128 | * First, download Oracle's VirtualBox, either from the VirtualBox website at [https://www.virtualbox.org/wiki/Downloads](https://www.virtualbox.org/wiki/Downloads), or from Oracle's download page at [http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html](http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html). Choose the version for the operating system you are running on your computer. 129 | * Once the download completes, run the installer to install VirtualBox. You will need administrator access on your computer to do so. 130 | 131 | 132 | **Getting our VM image** 133 | 134 | * Download our linux virtual machine image [here](https://s3-us-west-1.amazonaws.com/prod-edx/Compilers/VM/compilers-vm.zip), or if you have a BitTorrent client installed, you can use the torrent [here](http://spark-university.s3.amazonaws.com/stanford-compilers/vm/compilers-vm.zip?torrent). Note that this download is approximately 750MB. 135 | * Unzip the file into a convenient directory. The unzipped files are about 2GB, so make sure you have enough disk space available. If you are a Windows XP user and have trouble opening the zip file, try WinZip (shareware) or 7-Zip (free, open source) instead of the built-in zip support in Windows. 136 | * Once you have unzipped the VM, double-click on the file "Compilers.vbox". This should open the VM in VirtualBox. 137 | 138 | 139 | **Using the VM** 140 | 141 | * **The provided account is "compilers" and the password is "cool"**. 142 | * To start the VM, click the green "Start" button. This should make the VM boot. 143 | * To shut down the VM, click on the round "Bodhi" button at the bottom left and click System. Then choose Power Off. 144 | * We have installed what you need to do the assignments, plus a few other programs, such as vim and emacs. If you want to install other packages, you can use the Aptitude graphical package manager (under the Bodhi menu->Applications->Preferences) or the apt-get command line tool. If you are not familiar with these, there are many tutorials online that you can find through a quick Google search. 145 | * To get a terminal, click on the terminal icon at the bottom of the screen. This should get you to the point where you can start the assignments. 146 | 147 | This VM is based on Bodhi Linux, which is itself based on the popular linux distribution Ubuntu. We used Bodhi Linux in order to keep the download size more manageable, since a full Ubuntu install is quite large. However, since it is based on Ubuntu, most Ubuntu software packages can be installed on Bodhi Linux as well. 148 | 149 | 150 | ## Installing Directly on Linux 151 | 152 | **NOTE: We highly recommend using the VirtualBox VM.** 153 | 154 | However, there was enough demand that we are providing these instructions for people who want to run directly on their own installation of Linux. These instructions were tested with Ubuntu 11.10, but should work on similar (Debian-based) systems, and can be adapted for other distros. 155 | 156 | Steps: 157 | 158 | * Install packages (If you only intend to use the C++ version, you don't need the jdk). For Ubuntu: 159 | 160 | sudo apt-get install flex bison build-essential csh openjdk-6-jdk libxaw7-dev 161 | 162 | * Make the /usr/class directory: 163 | 164 | sudo mkdir /usr/class 165 | 166 | * Make the directory owned by you: 167 | 168 | sudo chown $USER /usr/class 169 | 170 | * Go to /usr/class and download the tarball: 171 | 172 | cd /usr/class 173 | 174 | wget http://spark-university.s3.amazonaws.com/stanford-compilers/vm/student-dist.tar.gz 175 | 176 | * Untar: 177 | 178 | tar -xf student-dist.tar.gz 179 | 180 | If you want things exactly like the VM: 181 | 182 | * Add a symlink to your home directory: 183 | 184 | ln -s /usr/class/cs143/cool ~/cool 185 | 186 | * Add the bin directory to your $PATH environment variable. If you are using bash, add to your .profile (or .bash_profile, etc. depending on your configuration; note that in Ubuntu have to log out and back in for this to take effect): 187 | 188 | PATH=/usr/class/cs143/cool/bin:$PATH 189 | -------------------------------------------------------------------------------- /CoolParser/CoolParser/SubProgram.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Specialized; 4 | using System.Diagnostics; 5 | using System.IO; 6 | using System.Reflection.Emit; 7 | using System.Text; 8 | 9 | namespace CoolParser 10 | { 11 | class SubProgram 12 | { 13 | public enum strToToken 14 | { 15 | e_typeCname = 4, 16 | e_class = 9, e_else, e_false, e_fi, e_if, e_in, e_inherits, e_isvoid, e_let, 17 | e_loop, e_pool, e_then, e_while, e_case, e_easc, e_new, e_of, e_not, e_true, e_main 18 | , e_self, e_SELF_TYPE, e_colon = 51, e_semicolon, e_la, e_dot, e_at, e_plus, e_minus, e_time, e_div 19 | , e_tilde, e_lessthan, e_LE, e_EEqual, e_equal, e_lb, e_rb, e_llb, e_lrb, 20 | e_lbstar, e_rbstar, e_bb, e_comma 21 | 22 | 23 | } 24 | 25 | public static int value; 26 | 27 | #region DictionAry Definition 28 | private readonly Dictionary _string2Token = new Dictionary 29 | { 30 | {"ID", 0}, 31 | {"Char", 1}, 32 | {"String", 2}, 33 | {"Integer", 3}, 34 | {"Type", 4}, 35 | {"class", 9}, 36 | {"else", 10}, 37 | {"false", 11}, 38 | {"fi", 12}, 39 | {"if", 13}, 40 | {"in", 14}, 41 | {"inherits", 15}, 42 | {"isvoid", 16}, 43 | {"let", 17}, 44 | {"loop", 18}, 45 | {"pool", 19}, 46 | {"then", 20}, 47 | {"while", 21}, 48 | {"case", 22 }, 49 | {"esac", 23 }, 50 | {"new", 24 }, 51 | {"of", 25 }, 52 | {"not", 26 }, 53 | {"true", 27 }, 54 | {"Main", 28 }, 55 | {"self", 29 }, 56 | {"SELF_TYPE", 30 }, 57 | {":", 51}, 58 | {";", 52}, 59 | {"<-",53}, 60 | {".", 54}, 61 | {"@", 55}, 62 | {"+", 56}, 63 | {"-", 57}, 64 | {"*", 58}, 65 | {"/", 59}, 66 | {"~", 60}, 67 | {"<", 61}, 68 | {"<=",62}, 69 | {"==",63}, 70 | {"=", 64}, 71 | {"(", 65}, 72 | {")", 66}, 73 | {"{", 67}, 74 | {"}", 68}, 75 | {"=>",69}, 76 | {",", 72}, 77 | {"ERR", -3}, 78 | 79 | }; 80 | #endregion 81 | //class Node 82 | //{ 83 | // public Node LeftChild { get; private set; } 84 | // public Node RightChild { get; private set; } 85 | // public char Label { get; private set; } 86 | 87 | // public Node(char label, Node left, Node right) 88 | // { 89 | // Label = label; 90 | // LeftChild = left; 91 | // RightChild = right; 92 | // } 93 | //} 94 | 95 | public void ProP() 96 | { 97 | 98 | ProC(); 99 | 100 | Console.WriteLine("Completed!"); 101 | 102 | 103 | 104 | 105 | var fs = new FileStream("out.txt", FileMode.Create); 106 | var sw = new StreamWriter(fs); 107 | foreach (var e in quadList) 108 | { 109 | Console.WriteLine(quadList.IndexOf(e)+":"+e.ToString()); 110 | sw.WriteLine(quadList.IndexOf(e)+":"+e.ToString()); 111 | } 112 | sw.Flush(); 113 | sw.Close(); 114 | 115 | } 116 | 117 | public int xLine; 118 | public int ReadPeek() 119 | { 120 | try 121 | { 122 | xLine = Program.TokenList.Peek().LineNum; 123 | value = Program.TokenList.Peek().tokens; 124 | 125 | return Program.TokenList.Peek().tokens; 126 | 127 | } 128 | catch (InvalidOperationException e) 129 | { 130 | return -3; 131 | } 132 | } 133 | public int ReadDeque() 134 | { 135 | Console.WriteLine("MATCHED TOKEN:"+ Program.TokenList.Peek().tokens+","+ Program.TokenList.Peek().GetValue()); 136 | return Program.TokenList.Dequeue().tokens; 137 | } 138 | public string ReadValueDeque() 139 | { 140 | Console.WriteLine("MATCHED TOKEN:" + Program.TokenList.Peek().tokens + "," + Program.TokenList.Peek().GetValue()); 141 | return Program.TokenList.Dequeue().GetValue(); 142 | } 143 | 144 | public int getTValue(string name) 145 | { 146 | int temp; 147 | _string2Token.TryGetValue(name, out temp); 148 | return temp; 149 | } 150 | public bool checkTerminalN(string terminal)//Only Check, no pop 151 | { 152 | 153 | 154 | 155 | if (ReadPeek() == getTValue(terminal)) 156 | { 157 | 158 | //switch (terminal) 159 | //{ 160 | // case "ID": 161 | // case "Integer": 162 | // case "string": 163 | // { 164 | // Program.SemanticStack.Push(Program.TokenList.Peek().GetValue()); 165 | // break; 166 | // } 167 | 168 | // case "true": 169 | // { 170 | // Program.SemanticStack.Push("true"); 171 | // break; 172 | 173 | // } 174 | // case "false": 175 | // { 176 | // Program.SemanticStack.Push("false"); 177 | // break; 178 | 179 | // } 180 | 181 | // default: 182 | // break; 183 | //} 184 | return true; 185 | } 186 | else 187 | { 188 | 189 | return false; 190 | } 191 | } 192 | public bool checkTerminal(string terminal) 193 | { 194 | 195 | if (ReadPeek() == getTValue(terminal)) 196 | { 197 | // Debug.WriteLine("MATCHED: "+terminal); 198 | 199 | 200 | 201 | ReadDeque(); 202 | 203 | return true; 204 | } 205 | else 206 | { 207 | 208 | return false; 209 | } 210 | } 211 | public bool checkTerminalE(string terminal) 212 | { 213 | if (ReadPeek() == getTValue(terminal)) 214 | { 215 | // Debug.WriteLine("MATCHED: " + terminal); 216 | 217 | ReadDeque(); 218 | return true; 219 | } 220 | else 221 | { 222 | if (ReadPeek() == -3) 223 | { 224 | throw new ParserException(string.Format("Error at Line {0}, Token {2} : Supposed Terminal {1}", 225 | xLine, terminal, value)); 226 | } 227 | 228 | else 229 | { 230 | throw new ParserException(string.Format("Error at Line {0}, Token {2} : Supposed Terminal {1}", 231 | xLine, terminal, Program.TokenList.Peek().GetValue())); 232 | } 233 | 234 | 235 | } 236 | 237 | 238 | } 239 | 240 | public class ParserException : Exception 241 | { 242 | public ParserException(string message) : base(message) 243 | { 244 | } 245 | } 246 | public void ProC() 247 | { 248 | Console.WriteLine("C"); 249 | checkTerminalE("class"); 250 | 251 | ProT(); 252 | ProIN(); 253 | checkTerminalE("{"); 254 | ProF(); 255 | checkTerminalE("}"); 256 | checkTerminalE(";"); 257 | ProCS(); 258 | 259 | 260 | 261 | } 262 | 263 | // current state 264 | // next state 265 | // final state 266 | //error 267 | 268 | 269 | public void ProCS() 270 | { 271 | Console.WriteLine("CS"); 272 | if (Program.TokenList.Count > 0) 273 | { 274 | if (ReadPeek() == getTValue("class")) 275 | { 276 | ProC(); 277 | } 278 | else 279 | { 280 | Console.WriteLine("ERROR"); 281 | throw new ParserException(string.Format("Error at Line {0}", Program.TokenList.Peek().LineNum)); 282 | } 283 | } 284 | else 285 | { 286 | Debug.WriteLine("$"); 287 | 288 | return; 289 | } 290 | 291 | 292 | 293 | 294 | } 295 | public string ProT()//T -> (类型名,以大写字母开头的字符串) 296 | 297 | { 298 | Console.WriteLine("T"); 299 | if (ReadPeek() == getTValue("Type")) 300 | if (Program.TokenList.Peek().GetValue() != "") 301 | { 302 | if (char.IsUpper(Program.TokenList.Peek().GetValue(), 0)) 303 | { 304 | var name=Program.TokenList.Peek().GetValue(); 305 | //Debug.WriteLine(Program.TokenList.Peek().GetValue()); 306 | ReadDeque(); 307 | return name; 308 | } 309 | else 310 | { 311 | throw new ParserException(string.Format("Error at Line {0}: Not Uppercase in Type Name", Program.TokenList.Peek().LineNum)); 312 | } 313 | } 314 | 315 | else 316 | throw new MissingFieldException(string.Format("Possible Error at Line {0}: Should be a T?", Program.TokenList.Peek().LineNum)); 317 | else 318 | { 319 | throw new ParserException(string.Format("Error at Line {0}: Supposed Type Name", Program.TokenList.Peek().LineNum)); 320 | } 321 | 322 | } 323 | 324 | 325 | 326 | public void ProIN() 327 | { 328 | Console.WriteLine("IN"); 329 | if (checkTerminal("inherits")) 330 | { 331 | 332 | 333 | ProT(); 334 | 335 | } 336 | else 337 | { 338 | Debug.WriteLine("$"); 339 | 340 | return; 341 | } 342 | } 343 | 344 | public string fsid; 345 | public void ProF() 346 | { 347 | Console.WriteLine("F"); 348 | fsid=ProID(); 349 | ProFS(); 350 | 351 | } 352 | public void ProFS() 353 | { 354 | Console.WriteLine("FS"); 355 | if (checkTerminal("(")) 356 | { 357 | Generate("define_method", "__", "__", fsid); 358 | ProFM(); 359 | checkTerminalE(")"); 360 | checkTerminalE(":"); 361 | ProT(); 362 | checkTerminal("{"); 363 | ProE(); 364 | checkTerminal("}"); 365 | checkTerminal(";"); 366 | Generate("end_define", "__", "__", "__"); 367 | Program.SemanticStack.Clear(); 368 | ProFP(); 369 | } 370 | else if (checkTerminal(":")) 371 | { 372 | ProT(); 373 | ProZ(); 374 | checkTerminal(";"); 375 | ProFP(); 376 | } 377 | else 378 | { 379 | throw new ParserException(string.Format("Error at Line {0}:", Program.TokenList.Peek().LineNum)); 380 | } 381 | 382 | } 383 | 384 | public void ProFP()//ERRIR 385 | { 386 | Console.WriteLine("FP"); 387 | try 388 | { 389 | ProF(); 390 | } 391 | catch(MissingFieldException) 392 | { 393 | Debug.WriteLine("$"); 394 | 395 | return; 396 | } 397 | 398 | } 399 | public void ProZ() 400 | { 401 | Console.WriteLine("Z"); 402 | if (checkTerminal("<-")) 403 | { 404 | ProE(); 405 | } 406 | 407 | else 408 | { 409 | Debug.WriteLine("$"); 410 | 411 | return; 412 | } 413 | } 414 | public void ProLEZ() 415 | { 416 | Console.WriteLine("Z"); 417 | if (checkTerminal("<-")) 418 | { 419 | ProE(); 420 | var y = Program.SemanticStack.Pop(); 421 | var x = Program.SemanticStack.Pop(); 422 | Generate("<-", y, "__", x); 423 | } 424 | 425 | else 426 | { 427 | Debug.WriteLine("$"); 428 | 429 | return; 430 | } 431 | } 432 | public void ProFMS() 433 | { 434 | 435 | Console.WriteLine("FMS"); 436 | if (checkTerminalN(")")) 437 | { 438 | return; 439 | } 440 | else 441 | { 442 | try 443 | { 444 | Debug.WriteLine("Checking if FM FMS will work"); 445 | checkTerminalE(","); 446 | ProFM(); 447 | 448 | } 449 | catch (MissingFieldException) 450 | { 451 | Debug.WriteLine("Not Exception... Change to Null"); 452 | Debug.WriteLine("$"); 453 | 454 | return; 455 | 456 | } 457 | } 458 | 459 | } 460 | public void ProFM() 461 | { 462 | Console.WriteLine("FM"); 463 | 464 | if (checkTerminalN(")")) 465 | { 466 | return; 467 | } 468 | else 469 | { 470 | ProID(); 471 | checkTerminalE(":"); 472 | ProT(); 473 | ProFMS(); 474 | } 475 | } 476 | public string ProID() 477 | { 478 | Console.WriteLine("ID"); 479 | 480 | if (checkTerminalN("ID")) 481 | { 482 | return ReadValueDeque(); 483 | } 484 | else 485 | throw new MissingFieldException( 486 | string.Format("Possible Error at Line {0}: Should be a ID?", Program.TokenList.Peek().LineNum)); 487 | 488 | //var x = Program.TokenList.Peek().GetValue().ToCharArray(); 489 | //if (char.IsLower(Program.TokenList.Peek().GetValue(), 0)) 490 | //{ 491 | // Debug.WriteLine(Program.TokenList.Peek().GetValue()); 492 | // ReadDeque(); 493 | //} 494 | //else 495 | //{ 496 | // throw new ParserException(string.Format("Error at Line {0}: Not Lowercase in Identifier", 497 | // Program.TokenList.Peek().LineNum)); 498 | //} 499 | 500 | 501 | } 502 | public int ProE() 503 | { 504 | Program.Token[] s = Program.TokenList.ToArray(); 505 | Console.WriteLine("E"); 506 | if (checkTerminalN("ID")) 507 | if (s[1].tokens == getTValue("<-")) 508 | { 509 | var id= ProID(); 510 | 511 | checkTerminalE("<-"); 512 | ProE(); 513 | var x = Program.SemanticStack.Pop(); 514 | Generate("<-", x, "__", id); 515 | Program.SemanticStack.Push(id); 516 | 517 | return 1; 518 | } 519 | else 520 | { 521 | 522 | ProG(); 523 | 524 | 525 | return 2; 526 | } 527 | 528 | else 529 | { 530 | if (checkTerminalN(")")) 531 | { 532 | return 0; 533 | } 534 | else 535 | { 536 | ProG(); 537 | return 3; 538 | } 539 | 540 | } 541 | } 542 | public void ProG() 543 | { 544 | var temp = ReadPeek(); 545 | Console.WriteLine("G"); 546 | if (checkTerminal("not")) 547 | { 548 | ProG(); 549 | var x = Program.SemanticStack.Pop(); 550 | 551 | var z = getNewVari(); 552 | Generate("not", x, "__", z); 553 | Program.SemanticStack.Push(z); 554 | } 555 | else 556 | { 557 | ProH(); 558 | } 559 | 560 | 561 | } 562 | public void ProH() 563 | { 564 | Console.WriteLine("H"); 565 | ProI(); 566 | ProHS(); 567 | } 568 | 569 | public void ProHS() 570 | { 571 | Console.WriteLine("HS"); 572 | if (checkTerminal("<=")) 573 | { 574 | ProI(); 575 | var x = Program.SemanticStack.Pop(); 576 | var y = Program.SemanticStack.Pop(); 577 | var z = getNewVari(); 578 | Generate("<=", x, y, z); 579 | Program.SemanticStack.Push(z); 580 | ProHS(); 581 | } 582 | else if (checkTerminal("<")) 583 | { 584 | ProI(); 585 | var x = Program.SemanticStack.Pop(); 586 | var y = Program.SemanticStack.Pop(); 587 | var z = getNewVari(); 588 | Generate("<", x, y, z); 589 | Program.SemanticStack.Push(z); 590 | ProHS(); 591 | } 592 | else if (checkTerminal("=")) 593 | { 594 | ProI(); 595 | var x = Program.SemanticStack.Pop(); 596 | var y = Program.SemanticStack.Pop(); 597 | var z = getNewVari(); 598 | Generate("=", x, y, z); 599 | Program.SemanticStack.Push(z); 600 | ProHS(); 601 | } 602 | else 603 | { 604 | Debug.WriteLine("$"); 605 | 606 | return; 607 | } 608 | } 609 | 610 | public void ProI() 611 | { 612 | Console.WriteLine("I"); 613 | ProJ(); 614 | ProIS(); 615 | } 616 | public void ProIS() 617 | { 618 | Console.WriteLine("IS"); 619 | if (checkTerminal("-")) 620 | { 621 | ProJ(); 622 | var x = Program.SemanticStack.Pop(); 623 | var y = Program.SemanticStack.Pop(); 624 | var z = getNewVari(); 625 | Generate("-", x, y, z); 626 | Program.SemanticStack.Push(z); 627 | ProIS(); 628 | } 629 | else 630 | if (checkTerminal("+")) 631 | { 632 | ProJ(); 633 | var x = Program.SemanticStack.Pop(); 634 | var y = Program.SemanticStack.Pop(); 635 | var z = getNewVari(); 636 | Generate("+", x, y, z); 637 | Program.SemanticStack.Push(z); 638 | ProIS(); 639 | } 640 | else 641 | { 642 | Debug.WriteLine("$"); 643 | 644 | return; 645 | } 646 | } 647 | public void ProJ() 648 | { 649 | Console.WriteLine("J"); 650 | ProK(); 651 | ProJS(); 652 | } 653 | public void ProJS() 654 | { 655 | Console.WriteLine("JS"); 656 | if (checkTerminal("*")) 657 | { 658 | ProK(); 659 | var x = Program.SemanticStack.Pop(); 660 | var y= Program.SemanticStack.Pop(); 661 | var z = getNewVari(); 662 | Generate("*", x, y, z); 663 | Program.SemanticStack.Push(z); 664 | ProJS(); 665 | } 666 | else if (checkTerminal("/")) 667 | { 668 | ProK(); 669 | var x = Program.SemanticStack.Pop(); 670 | var y = Program.SemanticStack.Pop(); 671 | var z = getNewVari(); 672 | Generate("/", x, y, z); 673 | Program.SemanticStack.Push(z); 674 | ProJS(); 675 | } 676 | else 677 | { 678 | Debug.WriteLine("$"); 679 | 680 | return; 681 | } 682 | } 683 | public void ProK() 684 | { 685 | Console.WriteLine("K"); 686 | if (checkTerminal("isvoid")) 687 | { 688 | 689 | ProK(); 690 | var x = Program.SemanticStack.Pop(); 691 | var z = getNewVari(); 692 | Generate("isvoid",x,"__",z); 693 | Program.SemanticStack.Push(z); 694 | //Program.SemanticStack.Pop(); 695 | //Program.SemanticStack.Push(); 696 | } 697 | else 698 | { 699 | ProL(); 700 | } 701 | 702 | } 703 | public void ProL() 704 | { 705 | Console.WriteLine("L"); 706 | if (checkTerminal("~")) 707 | { 708 | ProL(); 709 | var x = Program.SemanticStack.Pop(); 710 | var z=getNewVari(); 711 | Generate("~",x,"__",z); 712 | Program.SemanticStack.Push(z); 713 | } 714 | else 715 | { 716 | ProM(); 717 | } 718 | 719 | } 720 | public void ProM() 721 | { 722 | Console.WriteLine("M"); 723 | ProN(); 724 | ProMS(); 725 | } 726 | public void ProMS() 727 | { 728 | Console.WriteLine("MS"); 729 | if (checkTerminal("@")) 730 | { 731 | ProT(); 732 | checkTerminalE("."); 733 | var tempID= ProID(); 734 | checkTerminal("("); 735 | var t = ProE(); 736 | string SEM1=""; 737 | if (t != 0) 738 | { 739 | SEM1 = Program.SemanticStack.Pop(); 740 | Generate("add_par", SEM1, "__", "__"); 741 | } 742 | 743 | ProEP(); 744 | checkTerminal(")"); 745 | var z = getNewVari(); 746 | Generate("call", tempID, "__", z); 747 | Program.SemanticStack.Push(z); 748 | ProMS(); 749 | 750 | } 751 | else 752 | if (checkTerminal(".")) 753 | { 754 | var tempID = ProID(); 755 | checkTerminalE("("); 756 | var t = ProE(); 757 | string SEM1=""; 758 | if (t != 0) 759 | { 760 | SEM1 = Program.SemanticStack.Pop(); 761 | Generate("add_par", SEM1, "__", "__"); 762 | } 763 | ProEP(); 764 | checkTerminalE(")"); 765 | ProMS(); 766 | var z = getNewVari(); 767 | Generate("call", tempID, "__", z); 768 | Program.SemanticStack.Push(z); 769 | 770 | } 771 | else 772 | { 773 | Debug.WriteLine("$"); 774 | return; 775 | // throw new ParserException(string.Format("Error at Line {0}: Supposed @ or .", Program.TokenList.Peek().LineNum)); 776 | } 777 | 778 | 779 | 780 | } 781 | 782 | public string getNewVari() 783 | { 784 | var t = "t" + GeQcount; 785 | GeQcount++; 786 | return t; 787 | } 788 | public void ProN() 789 | { 790 | Console.WriteLine("N"); 791 | if (checkTerminal("(")) 792 | { 793 | ProE(); 794 | checkTerminalE(")"); 795 | } 796 | else 797 | { 798 | 799 | if (checkTerminalN("ID")) 800 | { 801 | 802 | Program.Token[] tmp = Program.TokenList.ToArray(); 803 | if (tmp[1].tokens == getTValue("(")) 804 | { 805 | var tempID=ProID(); 806 | checkTerminalE("("); 807 | var t = ProE(); 808 | if (t != 0) 809 | { 810 | var SEM1 = Program.SemanticStack.Pop(); 811 | Generate("add_par", SEM1, "__", "__"); 812 | } 813 | 814 | 815 | ProEP(); 816 | checkTerminalE(")"); 817 | var z = getNewVari(); 818 | Generate("call",tempID , "__", z); 819 | Program.SemanticStack.Push(z); 820 | 821 | //if (checkTerminal("(")) 822 | //{ 823 | // ProE(); 824 | 825 | // // checkTerminalE(","); 826 | // ProEP(); 827 | // checkTerminalE(")"); 828 | //} 829 | //else 830 | //{ 831 | // return; 832 | //} 833 | } 834 | else 835 | { 836 | var tempID= ProID(); 837 | Program.SemanticStack.Push(tempID); 838 | } 839 | } 840 | else 841 | { 842 | if (checkTerminalN("Integer")) 843 | { 844 | var tempID = ReadValueDeque(); 845 | Program.SemanticStack.Push(tempID); 846 | } 847 | else if (checkTerminalN("String")) 848 | { 849 | var tempID = ReadValueDeque(); 850 | Program.SemanticStack.Push(tempID); 851 | // Program.SemanticStack.Push(); 852 | } 853 | else if (checkTerminal("true")) 854 | { 855 | 856 | Program.SemanticStack.Push("true"); 857 | 858 | } 859 | else if (checkTerminal("false")) 860 | { 861 | Program.SemanticStack.Push("false"); 862 | } 863 | else if (checkTerminal("self")) 864 | { 865 | 866 | } 867 | else if (checkTerminal("new")) 868 | { 869 | 870 | var tempT=ProT();//(New, Type,___,tmp1) 871 | var z = getNewVari(); 872 | Generate("new",tempT,"__",z); 873 | Program.SemanticStack.Push(z); 874 | //GenQ("new",a,"_" 875 | } 876 | else if (checkTerminal("if")) 877 | { 878 | Generate("if", "__", "__", "__"); 879 | ProE(); 880 | var x= Program.SemanticStack.Pop(); 881 | 882 | var lineFill=Generate("j=", x, "false", "__");//wait to fill 883 | 884 | 885 | checkTerminalE("then"); 886 | ProE(); 887 | quadList[lineFill].result = (GeqLine + 1).ToString(); 888 | lineFill = Generate("j", "__", "__", "__"); 889 | 890 | 891 | checkTerminalE("else"); 892 | ProE(); 893 | quadList[lineFill].result = (GeqLine + 1).ToString(); 894 | 895 | checkTerminalE("fi"); 896 | Generate("end_if", "__", "__", "__"); 897 | } 898 | else if (checkTerminal("while")) 899 | { 900 | var temp_w=Generate("while", "__", "__", "__"); 901 | 902 | ProE(); 903 | var x=Program.SemanticStack.Pop(); 904 | var temp_x = Generate("j=", x, "false", "__"); 905 | 906 | checkTerminalE("loop"); 907 | ProE(); 908 | quadList[temp_x].result = (GeqLine + 1).ToString(); 909 | checkTerminalE("pool"); 910 | Generate("j", "__", "__",temp_w.ToString()); 911 | Generate("end_while", "__", "__", "__"); 912 | } 913 | else if (checkTerminal("{")) 914 | { 915 | ProE(); 916 | checkTerminalE(";"); 917 | ProEPS(); 918 | checkTerminalE("}"); 919 | } 920 | else if (checkTerminal("let")) 921 | { 922 | Generate("enter_scope", "__", "__", "__"); 923 | 924 | var id = ProID(); 925 | Program.SemanticStack.Push(id); 926 | checkTerminalE(":"); 927 | ProT(); 928 | ProLEZ(); 929 | 930 | 931 | ProLE(); 932 | checkTerminalE("in"); 933 | ProE(); 934 | Generate("exit_scope", "__", "__", "__"); 935 | 936 | } 937 | else if (checkTerminal("case")) 938 | { 939 | Generate("case", "__", "__", "__"); 940 | 941 | ProE(); 942 | checkTerminal("of"); 943 | ProCA(); 944 | checkTerminal("esac"); 945 | foreach (var line in WaitList) 946 | { 947 | quadList[line].result = GeqLine.ToString(); 948 | } 949 | WaitList.Clear(); 950 | Generate("exit_case", "__", "__", "__"); 951 | } 952 | } 953 | 954 | } 955 | } 956 | 957 | public void ProNA() 958 | { 959 | Console.WriteLine("NA"); 960 | } 961 | 962 | public string tempCA; 963 | public void ProCA() 964 | { 965 | tempCA= Program.SemanticStack.Pop(); 966 | Console.WriteLine("CA"); 967 | ProID(); 968 | checkTerminalE(":"); 969 | var tempT=ProT(); 970 | var linNum=Generate("j_checktype",tempCA,tempT,"__");//place no back 971 | checkTerminalE("=>"); 972 | ProE(); 973 | //Fill back 974 | quadList[linNum].result = (GeqLine+1).ToString(); 975 | var waitLine=Generate("j", "__", "__", "__");//wait to jump, return linenow 976 | WaitList.Add(waitLine); 977 | checkTerminalE(";"); 978 | 979 | ProCAS(); 980 | 981 | } 982 | public List WaitList=new List(); 983 | public void ProCAS() 984 | { 985 | Console.WriteLine("CAS"); 986 | if (checkTerminalN("ID")) 987 | { 988 | ProID(); 989 | checkTerminalE(":"); 990 | var tempT = ProT(); 991 | var linNum = Generate("j_checktype", tempCA, tempT, "__");//place no back 992 | 993 | checkTerminalE("=>"); 994 | ProE(); 995 | //Fill back 996 | quadList[linNum].result = (GeqLine + 1).ToString(); 997 | var waitLine = Generate("j", "__", "__", "__");//wait to jump, return linenow 998 | WaitList.Add(waitLine); 999 | checkTerminalE(";"); 1000 | ProCAS(); 1001 | } 1002 | else 1003 | { 1004 | Debug.WriteLine("$"); 1005 | 1006 | return; 1007 | } 1008 | } 1009 | 1010 | public void ProLE() 1011 | { 1012 | Console.WriteLine("LE"); 1013 | if (checkTerminal(",")) 1014 | { 1015 | var id=ProID(); 1016 | Program.SemanticStack.Push(id); 1017 | checkTerminal(":"); 1018 | ProT(); 1019 | ProLEZ(); 1020 | 1021 | ProLE(); 1022 | } 1023 | else 1024 | { 1025 | Debug.WriteLine("$"); 1026 | 1027 | return; 1028 | } 1029 | } 1030 | 1031 | public void ProEP() 1032 | { 1033 | Console.WriteLine("EP"); 1034 | if (checkTerminal(",")) 1035 | { 1036 | ProE(); 1037 | 1038 | var SEM1 = Program.SemanticStack.Pop(); 1039 | Generate("add_par", SEM1, "__","__"); 1040 | 1041 | ProEP(); 1042 | } 1043 | else 1044 | { 1045 | Debug.WriteLine("$"); 1046 | 1047 | return; 1048 | } 1049 | } 1050 | 1051 | public void ProEPS() 1052 | { 1053 | Console.WriteLine("EPS"); 1054 | if (checkTerminalN("}")) 1055 | { 1056 | Debug.WriteLine("$"); 1057 | 1058 | return; 1059 | } 1060 | else 1061 | { 1062 | 1063 | Program.SemanticStack.Pop(); 1064 | ProE(); 1065 | checkTerminalE(";"); 1066 | ProEPS(); 1067 | 1068 | } 1069 | 1070 | } 1071 | 1072 | 1073 | public class Quad 1074 | { 1075 | public string op; 1076 | public string arg1; 1077 | public string arg2; 1078 | public string result; 1079 | 1080 | public Quad(string Op, string Arg1, string Arg2, string Result) 1081 | { 1082 | this.op = Op; 1083 | this.arg1 = Arg1; 1084 | this.arg2 = Arg2; 1085 | this.result = Result; 1086 | } 1087 | 1088 | public override string ToString() 1089 | { 1090 | return (String.Format("({0},{1},{2},{3})", op, arg1, arg2, result)); 1091 | } 1092 | } 1093 | public static List quadList=new List(); 1094 | public static int GeQcount = 0; 1095 | public static int GeqLine = 0; 1096 | public int Generate(string op, string arg1, string arg2, string result) 1097 | { 1098 | 1099 | var q=new Quad(op,arg1,arg2,result); 1100 | quadList.Add(q); 1101 | Debug.WriteLine(String.Format("{4}:({0},{1},{2},{3})", op, arg1, arg2, result,GeqLine)); 1102 | GeqLine++; 1103 | var lineNow = GeqLine - 1; 1104 | return lineNow; 1105 | } 1106 | //public void Gequad(OperationType type, string op) 1107 | //{ 1108 | // var t = "t" + (++GeQcount); 1109 | // switch (type) 1110 | // { 1111 | // case OperationType.Arith: 1112 | // { 1113 | // switch (op) 1114 | // { 1115 | // case "isvoid": 1116 | // case "~": 1117 | // { 1118 | 1119 | // break; 1120 | // } 1121 | // case "add_par": 1122 | // { 1123 | // var SEM1 = Program.SemanticStack.Pop(); 1124 | // Generate(op, SEM1, "__", "__"); 1125 | 1126 | // break; 1127 | // } 1128 | // case "new": 1129 | // { 1130 | // Generate(op, SEM1, "__", t.ToString()); 1131 | // Program.SemanticStack.Push(t.ToString()); 1132 | // break; 1133 | 1134 | // } 1135 | // default: 1136 | // break; 1137 | // } 1138 | 1139 | // //var SEM1 = Program.SemanticStack.Pop(); 1140 | // //var SEM2 = Program.SemanticStack.Pop(); 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | // break; 1147 | // } 1148 | // case OperationType.Call: 1149 | // { 1150 | // break; 1151 | 1152 | // } 1153 | // case OperationType.Jump: 1154 | // { 1155 | // break; 1156 | // } 1157 | // } 1158 | 1159 | 1160 | //} 1161 | 1162 | public enum OperationType 1163 | { 1164 | Arith = 0, 1165 | Jump = 1, 1166 | Call = 2 1167 | 1168 | } 1169 | 1170 | } 1171 | } 1172 | --------------------------------------------------------------------------------