解决CSharpGL使用CGCompiler时发现的几个问题

解决CSharpGL使用CGCompiler时发现的几个问题

为了获取CSharpShadingLanguage的token流,我设计了这样一个文法:

<Expression> ::= "~" "!" "@" "#" "%" "^" "&" "*" "(" ")" "-" "+" "=" "{" "}" "[" "]" ":" ";" "<" ">" "," "." "?" "/" "~=" "!=" "%=" "^=" "&=" "*=" "-=" "+=" "<=" ">=" "/=" "&&" "++" "<<" ">>" constString identifier number;

这当然不能进行语法分析,但是足以进行词法分析。

在使用过程中发现CGCompiler有几个bug,在此记录并fix掉。

重复的token类型

文法中有identifier时,TokenType的枚举类型里会出现重复的identifier。

此问题已解决(大概吧)。只需在ContextfreeGrammarEnumTokenTypeSG.cs中加入如下判定。

GetCharType()没有判定@符号

此问题已解决。在ContextfreeGrammarLexicalAnalyzerSG.cs的GenerateLexicalAnalyzerMethodGetCharType()方法中加入3行固定代码即可。出现此问题是因为我以前漏掉了对@这个符号的解析。

GetDivideOpt()没有判定跳过单行注释

已解决。只需在ContextfreeGrammarLexicalAnalyzerSG.cs文件中补充如下代码即可。

原文地址:https://www.cnblogs.com/bitzhuwei/p/CGCompiler-fix.html