[ 2005/09/20 07:40 | by turbozv ]
News from http://www.freepascal.org/
引用
--------------------------------------------------------------------------------
August 22, 2005 The ARM port of Free Pascal can now be used to develop games for the Gameboy Advance.
--------------------------------------------------------------------------------
For details: http://fpc4gba.pascalgamedevelopment.com/
引用
--------------------------------------------------------------------------------
August 22, 2005 The ARM port of Free Pascal can now be used to develop games for the Gameboy Advance.
--------------------------------------------------------------------------------
For details: http://fpc4gba.pascalgamedevelopment.com/
[ 2005/09/19 08:39 | by turbozv ]
1)支持文法格式有: ''?' 0个或者1个, +' 1个或多个, '*' 0个或者多个, '|' 并列选择结构. '' 空串, 'A' 单个字符, \"string\" 字符串
2)自动展开文法,自动合并相同文法项
3)生成单一一个ANSI C的标准c文件,任何编译器均可以编译通过
TODO:
1)支持ASCII的字符,比如 '\n', \"hello\250\"
2)支持字符的范围格式,比如'0'-'9'
3)需要把空串文法放在并列选择的最后,比如 A : | B ; 应该调整为 A : B | ;
源程序: http://down.turbozv.com/PIG/PIG.dpr (Delphi 7.0编译通过)
还是举个例子吧,输入exp.txt
===============exp.txt=============
exp : [ '+' | '-' ] ? term [ [ '+' | '-' ] term ] * ;
term : factor [ [ '*' | '/' ] factor ] * ;
factor : uint | '(' exp ')' ;
uint : number + ;
number : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;
=================================
输出exp.c
/* Generated by PIG version 1.0 (turbozv@uestc.edu.cn)
$Id: PIG.dpr,v 1.4 2005/09/19 17:15:51 ZV Exp $
DateTime: 2005-9-20 15:23:21
===================== Orignal Rules ===================
1) exp : [ '+' | '-' ] ? term [ [ '+' | '-' ] term ] * ;
2) term : factor [ [ '*' | '/' ] factor ] * ;
3) factor : uint | '(' exp ')' ;
4) uint : number + ;
5) number : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;
===================Processed to Rules==================
1) exp : exp_1 ? term exp_2 * ;
2) term : factor term_1 * ;
3) factor : uint | '(' exp ')' ;
4) uint : number + ;
5) number : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;
6) exp_1 : '+' | '-' ;
7) exp_2 : exp_1 term ;
8) term_1 : term_2 factor ;
9) term_2 : '*' | '/' ;
*/
#include <stdio.h>
typedef void Parser;
static int is_exp(Parser * pVar, char *buf);
static int is_term(Parser * pVar, char *buf);
static int is_factor(Parser * pVar, char *buf);
static int is_uint(Parser * pVar, char *buf);
static int is_number(Parser * pVar, char *buf);
static int is_exp_1(Parser * pVar, char *buf);
static int is_exp_2(Parser * pVar, char *buf);
static int is_term_1(Parser * pVar, char *buf);
static int is_term_2(Parser * pVar, char *buf);
/* 1) exp : exp_1 ? term exp_2 * ; */
static int is_exp(Parser * pVar, char *buf)
{
int ret, sum = 0;
// exp_1 ?
if (-1 != (ret = is_exp_1(pVar, buf))) {
sum += ret;
buf += ret;
}
// term
if (-1 == (ret = is_term(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// exp_2 *
while (-1 != (ret = is_exp_2(pVar, buf))) {
sum += ret;
buf += ret;
}
return sum;
}
/* 2) term : factor term_1 * ; */
static int is_term(Parser * pVar, char *buf)
{
int ret, sum = 0;
// factor
if (-1 == (ret = is_factor(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// term_1 *
while (-1 != (ret = is_term_1(pVar, buf))) {
sum += ret;
buf += ret;
}
return sum;
}
/* 3) factor : uint | '(' exp ')' ; */
static int is_factor(Parser * pVar, char *buf)
{
int ret, sum = 0;
// uint
if (-1 != (ret = is_uint(pVar, buf))) {
sum += ret;
buf += ret;
return sum;
}
// '('
if ('(' != *buf)
return -1;
sum++;
buf++;
// exp
if (-1 == (ret = is_exp(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// ')'
if (')' != *buf)
return -1;
sum++;
buf++;
return sum;
}
/* 4) uint : number + ; */
static int is_uint(Parser * pVar, char *buf)
{
int ret, sum = 0;
// number +
if (-1 == (ret = is_number(pVar, buf)))
return -1;
do {
sum += ret;
buf += ret;
} while (-1 != (ret = is_number(pVar, buf)));
return sum;
}
/* 5) number : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ; */
static int is_number(Parser * pVar, char *buf)
{
int sum = 0;
// '0'
if ('0' == *buf) {
sum++;
buf++;
return sum;
}
// '1'
if ('1' == *buf) {
sum++;
buf++;
return sum;
}
// '2'
if ('2' == *buf) {
sum++;
buf++;
return sum;
}
// '3'
if ('3' == *buf) {
sum++;
buf++;
return sum;
}
// '4'
if ('4' == *buf) {
sum++;
buf++;
return sum;
}
// '5'
if ('5' == *buf) {
sum++;
buf++;
return sum;
}
// '6'
if ('6' == *buf) {
sum++;
buf++;
return sum;
}
// '7'
if ('7' == *buf) {
sum++;
buf++;
return sum;
}
// '8'
if ('8' == *buf) {
sum++;
buf++;
return sum;
}
// '9'
if ('9' != *buf)
return -1;
sum++;
buf++;
return sum;
}
/* 6) exp_1 : '+' | '-' ; */
static int is_exp_1(Parser * pVar, char *buf)
{
int sum = 0;
// '+'
if ('+' == *buf) {
sum++;
buf++;
return sum;
}
// '-'
if ('-' != *buf)
return -1;
sum++;
buf++;
return sum;
}
/* 7) exp_2 : exp_1 term ; */
static int is_exp_2(Parser * pVar, char *buf)
{
int ret, sum = 0;
// exp_1
if (-1 == (ret = is_exp_1(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// term
if (-1 == (ret = is_term(pVar, buf)))
return -1;
sum += ret;
buf += ret;
return sum;
}
/* 8) term_1 : term_2 factor ; */
static int is_term_1(Parser * pVar, char *buf)
{
int ret, sum = 0;
// term_2
if (-1 == (ret = is_term_2(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// factor
if (-1 == (ret = is_factor(pVar, buf)))
return -1;
sum += ret;
buf += ret;
return sum;
}
/* 9) term_2 : '*' | '/' ; */
static int is_term_2(Parser * pVar, char *buf)
{
int sum = 0;
// '*'
if ('*' == *buf) {
sum++;
buf++;
return sum;
}
// '/'
if ('/' != *buf)
return -1;
sum++;
buf++;
return sum;
}
void main()
{
}
2)自动展开文法,自动合并相同文法项
3)生成单一一个ANSI C的标准c文件,任何编译器均可以编译通过
TODO:
1)支持ASCII的字符,比如 '\n', \"hello\250\"
2)支持字符的范围格式,比如'0'-'9'
3)需要把空串文法放在并列选择的最后,比如 A : | B ; 应该调整为 A : B | ;
源程序: http://down.turbozv.com/PIG/PIG.dpr (Delphi 7.0编译通过)
还是举个例子吧,输入exp.txt
===============exp.txt=============
exp : [ '+' | '-' ] ? term [ [ '+' | '-' ] term ] * ;
term : factor [ [ '*' | '/' ] factor ] * ;
factor : uint | '(' exp ')' ;
uint : number + ;
number : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;
=================================
输出exp.c
/* Generated by PIG version 1.0 (turbozv@uestc.edu.cn)
$Id: PIG.dpr,v 1.4 2005/09/19 17:15:51 ZV Exp $
DateTime: 2005-9-20 15:23:21
===================== Orignal Rules ===================
1) exp : [ '+' | '-' ] ? term [ [ '+' | '-' ] term ] * ;
2) term : factor [ [ '*' | '/' ] factor ] * ;
3) factor : uint | '(' exp ')' ;
4) uint : number + ;
5) number : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;
===================Processed to Rules==================
1) exp : exp_1 ? term exp_2 * ;
2) term : factor term_1 * ;
3) factor : uint | '(' exp ')' ;
4) uint : number + ;
5) number : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;
6) exp_1 : '+' | '-' ;
7) exp_2 : exp_1 term ;
8) term_1 : term_2 factor ;
9) term_2 : '*' | '/' ;
*/
#include <stdio.h>
typedef void Parser;
static int is_exp(Parser * pVar, char *buf);
static int is_term(Parser * pVar, char *buf);
static int is_factor(Parser * pVar, char *buf);
static int is_uint(Parser * pVar, char *buf);
static int is_number(Parser * pVar, char *buf);
static int is_exp_1(Parser * pVar, char *buf);
static int is_exp_2(Parser * pVar, char *buf);
static int is_term_1(Parser * pVar, char *buf);
static int is_term_2(Parser * pVar, char *buf);
/* 1) exp : exp_1 ? term exp_2 * ; */
static int is_exp(Parser * pVar, char *buf)
{
int ret, sum = 0;
// exp_1 ?
if (-1 != (ret = is_exp_1(pVar, buf))) {
sum += ret;
buf += ret;
}
// term
if (-1 == (ret = is_term(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// exp_2 *
while (-1 != (ret = is_exp_2(pVar, buf))) {
sum += ret;
buf += ret;
}
return sum;
}
/* 2) term : factor term_1 * ; */
static int is_term(Parser * pVar, char *buf)
{
int ret, sum = 0;
// factor
if (-1 == (ret = is_factor(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// term_1 *
while (-1 != (ret = is_term_1(pVar, buf))) {
sum += ret;
buf += ret;
}
return sum;
}
/* 3) factor : uint | '(' exp ')' ; */
static int is_factor(Parser * pVar, char *buf)
{
int ret, sum = 0;
// uint
if (-1 != (ret = is_uint(pVar, buf))) {
sum += ret;
buf += ret;
return sum;
}
// '('
if ('(' != *buf)
return -1;
sum++;
buf++;
// exp
if (-1 == (ret = is_exp(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// ')'
if (')' != *buf)
return -1;
sum++;
buf++;
return sum;
}
/* 4) uint : number + ; */
static int is_uint(Parser * pVar, char *buf)
{
int ret, sum = 0;
// number +
if (-1 == (ret = is_number(pVar, buf)))
return -1;
do {
sum += ret;
buf += ret;
} while (-1 != (ret = is_number(pVar, buf)));
return sum;
}
/* 5) number : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ; */
static int is_number(Parser * pVar, char *buf)
{
int sum = 0;
// '0'
if ('0' == *buf) {
sum++;
buf++;
return sum;
}
// '1'
if ('1' == *buf) {
sum++;
buf++;
return sum;
}
// '2'
if ('2' == *buf) {
sum++;
buf++;
return sum;
}
// '3'
if ('3' == *buf) {
sum++;
buf++;
return sum;
}
// '4'
if ('4' == *buf) {
sum++;
buf++;
return sum;
}
// '5'
if ('5' == *buf) {
sum++;
buf++;
return sum;
}
// '6'
if ('6' == *buf) {
sum++;
buf++;
return sum;
}
// '7'
if ('7' == *buf) {
sum++;
buf++;
return sum;
}
// '8'
if ('8' == *buf) {
sum++;
buf++;
return sum;
}
// '9'
if ('9' != *buf)
return -1;
sum++;
buf++;
return sum;
}
/* 6) exp_1 : '+' | '-' ; */
static int is_exp_1(Parser * pVar, char *buf)
{
int sum = 0;
// '+'
if ('+' == *buf) {
sum++;
buf++;
return sum;
}
// '-'
if ('-' != *buf)
return -1;
sum++;
buf++;
return sum;
}
/* 7) exp_2 : exp_1 term ; */
static int is_exp_2(Parser * pVar, char *buf)
{
int ret, sum = 0;
// exp_1
if (-1 == (ret = is_exp_1(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// term
if (-1 == (ret = is_term(pVar, buf)))
return -1;
sum += ret;
buf += ret;
return sum;
}
/* 8) term_1 : term_2 factor ; */
static int is_term_1(Parser * pVar, char *buf)
{
int ret, sum = 0;
// term_2
if (-1 == (ret = is_term_2(pVar, buf)))
return -1;
sum += ret;
buf += ret;
// factor
if (-1 == (ret = is_factor(pVar, buf)))
return -1;
sum += ret;
buf += ret;
return sum;
}
/* 9) term_2 : '*' | '/' ; */
static int is_term_2(Parser * pVar, char *buf)
{
int sum = 0;
// '*'
if ('*' == *buf) {
sum++;
buf++;
return sum;
}
// '/'
if ('/' != *buf)
return -1;
sum++;
buf++;
return sum;
}
void main()
{
}
[ 2005/09/18 08:58 | by turbozv ]
Q: What is PIG?
A: PIG is the short form of Parser Interface Generator. It turns the grammar and token scripts to a Parser.C file which can interpret the just language.
Q: Why made another YACC/LEX?
A: Because I find YACC/LEX is too difficult to learn (maybe only for me), and I also want to practice in such field. By the way, my recent work is related to it.
Q: What language do you want to use to implement PIG?
A: I want to use Delphi (Pascal) first, because it's my favorite language. Then, I'd like to port it to Python, and then C/C++ for wilder support.
Q: What’s the plan, when can the first version be released?
A: As I said, I am now using Delphi7.0. Well, the first version may be released in a week or less, because my work needs a common CSS2-parser very soon. In the following week, I will do PIG full-time. lol
Q:How can I contact with you?
A:Many ways, but I think email is best. Email me at: turbozv_AT_uestc_DOT_edu_DOT_cn
A: PIG is the short form of Parser Interface Generator. It turns the grammar and token scripts to a Parser.C file which can interpret the just language.
Q: Why made another YACC/LEX?
A: Because I find YACC/LEX is too difficult to learn (maybe only for me), and I also want to practice in such field. By the way, my recent work is related to it.
Q: What language do you want to use to implement PIG?
A: I want to use Delphi (Pascal) first, because it's my favorite language. Then, I'd like to port it to Python, and then C/C++ for wilder support.
Q: What’s the plan, when can the first version be released?
A: As I said, I am now using Delphi7.0. Well, the first version may be released in a week or less, because my work needs a common CSS2-parser very soon. In the following week, I will do PIG full-time. lol
Q:How can I contact with you?
A:Many ways, but I think email is best. Email me at: turbozv_AT_uestc_DOT_edu_DOT_cn
[ 2005/09/17 08:59 | by turbozv ]
掌心万年历 1.2 QVGA:http://www.onlinedown.net/soft/38528.htm
掌心万年历 1.2 VGA:http://www.onlinedown.net/soft/42306.htm
掌心万年历 1.2 VGA:http://www.onlinedown.net/soft/42306.htm