SableCC EBNF compiler-compiler problem
Hej eksperter,jeg leger med et program til at generere compilere med kaldet SableCC. Det benytter en EBNF lignende syntax.
Jeg vil have lexeren og parseren til at genkende noget allá (problemet ligger i Productions-delen):
/*********************************************************
Config {
start (Classname, funcname):
dependencies {
define (ClassA):
define (ClassB):
define (ClassC):
}
options {
optimization (cpu):
}
}
*********************************************************/
Har indtil videre lavet følgende:
Helpers
ht = 0x09; lf = 0x0a; ff = 0x0c; cr = 0x0d; sp = 0x20;
line_terminator = (lf | cr | cr lf);
ascii_character = [0..0xff];
not_star = [ascii_character - '*'];
not_star_slash = [not_star - '/'];
ascii_caps = ['A'..'Z'];
ascii_small = ['a'..'z'];
digit = ['0'..'9'];
Tokens
l_brace = '{';
r_brace = '}';
l_parenthese = '(';
r_parenthese = ')';
colon = ':';
comma = ',';
config = 'Config';
start = 'start';
object = ascii_caps (ascii_small | ascii_caps)*;
function = ascii_small (ascii_small | ascii_caps)*;
dependencies = 'dependencies';
define = 'define';
options = 'options';
directive = ascii_small (ascii_small | ascii_caps)*;
value = (digit '.' digit digit) | ascii_small+;
whitespace = (sp | ht | ff | line_terminator)*;
comment = '/*' not_star* '*'+ (not_star_slash not_star* '*'+)* '/';
Ignored Tokens
whitespace,
comment;
Productions
ast = config l_brace p_config* r_brace;
p_config =
{p_start} p_start |
{p_dependencies} p_dependencies |
{p_options} p_options;
p_start = start l_parenthese object comma function r_parenthese colon;
p_dependencies = dependencies l_brace p_define* r_brace;
p_define = define l_parenthese object r_parenthese colon;
p_options = options l_brace p_directive* r_brace;
p_directive = directive l_parenthese value r_parenthese colon;
