Hi Everyone + doubt

View: New views
6 Messages — Rating Filter:   Alert me  

Hi Everyone + doubt

by Rodrigo Garcia-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I 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 + doubt

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi 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

signature.asc (265 bytes) Download Attachment

Parent Message unknown Re: Hi Everyone + doubt

by Rodrigo Garcia-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Etienne, thanks for replying and helping out.

If still concerned you didn't solved my homework. I would never ask for solutions.
Just for guidance. I'll go to the grammar section of sable's site.

Thanks a lot, I'll keep searching.

I'm having a problem with some substitutions made by sablecc because I define:

all = [0 .. 0xffff]

and when I'm trying to do the regex for multiple line comments I have to
put it like this:

multiline_comment = '/*' '*'* ([[0 .. 0xffff] - ['/' + '*']] [[0 .. 0xffff]
-'*']* '*'*)* '*/';

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.

Any further information?

Thanks for your time,
Rodrigo Garcia.

>Hi 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 + doubt

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi 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.
>  
I tested the attached grammar. SableCC does not complain (I tested with
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

signature.asc (265 bytes) Download Attachment

Parent Message unknown RE: Hi Everyone + doubt

by Rodrigo Garcia-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Etienne,

You were completely right, there was no error. I don't know what could have
happened. I've fixed that now. And I do think it stands for multi-line comment
since I've tested it out with this example
/*Line 1
*Line 2
*Line 3*/

Output:

token /*Line 1
*Line 2
*Line 3*/ belongs to lexico.node.TMultilineComment

:)


Nice syntax for the next sable version.

Remember the grammar you told me to check?

integer_literal =  decimal_numeral integer_type_suffix?
non_zero_digit = ['1'..'9'];
digit = ['0'..'9'];
decimal_numeral = '0' | non_zero_digit digit*;
integer_type_suffix = 'l' | 'L';

Where is it stated the size of the number in bits? Where do I state my biggest
number? Or should I define

Positive_numbers = ['0' .. '2147483647' ];
negatives = ['1' .. '2147483648' ];
Negative_numbers = '-' negatives;

This to tell that I want a 32 bit signed number. Although it looks dirty,
I didn't see the place where the definition of the size takes place

Thanks,

Rodrigo Garcia



-----Original Message-----
From: sablecc-discussion-bounces+a00995205=itesm.mx@... [mailto:sablecc-discussion-bounces+a00995205=itesm.mx@...]
On Behalf Of Etienne M. Gagnon
Sent: Sunday, June 08, 2008 9:12 PM
To: Discussion mailing list for the SableCC project
Subject: Re: Hi Everyone + doubt

Hi 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.
>  

I tested the attached grammar. SableCC does not complain (I tested with 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


No virus found in this incoming message.
Checked by AVG.
Version: 8.0.100 / Virus Database: 270.0.0/1489 - Release Date: 6/7/2008
11:17 AM


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: Hi Everyone + doubt

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

signature.asc (265 bytes) Download Attachment
LightInTheBox - Buy quality products at wholesale price