|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Hi Everyone + doubtI think the original wasn't accepted since it was sent from another account.
Hi everyone, My name is Rodrigo Garcia. I?m from Mexico and I?ve just enrolled a compilers course in which we?ll be seeing SableCC. I?ve read some of the thesis and just made the first part which would be the lexer. Although it seems I?m still struggling with the largest/precedence rule. I?d like to ask wether or not this regex is correct since I can?t make it to work: field_decl = type { id | id '[' int_literal ']' } + , ; As far as I know (what the required grammatic states) this is supposed to be a comma separated list or one or more { id | id '[' int_literal ']' } incidences. Is this implementation correct? How do you think is the proper manner to state that. The context in which field_decl lives is: program = class Program '{' field_decl* method_decl*'}' my sablecc implementation (valid according to sablecc, I?ll take in suggestions ) program = r_class r_program l_brace field_decl* r_brace; field_decl = type { id | id '[' int_literal ']' } + , method_decl = { type | void } id ([{ type id }+,]) block block = '{' var decl* statement+ '}' var_decl = type id+, .. As you can see field_decl and method_decl both have the "+ ," which presumable represents a comma separated list but since field_decl has it then I?m stuck. Hopefully you?ve been into this or have some pointers that can be useful. Have a good night, best regards Rodrigo Garcia _______________________________________________ SableCC-Discussion mailing list SableCC-Discussion@... http://lists.sablecc.org/listinfo/sablecc-discussion |
|
|
Re: Hi Everyone + doubtHi Rodrigo,
> field_decl = type { id | id '[' int_literal ']' } + , ; > Is it a lexical or a syntactic declaration? > As far as I know (what the required grammatic states) this is supposed to > be a comma separated list or one or more { id | id '[' int_literal ']' } > incidences. Is this implementation correct? How do you think is the proper > manner to state that. The context in which field_decl lives is: > You should definitely give a look at the grammars you will find on the site: http://sablecc.org/wiki/GrammarPage You'll find there a few examples of field declaration. Etienne PS: I just hope I haven't solved a homework of yours... Good luck with the course! -- Etienne M. Gagnon, Ph.D. SableCC: http://sablecc.org SableVM: http://sablevm.org _______________________________________________ SableCC-Discussion mailing list SableCC-Discussion@... http://lists.sablecc.org/listinfo/sablecc-discussion |
|
|
|
|
|
Re: Hi Everyone + doubtHi Rodrigo,
See blow. > I can't do this : > > multiline_comment = '/*' '*'* ([all - ['/' + '*']] [all -'*']* '*'*)* '*/'; > > > And I don't know why really. Everything seems to be OK. What I think is that > the substraction expression groupA - groupB isn't working at all when it > replaces all for it's value and the output of the console is groupA groupB > and it tells me that it expected '+' or '-' which in fact is there. > both 2.18.2 and 3.2). It does not ask for a '+' or a '-'. As to whether the regular expression you wrote matches a multiline comment, or not, I leave it to you as an exercise to determine. Hint: No, SableCC does not look buggy to me; at least, not on your example. Yep, regular expressions are tricky to write. Just to tease you.... SableCC 4 will allow you to write: multiline_comment = $shortest '/*' $any* '*/'; :-) Have fun! Etienne -- Etienne M. Gagnon, Ph.D. SableCC: http://sablecc.org SableVM: http://sablevm.org Helpers all = [0 .. 0xffff]; Tokens multiline_comment = '/*' '*'* ([all - ['/' + '*']] [all -'*']* '*'*)* '*/'; _______________________________________________ SableCC-Discussion mailing list SableCC-Discussion@... http://lists.sablecc.org/listinfo/sablecc-discussion |
|
|
|
|
|
Re: Hi Everyone + doubt
Hi Rodrigo,
You don't want to limit integer size at scanning time. Given the following code: x = 1254734;it would give you an error message such as: syntax error on number "34", was expecting a semicolon. You want to let the lexer eat the whole number, then let semantic verifications catch the error. This will allow users to get a better error message, such as: number "1254734" is too big. Have fun! Etienne Where is it stated the size of the number in bits? Where do I state my biggest number? Or should I define ... -- Etienne M. Gagnon, Ph.D. SableCC: http://sablecc.org SableVM: http://sablevm.org _______________________________________________ SableCC-Discussion mailing list SableCC-Discussion@... http://lists.sablecc.org/listinfo/sablecc-discussion |
| Free Forum Powered by Nabble | Forum Help |