8
16
2012
66

模块计算语言的设计

本站文章,皆为原创,如需转载,请注明出处,违者必究

一直以来,我都想开发一款类似Simulink的方框图计算软件。这种软件可以方便的对一些线性系统进行建模,从而分析出一个复杂系统对内和对外的输入输出以及调节机制。在Matlab之中,主要用于实现模型的都是一些固定功能的功能模块,当然,他也支持一种用户自定义的用Matlab语言进行编写的自由模块。Matlab设计的是Simulink模式,而对于我所设计的Realsim软件来说,我期待所有模块都可以由用户来定义,最终通过源代码的方式发布一系列的原配功能模型,以实现Matlab的功能化对齐。

Matlab所采用的M语言本身,过于贴近Fortran的思维方式,经过多年的使用经历,作为C系语言的开发者来说,采用C/C++一类的思维模式当然是最好的,同时需要针对具体情况具体分析。从本质上来讲,我设计Realsim本意并非简单的复制一个Simulink,在Matlab之中,M语言自始至终都是考虑为控制台编写运行脚本提供服务,而并非面向Simulink的功能化模块。

Realsim所采用的语言,按照我的思路,应该仅仅是面向Realsim的功能化模块的,无需考虑控制台的各种功能。而对于模块来说,如果我们把它想象为一个封闭黑箱系统,那么它对外只是一些输入和输出(单数、向量、矩阵),所以必须考虑对C系语言扩展到全数据类型的支持,因而下面我们做两部分工作:

  • 第一,对词法进行定义
    • 首先,定义内嵌功能名(分隔、运算、逻辑、循环、分支、返回)
    • 其次,定义数字型词法(整数、小数)
    • 第三,定义定义名词法(函数、变量名)

因而按照如下定义:

内嵌功能:,,  ;,  (,  ),  [,  ],  {,  },
        +,  -,  *,  /,  %,  ^,  <,  >,  =,  !,  &&, ||,
        +=, -=, *=, /=, %=, ^=, <=, >=, ==, !=, &=, |=,
        if, else, break, for, switch, case, do, while, return, null (共计32种符号,42种状态,其中null为0X0矩阵,意味着内容为空)
数字类型:[0-9]+, [0-9]+.[0-9]*   (共计两个状态)
定义名称:[_a-zA-Z][_a-zA-Z0-9]*  (共计一个状态)

有了以上的词法定义,我们就可以开发词法器了。按照传统的方式,我们采用自动机来完成这部分的开发,当然,首先需要我们设计一个状态表。现在我来设计这样的状态表,它是个二维矩阵,状态表默认值初始化为0,横向宽256,代表当前符号类型(ASCII),纵向高42,分别代表当下状态类型。在一种状态下遇到某一条件符号,则会进入相应的新状态,最终得到结果状态后,则跳转返回最终值。跳出条件为,状态最高位0x80设置为1。

代码如下:


// 各种词法状态
#define ST_INITIAL           0x00;
#define ST_COMMA             0x80;
#define ST_SEMICOLON         0x81;
#define ST_LEFT_PARENTHESES  0x82;
#define ST_RIGHT_PARENTHESES 0x83;
...

struct CLexer
{
  unsigned char m_nTable[45][256];

  Lexer() {

    // 初始化状态表

    for(int i = 0; i < 45; i++)
      for(int j = 0; j < 256; j++)
        m_nTable[i][j] = ST_INITIAL;

    // 对状态跳转进行编程

    m_nTable[0][','] = ST_COMMA;
    m_nTable[0][';'] = ST_SEMICOLON;
    m_nTable[0]['('] = ST_LEFT_PARENTHESES;
    m_nTable[0][')'] = ST_RIGHT_PARENTHESES;
    ...
  }

  int Process(CSource *src) {
    unsigned char nStatus = 0;

    while (!(nStatus & 0x80)) {
      nStatus = m_nTable[nStatus][src->text[src->index++]];
    }

    return nStatus;
  }
};
  • 第二,对数据类型进行改造和扩展。
    • 首先,Realsim语言之中,仅保留浮点型变量,去除字符型变量与整形变量、指针的支持。
    • 其次,每一个变量全都以矩阵实现,默认用于计数和控制的变量为1X1矩阵。
    • 第三,变量有默认的查询函数,和取数据功能。

这样我们得到如下的范例:

a = 1;                      // 赋值,直接赋予单数,数字默认为double浮点型
a = {{1, 2, 3}, {4, 5, 6}}; // 赋值,采用C语言标准来实现,摒弃M语言面向数学家的方式
b = a[2][3];                // 取值,取后b自动初始化为相应尺寸,当前结果为1X1单数
b = a[];                    // 查询,获取a矩阵尺寸,结果为1X2向量,表达a的高、宽值

