Antlr

warning: Creating default object from empty value in /srv/www/blog.sqlitedeveloper.com/www/modules/i18n/i18ntaxonomy/i18ntaxonomy.pages.inc on line 34.

在DLL中使用Antlr

.-noscript-blocked { border: 1px solid red !important; background: white url("chrome://noscript/skin/icon32.png") no-repeat left top !important; opacity: 0.6 !important; }

新建一个Win32 DLL项目,设置如下

如何include预编译头文件到antlr生成的cpp中

在Antlr生成cpp文件时,我们可能希望添加预编译头文件StdAfx.h到cpp文件中,标准的Header开关只能把头文件include到生成的头文件,而不能是cpp文件。

要想添加头文件到cpp中,需要使用antlr cpp生成器特殊控制开关关键字pre_include_cpp,示意如下
header "pre_include_cpp" {
#include "StdAfx.h"
}

anltr中如何声明变量

.-noscript-blocked { border: 1px solid red !important; background: white url("chrome://noscript/skin/icon32.png") no-repeat left top !important; opacity: 0.6 !important; }

column_ref_2[string& szTableName, string& szColumnName]
{
string s1,s2,s3, s4="";
}
:

c:id { s1=#c->getText();}
(PERIOD c1:id { s2=#c1->getText();}
(PERIOD c2:id { s3=#c2->getText();}
(PERIOD c3:id { s4=#c3->getText();}
)?)?)?
{
if (s2=="")
{

Antlr eclipse plugin

.-noscript-blocked { border: 1px solid red !important; background: white url("chrome://noscript/skin/icon32.png") no-repeat left top !important; opacity: 0.6 !important; }

Antlr的Unicode支持

.-noscript-blocked { border: 1px solid red !important; background: white url("chrome://noscript/skin/icon32.png") no-repeat left top !important; opacity: 0.6 !important; }

Antlr从2.72起开始提供了完善的Unicode支持,首先设置charVocabulary选项,指定Unicode范围,注意antlr不支持\uFFFF,因为这个值对应于-1,被antlr用来标示结尾字符了。

Antlr语法文件的一些常用配置选项

.-noscript-blocked { border: 1px solid red !important; background: white url("chrome://noscript/skin/icon32.png") no-repeat left top !important; opacity: 0.6 !important; }

  • 要想在生成的cpp代码中添加一些预定义的头文件,可以使用Header语法定义,示意如下

header {
#include <iostream> // if you want to use some cout's in the actions
ANTLR_USING_NAMESPACE(std)
ANTLR_USING_NAMESPACE(antlr)

// Global header ends here
}

antlr之Hello World

最近要写一个SQL的Parser,因此需要一个Parser代码生成器,以前用过Lex 和 Yacc,但是缺点是生成的代码可读性非常差,而且生成的都是C的代码,重用性不好,所以这次准备用Antlr来实现.

* 首先下载antlr2.75,安装运行
* 然后安装JRE1.42
* 然后添加classpath c:\antlr\275\bin
* 编写一个简单的test.g

class P extends Parser;

startRule
: n:NAME
{printf("name:%s ", n->toString().c_str());}
;

class L extends Lexer;

// one-or-more letters followed by a newline
NAME: ( 'a'..'z'|'A'..'Z' )+ NEWLINE
;

NEWLINE
: '\r' '\n' // DOS
| '\n' // UNIX
;

* 运行命令java antlr.Tool test.g 将生成parser的java代码
* 要生成cpp的代码只要在test.g文件中添加一个选项就可以了
options {

同步内容