Lexical analyzer (3. Main program file)

Source: Internet
Author: User

//////////////////////////////////////// //////////////////////////////////
// Fundamentals of Compiler
// Project: World Analysis
// Written by: kejie 03 computer science and techology 086
// Create time: 2006.4.5
// Modified: 2006.4.15
// File name: Main. cpp
// Note: this file is the main program, useing to analyze the source file
// Copyright University of Electronic Science and Technology of China, Zhongshan Institute.
//////////////////////////////////////// //////////////////////////////////

// # Include <iostream. h>
// # Include <fstream. h>
# Include "analysis. H"
# Include <stdio. h>

// File path
Char * charpath = "operatortable.txt ";

Extern char * keyworldpath;
Extern char * sourcepath;
Static int chosenum;

// Variable table, used to save the scanned Variables

// Constant table, used to save the scanned constant

Lex wordanalysis (sourcepath); // lexical analyzer class
Bstree operatortable (charpath, 0x0); // The operator starts encoding from 0x00
Bstree keytable (keyworldpath, 0x040); // The keyword starts encoding from 0x40.

// Program start interface (because it is too late to use MFC to create a program interface, you can only run it in DOS now!
Void interface ()
{
Cout <"University of Electronic Science and Technology of China, Zhongshan Institute" <Endl
<"Computer Engineering Department" <Endl
<"03 Computer Science and Technology" <Endl;
 
Cout <"Author: kejie" <Endl;
 
Cout <SETW (59) <"foundamenation of complieration: Word analysis" <Endl
<SETW (49) <"1. Show the source of read" <Endl
<SETW (51) <"2.run the analysis program" <Endl
<SETW (48) <"3. Print the keyword Tree" <Endl
<SETW (49) <"4. Print the operator Tree" <Endl
<SETW (30) <"5. Exit" <Endl
<"If your have any question about the program or want to learn more about me Please mail to me! "<Endl
<"My email address is: kejieleung@163.com" <Endl
<"Waiting for you! Thank you! "<Endl
<"Please chose an operation :";

}

Void choose (INT num)
{
// Assert (Num> = 1 & num <= 5 );
Switch (Num)
{
Case 1:
Cout <"follow is the Souce read from the outer Fiel source.txt." <Endl;
Wordanalysis. printsource ();
Break;
Case 2:
Cout <"follow is the result of the worl analysis :";
Wordanalysis. Analysis ();
Break;
Case 3:
Cout <"follow is the tree that the program code the Key worlds in the keyword. Text:" <Endl;
Keytable. printtree ();
Break;
Case 4:
Cout <"follow is the tress that the program code the operators int the operatortable.txt" <Endl;
Operatortable. printtree ();
Break;
Case 5:
Break;
Default:
Cout <"input eorror! ";
}

Cout <Endl;
}
Int main ()
{
While (chosenum! = 5)
{
System ("CLS ");
Interface ();
Cin> chosenum;

Choose (chosenum );
Cout <"press any key to continue! "<Endl;
Getchar ();

}

Cout <Endl;
 

Return 0;
}

// Program debugging record (created 4.7 update 4.13)

// 1. There is a problem with string recognition. For example, "X..." in the output should be full output without considering whether it is a keyword (OK)
// 2. the binary operator cannot be recognized (OK)

// 3. Encoding negative (OK)
// 4. The space cannot be correctly confirmed (OK)
// 5. An error occurred while releasing the binary tree (OK)
// 6. The variable is not initialized (the constructor cannot call it by itself) (OK)
// 7. A logical error occurred when determining whether the keyword is a common string (OK)
// 8. Buffer indicates that the bufpos value is abnormal (OK)

// 9. Incomplete Operators
// 10. The variable is repeated (it should be saved in the symbol table and indicated by a pointer)
// 11. Reading comments cannot be removed (OK)
// 12. The error message is not processed.
// 13. The constant table is not created

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.