我似乎遇到了SableCC生成相關詞法分析器,節點和解析通常從語法文件自動生成的東西的問題。我目前沒有實現抽象語法樹。SableCC語法文件的問題
當我嘗試與下面的語法文件運行SableCC,我得到以下錯誤:
[41,33] AFunctionHead.Id的重新定義。我知道這個問題是什麼,但它似乎是生產領域的東西。我可能錯過了什麼?
Package Grammar_Specification;
Helpers
digit = ['0'..'9'];
letter = (['a'..'z'] | ['A'..'Z']);
underscore = '_';
plus = '+';
minus = '-';
mult = '*';
div = '/';
equals = '=';
l_par = '(';
r_par = ')';
l_curly = '{';
r_curly = '}';
unicode_input_character = [0..0xffff];
lf = 0x000a;
cr = 0x000d;
line_terminator = lf | cr | cr lf;
input_character = [unicode_input_character - [cr + lf]];
not_star = [input_character - '*'] | line_terminator;
not_star_not_slash = [input_character - ['*' + '/']] | line_terminator;
multi_line_comment = '/*' not_star+ '*'+ (not_star_not_slash not_star* '*'+)* '/';
line_comment = '//' input_character* line_terminator?;
Tokens
func = 'FUNC';
id = (letter(letter | digit | underscore)* | underscore(letter | digit | underscore)*);
float_literal = minus? digit (digit)* ('.' (digit)*)? (('e' | 'E') (plus | minus)? digit (digit)*)?;
whitespace = (' ' | '\t' | '\n' | '\r')+;
comment = multi_line_comment | line_comment;
Productions
program = function_decl*statement*;
function_decl = function_head function_body;
function_head = func id l_par id r_par;
function_body = l_curly statement* r_curly;
statement = id equals expression;
expression = expression plus term |
expression minus term |
term;
term = term mult factor |
term div factor |
factor;
factor = l_par expression r_par |
identifier l_par expression r_par |
float_literal |
id;
非常感謝:)我認爲我設法理清的問題:d – Curiosity 2014-09-10 19:06:01