(未完待续)

Category: 默认分类 | Tags: | Read Count: 1648
Avatar_small
UPMSP 6th Question 说:
2023年9月03日 22:00

Students Practicing UPMSP 6th Important Question paper 2024 helps the Students to Perform well in the Public Exam 2024, Here we have Compiled the UP Board Model Paper 2024, Students can Download the Guess Paper of all the Subjects Social Science, Scince, Mathematics, Hindi, English, The board will soon Release the UP Question 2024 for the Remaining Subjects as well.Students UPMSP 6th Question Paper 2024 Check the UP Model Paper 2024 this Web page Provide Direct links for Subject Wise pdf Download, Important Questions That Appear in Examination 2024 are as per the Pattern issued by Uttar Pradesh Madhyamik Shiksha Parishad Students Pass Exam with Outstanding Marks.

Avatar_small
seo service london 说:
2023年11月01日 21:23

Thanks mate. I am really impressed with your writing talents and also with the layout on your weblog. Appreciate, Is this a paid subject matter or did you customize it yourself? Either way keep up the nice quality writing, it is rare to peer a nice weblog like this one nowadays

Avatar_small
토토사이트주소 说:
2023年11月06日 18:47

Can I simply say what a reduction to search out someone who really is aware of what theyre talking about on the internet. You definitely know easy methods to carry a problem to mild and make it important. More people must read this and understand this aspect of the story. I cant believe youre no more popular because you definitely have the gift.

Avatar_small
메이저사이트 说:
2023年11月06日 18:50

I in addition to my buddies happened to be digesting the excellent points located on your web site and then all of the sudden I had an awful feeling I never expressed respect to the site owner for them. All the men were absolutely thrilled to read through them and have

Avatar_small
리버카지노 도메인 주소 说:
2023年11月06日 19:52

An impressive share, I just given this onto a colleague who had previously been performing a small analysis on this. And hubby in fact bought me breakfast simply because I found it for him.. smile. So permit me to reword that: Thnx for the treat! But yeah Thnkx for spending any time go over this, I find myself strongly regarding this and really like reading much more about this topic. If you can, as you grow expertise, does one mind updating your blog post with increased details? It can be extremely helpful for me. Massive thumb up with this blog post!

Avatar_small
슈어맨주소 说:
2023年11月06日 19:58

Hello, Neat post. There’s a problem along with your web site in internet explorer, would test this? IE nonetheless is the market leader and a huge element of folks will pass over your great writing due to this problem.|so I only wanted to offer a fast shout out and claim I genuinely enjoy studying your articles. Could you suggest any other blogs/websites/forums that will deal with the identical subjects? Thanks.

Avatar_small
네임드스코어 说:
2023年11月06日 20:06

The vacation delivers on offer are : believed a selection of some of the most selected and additionally budget-friendly global. Any of these lodgings tend to be very used along units may accented by means of pretty shoreline supplying crystal-clear turbulent waters, concurrent with the Ocean. hotels packages

Avatar_small
메이저사이트 说:
2023年11月06日 20:19

It’s the best time to make a few plans for the longer term and it is time to be happy. I have learn this post and if I may just I wish to counsel you few attention-grabbing issues or advice. Maybe you can write next articles relating to this article. I wish to read even more things approximately it!|

Avatar_small
토토디텐드 说:
2023年11月06日 20:49

Just wish to say your article is as amazing. The clarity in your post is just nice and i could assume you are an expert on this

Avatar_small
오래된사설토토 说:
2023年11月06日 20:52

Fantastic blog! Do you have any tips and hints for aspiring writers? I’m planning to start my own site soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m totally overwhelmed .. Any suggestions? Bless you!|

Avatar_small
먹튀중개소 인증업체 说:
2023年11月06日 21:08

Hey! Someone in my Facebook group shared this website with us so I came to give it a look. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers! Terrific blog and amazing design.| You reported this exceptionally well! fda kratom

Avatar_small
먹튀 说:
2023年11月06日 21:09

you’re actually a just right webmaster. The web site loading pace is incredible. It seems that you are doing any unique trick. Moreover, The contents are masterpiece. you have done a wonderful job on this matter! you’re in point of fact a excellent webmaster. The web site loading velocity is amazing. It sort of feels that you’re doing any unique trick. Also, The contents are masterpiece. you’ve done a wonderful job on this matter!

Avatar_small
안전놀이터 说:
2023年11月06日 21:23

