pascal

PASCAL语言子集的词法、语法分析器之实现

丶灬走出姿态 提交于 2020-01-04 23:56:34
针对简单的文法(PASCAL语言子集),制作相应的词法分析器和递归下降的语法分析器。 文法要求如下: 1、 关键字、标识符、数字等: 1.begin 2.if 3.then 4.while 5.do 6.end 10. 标识符 11. 数字 13.+ 14.- 15.* 16./ 17.: 18.:= 20.< 21.<> 22.<= 23.> 24.>= 25.= 26.; 27.( 28.) 2、 文法规则 : 程序 → begin 语句串 end 语句串 → 语句 { ; 语句 } 语句 → 赋值语句 | 条件语句 | 循环语句 赋值语句 → 变量 := 表达式 条件语句 → if 条件 then ( 语句 | 程序 ) 循环语句 → while 条件 do ( 语句 | 程序 ) 表达式 → 项 { + 项 | - 项 } 条件 → 表达式 关系符 表达式 关系符 → < | <> | <= | > | >= | = 项 → 因子 { * 因子 | / 因子 } 因子 → 变量 | 数字 | ( 表达式 ) 变量 → 标识符 一、 词法分析器 词法分析器的任务是清除源文件中多余的空格、换行、制表符等,识别文法符号。按顺序输出识别的标识符及其种别编号,供语法分析器调用。 代码如下: #include <stdio.h> #include <string.h> #include

GetEnumName TypeInfo problems (pascal / Delphi console)

旧街凉风 提交于 2020-01-03 20:58:09
问题 Working on a console application using Delphi 7, and have run into a problem. I get an error on line 26 after str := GetEnumName(TypeInfo (words[3].group), The error reads "[Error] Project1.dpr(26): TYPEINFO standard function expects a type identifier" if anyone could help with this, it would be a great help! Cheers! program Project1; {$APPTYPE CONSOLE} uses SysUtils, TypInfo; type wordset = Record word : String; group : (flavour, colour, place, animal); end; Var words : Array [1..50] of

Using C++ interface in delphi/pascal

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 05:56:09
问题 I have the following interface defined in a dll: class TestInterface { public: int foo(int)=0; }; And the following functions let's me create objects of this type: extern "C" declspec(dllexport) TestInterface* __stdcall CreateInterface(); The interface is implemented in the dll and I can use it in C++ without any problems (I've also defined the .def file to make sure everything works correctly). However when it comes to using it in pascal I have problems. Here's how I'm trying to use the

How to access registry of a remote machine in Inno Setup

