# compilers **Repository Path**: jingok/compilers ## Basic Information - **Project Name**: compilers - **Description**: 编译原理大作业,2015 - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2015-11-17 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 软件工程大作业-编译原理 实现方式:使用`Node.js`的API,使得具备了对本地文件进行读写的能力,同时也脱离了浏览器环境,可以将`绘图服务`跑在服务器上. # 配置环境 ### 安装Node.js(略) ### 安装Node-canvas 此插件依赖于`Cario`,所以在安装它之前需要安装一些依赖,大体如下,具体可以看官方文档.[链接](https://github.com/Automattic/node-canvas) ``` OS X brew install pkg-config cairo libpng jpeg giflib Ubuntu sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++ Windows [wiki](https://github.com/Automattic/node-canvas/wiki/Installation---Windows) ``` 依赖安装好以后,执行: ``` npm install canvas ``` # 开始使用 ## 1. 准备输入文件 创建demo.txt,如下所示: ``` -- 函数曲线 rot is 0; origin is (200,500); scale is(2,1); for t from 0 to 300 step 1 draw(t,0); for t from 0 to 300 step 1 draw(0,-t); for t from 0 to 300 step 1 draw(t,-t); scale is (2,0.1); for t from 0 to 55 step 0.1 draw(t,-(t*t)); scale is (10,5); for t from 0 to 60 step 0.1 draw(t,-sqrt(t)); scale is (2,20); for t from 0 to 300 step 0.1 draw (t,-ln(t)); scale is (20,0.1); for t from 0 to 8 step 0.1 draw(t,-exp(t)); -- CCTV origin is (1000,500); scale(100,100/3); rot is pi/2+0*pi/3; for t from -pi to pi step pi/100 draw(cos(t),sin(t)); rot is pi/2+2*pi/3; for t from -pi to pi step pi/100 draw(cos(t),sin(t)); rot is pi/2-2*pi/3; for t from -pi to pi step pi/100 draw(cos(t),sin(t)); -- 波浪 origin is (1500,500); rot is 0; scale(50,50); for t from 0 to 2*pi+pi/50 step pi/50 draw(t,sin(t)); origin is (1500,600); for t from 0 to 2*pi+pi/50 step pi/50 draw(t,sin(t)); origin is (1500,700); for t from 0 to 2*pi+pi/50 step pi/50 draw(t,sin(t)); -- 同心圆 origin is (1350, 220); scale is (50, 50); for t from 0 to 2*pi step pi/100 draw(cos(t), sin(t)); scale is (100, 100); for t from 0 to 2*pi step pi/200 draw(cos(t), sin(t)); -- 呼啦圈 origin is (500,900); scale(100,100); rot is 0; for t from 0 to 2*pi step pi/100 draw(cos(t),sin(t)); for t from 0 to pi*20 step pi/100 draw( ( (1-1/(10/7) )*cos(t) + 1/(10/7)*cos( -t*((10/7)-1)) ) ,((1-1/(10/7))*sin(t)+1/(10/7)*sin(-t*((10/7)-1))) ); ``` ## 2.在根目录下创建`index.js` 配置options对象 * `__dirname` Node.js预置变量,表示当前目录 * `fileUrl` 输入绘图程序文件 * `img` {Object} * `url` 输出绘图结果文件 * `width` 绘图输出文件宽度 * `height` 绘图输出文件高度 * `lexLog` 如果有,则会在此目录下生成`词法分析`日志文件 * `parseLog` 如果有,则会在此目录下生成`语法分析`日志文件 ``` var Compilers = require('compilers'); var options = { fileUrl: __dirname+'/input/demo.txt', //必须 img: { url: __dirname, //必须 width: 2000, //必须 height: 2000, //必须 lexLog:__dirname, //可选 parseLog:__dirname // 可选 } }; Compilers.handle(options); ``` ## 3. 运行 ``` node index.js ``` (^▽^)コ祝贺你 ![](http://7xlqsb.com1.z0.glb.clouddn.com/result.png)