I’m impressed, I must say. Actually rarely do you encounter a blog that’s both educative and entertaining, and let me tell you, you’ve got hit the nail to the head. Your notion is outstanding; the issue is an issue that not enough people are speaking intelligently about. I am very happy that we found this at my look for something about it.

Avatar_small
소울카지노가입코드 说:
2023年11月06日 21:27

it is a really nice point of view. I usually meet people who rather say what they suppose others want to hear. Good and well written! I will come back to your site for sure!I was reading through some

Avatar_small
ok토토먹튀검증 说:
2023年11月06日 21:37

Today, I went to the beachfront with my kids. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is completely off topic but I had to tell someone!|

Avatar_small
토토사이트 说:
2023年11月06日 21:48

Hello, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam responses? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me crazy so any assistance is very much appreciated.|

Avatar_small
퀸즈카지노가입 说:
2023年11月06日 21:51

Strong blog. I acquired several nice info. I?ve been keeping a watch on this technology for a few time. It?utes attention-grabb

Avatar_small
메이저토토사이트 说:
2023年11月06日 22:03

An impressive share, I just given this onto a colleague who had previously been performing a small analysis on this. And hubby in fact bought me breakfast simply because I found it for him.. smile. So permit me to reword that: Thnx for the treat! But yeah Thnkx for spending any time go over this, I find myself strongly regarding this and really like reading much more about this topic. If you can, as you grow expertise, does one mind updating your blog post with increased details? It can be extremely helpful for me. Massive thumb up with this blog post!

Avatar_small
메이저놀이터 说:
2023年11月06日 22:08

Being grateful for for your post. I know that within today’s complicated world, folks have many beliefs and this has made it to be really hard for learners just like me. However, you have made the idea very easy for me to comprehend and I now know the correct thing. Your continued reputation among the top experts with this topic may be enhanced through words of appreciation from followers like me. Thanks, once more.

Avatar_small
บาคาร่าออนไลน์ 说:
2023年11月06日 22:21

This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! Keep up the good work.World Facts For Children… […]here are some links to sites that we link to because we think they are worth visiting[…]…

Avatar_small
토토사이트 说:
2023年11月06日 22:25

I am extremely impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it’s rare to see a great blog like this one these days.| Informative, pretty much as I had come to expect from this site.

Avatar_small
파워볼사이트 说:
2023年11月06日 22:59

The vacation delivers on offer are : believed a selection of some of the most selected and additionally budget-friendly global. Any of these lodgings tend to be very used along units may accented by means of pretty shoreline supplying crystal-clear turbulent waters, concurrent with the Ocean. hotels packages

Avatar_small
파워볼사이트 说:
2023年11月06日 23:00

The vacation delivers on offer are : believed a selection of some of the most selected and additionally budget-friendly global. Any of these lodgings tend to be very used along units may accented by means of pretty shoreline supplying crystal-clear turbulent waters, concurrent with the Ocean. hotels packages

Avatar_small
스포츠토토 说:
2023年11月06日 23:01

Hey there would you mind stating which blog platform you’re working with? I’m going to start my own blog soon but I’m having a difficult time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique. P.S My apologies for getting off-topic but I had to ask!|

Avatar_small
먹튀사이트 说:
2023年11月06日 23:06

An impressive share, I just given this onto a colleague who had previously been performing a small analysis on this. And hubby in fact bought me breakfast simply because I found it for him.. smile. So permit me to reword that: Thnx for the treat! But yeah Thnkx for spending any time go over this, I find myself strongly regarding this and really like reading much more about this topic. If you can, as you grow expertise, does one mind updating your blog post with increased details? It can be extremely helpful for me. Massive thumb up with this blog post!

Avatar_small
먹튀검증 커뮤니티 说:
2023年11月06日 23:22

The vacation delivers on offer are : believed a selection of some of the most selected and additionally budget-friendly global. Any of these lodgings tend to be very used along units may accented by means of pretty shoreline supplying crystal-clear turbulent waters, concurrent with the Ocean. hotels packages

Avatar_small
토토검증 说:
2023年11月06日 23:23

Does your blog have a contact page? I’m having a tough time locating it but, I’d like to shoot you an e-mail. I’ve got some ideas for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it grow over time.|

Avatar_small
토토사이트 Wbet 说:
2023年11月06日 23:45

Fantastic blog! Do you have any tips and hints for aspiring writers? I’m planning to start my own site soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m totally overwhelmed .. Any suggestions? Bless you!|

Avatar_small
카지노사이트추천 说:
2023年11月06日 23:48

