比较文件文本的内容与数组中的字母

问题描述:

我制作了来自(az)的所有字母的数组,我想比较文本文件的内容与这个数组,我想这样做,因为我需要区分标识符和保留字。

i已经为保留字写了代码,但我不能用作标识符。

i需要任何想法。

thx。

i made array that had all letter from(a-z) ,i want to compare the content of text file with this array ,i want to make that because i need to distinguish between identifier and reserved word.
i already write code for reserved word but i can''t for identifier.
i need any idea please.
thx.

好的,我看到一些类型的数组,但你不会说一个什么样的数组。


比较的性质是什么?你所说的只是比较。没有说什么样的比较。


你是什么意思保留字和标识符?那与你的比较有什么关系?
OK, I see an array of some type but you don''t say an array of what.

What is the nature of your comparison? All you say is "compare" without saying what kind of comparison.

What do you mean by "reserved word" and "identifier"? And how is that related to your comparison?


我想在文本文件中创建程序,这个文件包含c ++程序,程序可能用其他语言编写。

保留字像(for,if,while,......)即这些单词我不能把它写成变量。

标识符任何单词但这个单词不能以数字,但可能包含中间的数字,如(x1,count,sum2,......)。

i想在borland c ++编写程序告诉我哪个单词将成为标识符,哪个将是保留字,这将发生在我阅读文本文件时。

in borland c ++我制作的数组包含来自(az)的所有字母,将这些字母与文本文件中的每个字词进行比较,当第一个字时在txt与数组中的任何字母匹配时,这个单词将成为标识符。

i代码告诉我保留字的位置,但我不知道为此任务编写正确的代码。

i希望我的问题现在宣布。

thx。
i want to make program in text file this file contains program by c++,the program may be written by another language.
reserved word like(for,if,while,......)i.e these word i can''t write it as variable.
identifier any word but this word must not start with digit but may contain digit in the middle like(x1,count,sum2,......).
i want to write program in borland c++ to tell me which word will be identifier and which will be reserved word ,this will happen when i read text file .
in borland c++ i made array contain all letter from (a-z) to compare these letter with every word in the text file ,when the first word in txt match with any letter in array ,this word will be identifier .
i made code to tell me where is the reserved word but i don''t know writing right code for this task.
i hope my problem declared now.
thx .


我不确定你的方法是否有效。


我建议你写一个字典的文本文件。将所有保留的单词和标识放在该文件中。添加一个代码,指示该单词是保留字还是关键字。


启动程序时,将字典文件读入数组。


然后,读取您的数据文件并查找字典数组中的单词。


如果您想获得一点点发烧友,请将您的字典文件读入地图<&gt ;容器并在容器中执行查找,而不是按顺序通过数组。
I am not sure your approach will work.

I suggest you write a text file that is a dictionary. Put all of your reserved words and identifers in that file. Add a code that indicates whether the word is a reserved word or a keyword.

When you start your program, read the dictionary file into an array.

Then, read your data file and look up the words in the dictionary array.

If you want to get a little fancier, read your dictionary file into a map<> container and do the lookups in the container rather than goiing throug the array sequentially.