1. 程式人生 > >Parser Generator Tips翻譯(中英對譯) by Joshua Xu

Parser Generator Tips翻譯(中英對譯) by Joshua Xu

multi parse num vc++ 源文件 int 文件 point ascii

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代碼的時候特別有用。
(這裏翻譯得很難懂,原因是我不懂這一塊的技術。等我了解多一些知識再來修改)

Parser Generator Tips翻譯(中英對譯) by Joshua Xu