We are a group of volunteers and starting a new scheme in our community. Your site provided us with helpful info to work on. You have performed a formidable activity and our entire neighborhood will be thankful to you.| I just want to mention I am new to blogging and site-building and really savored this blog site. Very likely I’m likely to bookmark your blog post . You surely come with tremendous article content. Appreciate it for sharing with us your web-site.

Avatar_small
카이소 说:
2023年11月07日 00:01

Being grateful for for your post. I know that within today’s complicated world, folks have many beliefs and this has made it to be really hard for learners just like me. However, you have made the idea very easy for me to comprehend and I now know the correct thing. Your continued reputation among the top experts with this topic may be enhanced through words of appreciation from followers like me. Thanks, once more.

Avatar_small
사설토토 说:
2023年11月07日 00:10

Hey! Someone in my Facebook group shared this website with us so I came to give it a look. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers! Terrific blog and amazing design.| You reported this exceptionally well! fda kratom

Avatar_small
먹튀사이트 说:
2023年11月07日 00:26

Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your website? My website is in the very same area of interest as yours and my users would certainly benefit from some of the information you provide here. Please let me know if this alright with you. Thanks a lot!|

Avatar_small
메이저놀이터주소 说:
2023年11月07日 00:29

Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your website? My website is in the very same area of interest as yours and my users would certainly benefit from some of the information you provide here. Please let me know if this alright with you. Thanks a lot!|

Avatar_small
먹튀검증커뮤니티추천 说:
2023年11月07日 00:43

Excellent post. I was checking continuously this weblog and I’m inspired! Very useful information specifically the remaining phase  I deal with such info much. I used to be seeking this certain info for a very long time. Thank you and good luck. |I was suggested this website by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty. You’re wonderful! Thanks!|

Avatar_small
먹튀제보 说:
2023年11月07日 00:46

Being grateful for for your post. I know that within today’s complicated world, folks have many beliefs and this has made it to be really hard for learners just like me. However, you have made the idea very easy for me to comprehend and I now know the correct thing. Your continued reputation among the top experts with this topic may be enhanced through words of appreciation from followers like me. Thanks, once more.

Avatar_small
먹튀대피소 说:
2023年11月07日 00:55

I know this if off topic but I’m looking into starting my own weblog and was wondering what all is needed to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web savvy so I’m not 100 certain. Any tips or advice would be greatly appreciated. Many thanks|

Avatar_small
사설토토추천 说:
2023年11月07日 01:18

I absolutely love your blog and find a lot of your post’s to be exactly what I’m looking for. Does one offer guest writers to write content for yourself? I wouldn’t mind creating a post or elaborating on many of the subjects you write concerning here. Again, awesome web log!|

Avatar_small
안전놀이터순위 说:
2023年11月07日 01:37

It’s the best time to make a few plans for the longer term and it is time to be happy. I have learn this post and if I may just I wish to counsel you few attention-grabbing issues or advice. Maybe you can write next articles relating to this article. I wish to read even more things approximately it!|

Avatar_small
먹튀사이트 说:
2024年1月14日 20:18

I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful.

Avatar_small
슬롯커뮤니티 说:
2024年1月14日 22:23

This Is Very Nice and Wonderful Keep Writing Such type Of Wonderful blogs

Avatar_small
토토사이트 说:
2024年1月14日 23:23

You have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!

Avatar_small
소액결제현금화 说:
2024年1月14日 23:43

Hmm!! This blog is really cool, I’m so lucky that I have reached here and got this awesome information.

Avatar_small
카지노사이트 说:
2024年1月15日 00:07

hi was just seeing if you minded a comment. i like your website and the thme you picked is super. I will be back.

Avatar_small
스포츠무료중계 说:
2024年1月15日 00:20

Thank you Superb article. When I saw Jon’s email, I know the post will be good and I am surprised that you wrote it man!

Avatar_small
카지노사이트 说:
2024年1月15日 01:06

Wow, cool post. I'd like to write like this too — taking time and real hard work to make a great article… but I put things off too much and never seem to get started. Thanks though.

Avatar_small
ios industrial real 说:
2024年1月15日 01:10

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too.

Avatar_small
토토사이트 说:
2024年1月15日 01:45

I like this website so much, saved to favorites .

Avatar_small
슬롯사이트 说:
2024年1月15日 18:29

You completed certain reliable points there. I did a search on the subject and found nearly all persons will agree with your blog.

Avatar_small
바카라사이트 说:
2024年1月15日 19:00

Very good blog post.Much thanks again. Cool.

Avatar_small
바카라 커뮤니티 说:
2024年1月15日 21:47

Phenomenal blog. I delighted in researching your articles. This is to an extraordinary degree an amazing examined for me. I have bookmarked it and I am suspecting inspecting new articles. Continue doing shocking

