Parser Generator Tips翻译(中英对译) by Joshua Xu

You can use the ParserWizard command from the Project menu to help you create initial YACC and Lex skeleton source files.
如果需要生成初始的YACC & Lex骨架源文件,可以在系统菜单中,选取Project->ParserWizard。

Use the Parser Generator Registration command from the Tools menu to register your copy of Parser Generator at the appropriate time.
如果需要注册软件,可以在系统菜单中,选取Tools->Parser Generator Registration。

AYACC and ALex are suited for integration into the Visual C++ development environment.  In particular the error messages generated by the two tools are compatible with those recognised by Visual C++.  This means that error mapping from the Output window to the relevant YACC or Lex source file can take place.
AYACC和ALex适合集成到VC++开发环境里面。这两个工具生成的错误信息(error message)是VC++兼容的。
这意味着可以根据VC的输出窗口(output window)里面的错误信息追溯到对应的YACC或Lex源文件。

AYACC and ALex both generate verbose files (.v extension).  These show exactly how the generated parser and lexical analyser will behave in any given circumstances.  If you not sure that your parser or lexical analyser is working correctly, then it is a good idea to look at these at some point.
AYACC和Alex都生成.v文件(verbose)。 这些verbose文件精确地显示了parser和lexical analyser在特定环境中的行为。
如果你无法确定一个语法分析器(parser)或词法分析器(lexical analyser)能否正常工作,有个好主意是先检查verbose文件。

If you are generating multiple model C or C++ and Java parsers and lexical analysers then you will need to give the parser or lexical analyser a name.  This can be done with a Name declaration.  This is introduced with the %name keyword and has a trailing identifier.  For example, %name myparser.
如果生成了多个C/C++/Java语法分析器(Parser)和词法分析器(lexical analyser),那么必须要给它们起个名字。
声明一个变量即可:关键字是%name,后面跟一个标识符。例如:%name myparser。

You can place code in AYACC and ALex generated include files by using an Include Declaration.  These are introduced with the %include keyword and have a trailing declaration code block {...}.  For example, %include { /* a comment */ }.
你可以将需要的代码放入AYACC和ALex生成的include文件中。
关键字是%include,后面跟一个代码块。
例如:%include { /* a comment */ }.

You can now associate destructor actions with symbols in YACC source files.  These will be called whenever the symbol is popped off of the stack, or the lookahead token is discarded, during error recovery.  This is particular handy if the symbol contains allocated memory which would otherwise be lost.
你可以在YACC源文件中将符号(symbol)与析构动作(destructor action)关联起来。
当错误恢复时,这个symbol会被弹出栈顶,或前瞻令牌(lookahead token)被抛弃;此时会执行对应的destructor action。
当某个symbol包含分配内存(new byte[])的动作时,关联析构动作至为方便(这样可以在析构时delete[]内存)。
否则那部分内存就被丢失了。

It is possible for the lexical analyser to get input from elsewhere other than the yyin stream. In order to do this you need to redefine the yygetchar function in your Lex source file.  Note that this applies to single model C lexical analysers, although it is similar for other types as well (yygetchar member for C++ etc).
对一个词法分析器(lexical analyser)而言,除了yyin流,还可以有其它方式获得输入(input)。
如何做到?只需要在lex源文件中,重定义yygetchar函数。

You can change characters in a regular expression to equivalent characters in another code page by using the Code Page Statement.  This has a number of different forms such as: %codepage_ansi, %codepage_oem, %codepage_ascii and %codepage n, where n specifies the code page i.e. 932.
用Code Page语句,可以将某个正则表达式中的字符,改变为另一个代码页(codepage)的同等字符。
这包括一系列语句,比如
%codepage_ansi,
%codepage_oem,
%codepage_ascii,
%codepage n(n代表特定的代码页,比如932)

You can disable and enable trailing break statement generation in Lex actions by using an Action Terminator Statement.  The %break keyword specifies that break statements will be generated and the %return statement specifies that they wont.  This is particularly useful when generating Java code.
使用Action Terminator Statement,可以enable或disable 尾部break语句。关键字%break规定,一定会生成break语句,而%return规定一定不会。 这在生成Java代码的时候特别有用。
(这里翻译得很难懂,原因是我不懂这一块的技术。等我了解多一些知识再来修改)

猜你喜欢

转载自www.cnblogs.com/presbyter/p/10358166.html