*爱你&永不变心* 提交于 2020-01-03 04:55:07
问题 I have Inno Setup installers that I use to update computers at customer sites. Generally there are two computers, but sometimes three or more. All are networked, and exactly one is headless. It is relatively easy to run the installer on all the headed (if that's the opposite of headless?) workstations, thus running all tasks associated with those computers. There are also tasks that need to be performed on the headless workstation. Generally, these are quick, simple tasks (copying small files

C#代码规范 程序员必备的秘笈

江枫思渺然 提交于 2020-01-03 01:41:21
1. 引言 本文是一套面向C# programmer 和C# developer 进行开发所应遵循的开发规范。 按照此规范来开发C#程序可带来以下益处: · 代码的编写保持一致性, · 提高代码的可读性和可维护性, · 在团队开发一个项目的情况下,程序员之间可代码共享 · 易于代码的回顾, 本规范是初版,只适用于一般情况的通用规范,并不能覆盖所有的情况。 2. 文件组织 2.1 C# 源文件 类名或文件名要简短,不要超过2000LOC,将代码分割开,使结构清晰。将每个类放在一个单独的文件中,使用类名来命名文件名(当然扩展名是.cs)。这种约定会使大家工作更简单。 2.2 目录设计 为每一个命名空间创建一个目录。(用MyProject/TestSuite/TestTier作为MyProject.TestSuite.TestTier的路径,而不用带点的命名空间名做路径)这样可以更容易地将命名空间映射到目录层次划分。 3. 缩进 3.1 换行 当一个表达式超过一行时,根据这些通用原则进行处理: · 在逗号后换行。 · 在操作符后换行。 · 在高层换行而不要在低层处换行。 · 折行后对齐上一行语句同一层的表达式起始位置。 方法调用换行示例: longMethodCall(expr1, expr2, expr3, expr4, expr5); 算术表达式换行示例: 推荐: var = a *

C# 编码规范

a 夏天 提交于 2020-01-03 01:31:03
Pascal命名法:每个单词首字母均大写。 Camel命名法:第一个单词首字母小写,其余单词首字母大写。 类: 1、使用 Pascal 大小写。 2、用名词或名词短语命名类,保证类名清晰,尽量达到望文生义的境界。 3、类名称尽量少用或不用缩写,若使用了缩写一定要在注释中详细注明类的用途。 4、不要使用类型前缀,例如,类名称前加上C以表示这是一个类,如:CButton。 5 、类命名中不要使用下划线及数字。 6 、有时候虽然该类不是接口,但需要提供以字母 I 开始的类名称,此时只要 I 是作为类名称组成部分的整个单词的第一个字母,这依然是可行的。例如,类名 IdentityOrder 就是适用的。 类命名示例: public class FlightBuilder public class HotelInfo public class TicketShopper 接口: 1、 接口使用大些字母I做前缀,其后跟名词或名词短语,以描述这个接口,名词和短语使用Pascal方式,如,接口名称 ICache。 2、接口名称尽量少用或不用缩写,保证接口名清晰,尽量达到望文生义的境界,若使用了缩写一定要在注释中详细描述接口的用途。 3、接口名称中不要使用下划线及数字。 接口命名示例: public interface ICache public interface IClone 枚举: 1

Specially debugging line by line

半世苍凉 提交于 2020-01-02 07:37:12
问题 I have a script written in Pascal. I would to debug it in this way: stop at every line, dump values of all variables in memory and go to the next line. Is it possible to do it with gdb or some other open-source tool for Linux? 回答1: Compile file with option -g : fpc/gpc -g file.pas Run gdb for this file: gdb file Set all of needed variables: display first_var display second_var ... Start debugging: start By pressing s you can continue to the next line. 回答2: I'll present a proof-of-concept that

Specially debugging line by line

北战南征 提交于 2020-01-02 07:36:12
问题 I have a script written in Pascal. I would to debug it in this way: stop at every line, dump values of all variables in memory and go to the next line. Is it possible to do it with gdb or some other open-source tool for Linux? 回答1: Compile file with option -g : fpc/gpc -g file.pas Run gdb for this file: gdb file Set all of needed variables: display first_var display second_var ... Start debugging: start By pressing s you can continue to the next line. 回答2: I'll present a proof-of-concept that

Move() to Insert/Delete item(s) from a dynamic array of string

戏子无情 提交于 2019-12-31 21:54:29
问题 Using System.Move() to insert/delete item(s) from an array of string is not as easy as insert/delete it from other array of simple data types. The problem is ... string is reference counted in Delphi. Using Move() on reference-counted data types needs deeper knowledge on internal compiler behaviour. Can someone here explain the needed steps for me to achieve that, or better with some snippet codes, or direct me to a good reference on the internet? Oh, Please don't tell me to use the "lazy-but

Delphi - Using DeviceIoControl passing IOCTL_DISK_GET_LENGTH_INFO to get flash media physical size (Not Partition)

心不动则不痛 提交于 2019-12-30 07:08:28
问题 Alright this is the result of a couple of other questions. It appears I was doing something wrong with the suggestions and at this point have come up with an error when using the suggested API to get the media size. Those new to my problem I am working at the physical disk level, not within the confines of a partition or file system. What I am doing I am trying to get the size of a flash card from the first block to the last, boot record partition space and all. While I don't need it to dump