Avatar_small
seo serviseo service 说:
2024年1月15日 22:14

Whenever I have some free time, I visit blogs to get some useful info. Today, I found your blog with the help of Google ; I found it one of the most informative blog

Avatar_small
카지노 커뮤니티 说:
2024年1月15日 22:38

"Nice blog here! Also your website loads up very fast!
What host are you using? Can I get your affiliate
link to your host? I wish my website loaded up as fast as
yours lol"

Avatar_small
civaget 说:
2024年1月17日 02:29

오피타임's competitive pricing for premium services is a win-win.

Avatar_small
civaget 说:
2024年1月17日 09:42

제주안마's ability to release stress, ease pain, and promote mental clarity makes it the perfect choice for a wellness escape on Jeju Island.

Avatar_small
카지노사이트 说:
2024年1月17日 18:50

I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work.

Avatar_small
메이저사이트 说:
2024年1月17日 21:15

I personally use them exclusively high-quality elements : you will notice these folks during

Avatar_small
바카라 사이트 추천 说:
2024年1月21日 16:43

온라인 카지노 커뮤니티 온카허브 입니다. 온카허브는 카지노 먹튀 사이트들과 안전한 카지노 사이트 정보를 공유하고 있습니다. 카지노 먹튀검증 전문팀을 자체적으로 운영함으로써 철저한 검증을 진행하고 있습니다. [url] https://oncahub24.com/ [/url]

 
Avatar_small
온라인 카지노 먹튀 说:
2024年1月21日 17:21

온라인 카지노 커뮤니티 온카허브 입니다. 온카허브는 카지노 먹튀 사이트들과 안전한 카지노 사이트 정보를 공유하고 있습니다. 카지노 먹튀검증 전문팀을 자체적으로 운영함으로써 철저한 검증을 진행하고 있습니다.

Avatar_small
카지노 说:
2024年1月22日 22:40

카지노 우리카지노 카지노는 바카라, 블랙잭, 룰렛 및 슬롯 등 다양한 게임을 즐기실 수 있는 공간입니다. 게임에서 승리하면 큰 환호와 함께 많은 당첨금을 받을 수 있고, 패배하면 아쉬움과 실망을 느끼게 됩니다.

Avatar_small
바카라 사이트 추천 说:
2024年1月22日 22:47

하노이 꼭 가봐야 할 베스트 업소 추천 안내 및 예약, 하노이 밤문화 에 대해서 정리해 드립니다. 하노이 가라오케, 하노이 마사지, 하노이 풍선바, 하노이 밤문화를 제대로 즐기시기 바랍니다. 하노이 밤문화 베스트 업소 요약 베스트 업소 추천 및 정리. https://hanoi-nightlife.com/

Avatar_small
먹튀사이트 说:
2024年1月24日 16:26

No.1 먹튀검증 사이트, 먹튀사이트, 검증사이트, 토토사이트, 안전사이트, 메이저사이트, 안전놀이터 정보를 제공하고 있습니다. 먹튀해방으로 여러분들의 자산을 지켜 드리겠습니다. 먹튀검증 전문 커뮤니티 먹튀클린만 믿으세요!!

Avatar_small
베트남 밤문화 说:
2024年1月24日 20:02

베트남 남성전용 커뮤니티❣️ 베트남 하이에나 에서 베트남 밤문화를 추천하여 드립니다. 베트남 가라오케, 베트남 VIP마사지, 베트남 이발관, 베트남 황제투어 남자라면 꼭 한번은 경험 해 봐야할 화끈한 밤문화로 모시겠습니다. 

Avatar_small
seo service UK 说:
2024年2月23日 22:09

I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work...

Avatar_small
블록체인개발 说:
2024年4月22日 19:31

블록체인개발 코인지갑개발 IT컨설팅 메스브레인팀이 항상 당신을 도울 준비가 되어 있습니다. 우리는 마음으로 가치를 창조한다는 철학을 바탕으로 일하며, 들인 노력과 시간에 부흥하는 가치만을 받습니다. 고객이 만족하지 않으면 기꺼이 환불해 드립니다.
https://xn--539awa204jj6kpxc0yl.kr/

Avatar_small
Cryto exchange 说:
2024年5月31日 17:52

The tech-original mission is to help you better understand technology, and make better decisions in the fields of IT, Tech, and Crypto.
https://www.tech-original.com/

Avatar_small
Cryto exchange 说:
2024年6月06日 19:43

The tech-original mission is to help you better understand technology, and make better decisions in the fields of IT, Tech, and Crypto.
https://www.tech-original.com/


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com