- 博客(14)
- 资源 (8)
- 收藏
- 关注
原创 编译器DIY——词法分析
在上一篇文章中已经介绍了读文件的操作,那么这一篇文章中将会仔细解释词法分析。在源文件中解析出的单词流必须识别为保留字,标识符,常量,操作符和界符五大类1.显然我们需要列举出所有的保留字,而这里与保留字相似的那么就是标识符,在C语言中,保留字都是以小写字母开头,而且其中的字母只能是小写字母,而标识符的第一个字母则必须为字符(小写大写皆可)后面可以接大小写字母和字符 ‘_’, 在我写的这个编译
2014-06-14 16:01:05 1920
原创 编译器DIY——读文件
编译器的前端词法分析:将源文件解析成一个个的单词流,为语法分析做准备。在词法分析阶段,我们要做的就是将词分出来,并且确定单词的类型,一般的程序设计语言的单词符号可以份为以下5种:1.关键字,如int,long等2.标识符,用来表示各种名字,如常量名,变量名等3.常数,各种类型的常数,如12,1.2等4.运算符:如+,-,*,/等5.界符,如“,”“;”等那么在实际的过程
2014-06-12 09:44:10 1271
原创 编译器DIY之———统计英文文本中的单词数,字符数和行数
咳咳,这一章节应该是连载编译器的DIY的,可是在做DIY之前先用flex 来练练手,对于后面的理解有帮助作用。在word 中我经常看到有一个单词统计的功能,那么是怎么来实现的了,当然第一个念头就是遍历整个文本依据换行和空格对字符串进行分析,那么这是可行的。可是能不能简单点了,其实对文本做单词分析,大家都知道怎么做,难得地方可能就是代码的实现了,那么现在如果使用正则表达式来实现的话,那么一切问题
2014-06-10 09:31:34 4196
原创 projecteuler---->problem=25----1000-digit Fibonacci number
问题描述:The Fibonacci sequence is defined by the recurrence relation:Fn = Fn1 + Fn2, where F1 = 1 and F2 = 1.Hence the first 12 terms will be:F1 = 1F2 = 1F3 = 2F4 = 3F5 = 5F6 = 8
2014-06-09 17:07:54 1093
原创 projecteuler---->problem=24----Lexicographic permutations
问题描述:A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabeti
2014-06-09 16:50:01 1149
原创 projecteuler---->problem=23----Non-abundant sums
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means th
2014-06-07 11:19:34 1223
原创 projecteuler---->problem=22----Names scores
sing names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical v
2014-06-05 10:19:32 1301
原创 projecteuler---->problem=21----Amicable numbers
Let d(n) be defined as the sum of proper divisors of n (numbers less thann which divide evenly into n).If d(a) = b and d(b) = a, where a b, then a and b are an amicable pair and each of a andb
2014-06-05 08:50:31 1117
原创 projecteuler---->problem=20----Factorial digit sum
n! means n (n 1) ... 3 2 1For example, 10! = 10 9 ... 3 2 1 = 3628800,and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.Find the sum of the digits
2014-06-05 08:26:43 1301
原创 projecteuler---->problem=19----Counting Sundays
You are given the following information, but you may prefer to do some research for yourself.1 Jan 1900 was a Monday.Thirty days has September,April, June and November.All the rest have thirty
2014-06-05 07:55:42 1107
原创 projecteuler---->problem=18----Maximum path sum I
By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.37 42 4 68 5 9 3That is, 3 + 7 + 4 + 9 = 23.Find th
2014-06-04 22:48:16 1185
原创 projecteuler---->problem=15----Lattice paths
Starting in the top left corner of a 22 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.How many such routes are there through a 20
2014-06-03 16:43:24 1213 1
原创 projecteuler---->problem=16----Power digit sum
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.What is the sum of the digits of the number 21000?翻译:215 = 32768的各位数之和为3 + 2 + 7 + 6 + 8 = 26。那么21000的各位数之和为……?import
2014-06-03 15:47:31 1122
原创 projecteuler---->problem=14----Longest Collatz sequence
title:The following iterative sequence is defined for the set of positive integers:n n/2 (n is even)n 3n + 1 (n is odd)Using the rule above and starting with 13, we generate the followi
2014-06-03 10:16:43 1274
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人