[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AW: How to write SableCC Productions
Hi Bittkau,
> thank you for your help!
>
> I've tried:
>
> Helpers
> cr = 13 ;
> lf = 10 ;
> Tokens
> colon = ':' ;
> underscore = '_';
> letter = ['a'..'z'] + ['A'..'Z'];
> endofline = cr | lf | cr lf ;
>
> Productions
> il_instruction = labeltag? il_instruction_rest? eol;
> labeltag = label colon;
> label = identifier;
> il_instruction_rest =
> {il_simple_operation} il_simple_operation |
> {il_expression} il_expression;
>
> identifier = letter+; //not true, test only
> eol = endofline+;
>
> so far so good, but now I get the error:
> Verifying identifiers.
> PIlSimpleOperation and TIlSimpleOperation undefined.
Your need either a production rule, or a token called il_simple_operation.
You will also need one for il_expression. Also, you will probably find it
simpler to make identifier a token rather than a production.
You may want to ignore blank space too. Generally you can cut and paste
these rules from existing grammars. I think you want something like:
Helpers
cr = 13 ;
lf = 10 ;
tab = 9 ;
nondigit = ['_' + [['a' .. 'z'] + ['A' .. 'Z']]];
digit = ['0' .. '9'];
Tokens
colon = ':' ;
eol = cr | lf | cr lf ;
blank = ( tab | ' ' )+;
il_simple_operation = 'operation' ; // no idea why
il_expression = 'expression' ; // just made it up
// important to have this last, so 'operation' and 'expression'
// are not analysed as identifiers
identifier = nondigit (digit | nondigit)*;
Ignored Tokens
blank;
Productions
il_instruction = labeltag? il_instruction_rest? eol;
labeltag = label colon;
label = identifier;
il_instruction_rest =
{il_simple_operation} il_simple_operation |
{il_expression} il_expression;
Have you downloaded Etienne's thesis (it is at www.sablecc.org)? It
explains everything very well.
Regards,
Roger
> >
That may be, but I don't know where and how to
define. > > In the meantime I tried to convert the identifier from BNF:
> identifier ::= (letter | ('_' (letter | digit))) {['_'] (letter | digit)}
>
> would be very nice, if somebody could help me.
>
> Mit freundlichen Grüssen
> Rainer Bittkau
>
> Baumer Electric AG, Abt. Betriebsmittel
> Hummelstrasse 17
> Postfach
> CH-8501 Frauenfeld
> Tel. ++41 52 728 14 55; Fax. ++41 52 728 17 27
> mailto:rbittkau@baumerelectric.com
> http://www.baumerelectric.com
>
>
> -----Ursprüngliche Nachricht-----
> Von: Dan Sandberg [mailto:dan@siliconpoetry.com]
> Gesendet: Dienstag, 5. Juni 2001 19:18
> An: Roger Keays
> Cc: Bittkau Rainer; 'sablecc-list@sable.mcgill.ca'
> Betreff: Re: How to write SableCC Productions
>
>
> Oops. Thanks for the correction.
>
> -Dan
>
> Roger Keays wrote:
> >
> > On Tue, 5 Jun 2001, Dan Sandberg wrote:
> >
> > > Hi.
> > >
> > > You can't put alternatives in parenthesis. So:
> > > il_instruction = ( label colon ) ? ( il_simple_operation | il_expression
> > > ) ? eol ;
> > >
> > > should be
> > >
> > > il_instruction = ( label colon )? il_instruction_rest? eol;
> > > il_instruction_rest = {simple_operator} il_simple_operator |
> > > {expression} il_expression;
> > >
> >
> > Is this right? I though parantheses indicated ignored alternatives. I
> > think what Bittkau is looking for is:
> >
> > il_instruction = labelcolon? il_instruction_rest? eol;
> > labelcolol = label colon
> > il_instruction_rest = {simple_operator} il_simple_operator |
> > {expression} il_expression;
> >
> > Regards,
> >
> > Roger
> >
> > > [Alternatives need to be named, using the {name} notation]
> > >
> > > Also, I don't see where the label token was defined in the example you
> > > gave.
> > >
> > > I don't know of any tools that convert from BNF automatically.
> > >
> > > -Dan
> > >
> > > Bittkau Rainer wrote:
> > > >
> > > > I'm at the very first steps to write a compiler for the IEC 61131-3
> PLC
> > > > language.
> > > > The following BNF fragment
> > > >
> > > > il_instruction ::= [label':'][il_simple_operation | il_expression] EOL
> {EOL}
> > > >
> > > > transformed to SableCC
> > > >
> > > > Tokens
> > > > colon = ':' ;
> > > > endofline = cr | lf | cr lf;
> > > > eol = endofline+;
> > > > Productions
> > > > il_instruction = ( label colon ) ? ( il_simple_operation |
> il_expression )
> > > > ? eol ;
> > > >
> > > > Error message:
> > > > org.sablecc.sablecc.parser.ParserException: [6,36] TSemicolon TBar
> excepted.
> > > >
> > > > [6,36] is the position of the first '?'
> > > > What is wrong with it?
> > > >
> > > > Are there any tools to do the transformation? (there are about 250
> other
> > > > productions to do)
> > > >
> > > > TIA
> > > >
> > > > Mit freundlichen Grüssen
> > > > Rainer Bittkau
> > > >
> > > > Baumer Electric AG, Abt. Betriebsmittel
> > > > Hummelstrasse 17
> > > > Postfach
> > > > CH-8501 Frauenfeld
> > > > Tel. ++41 52 728 14 55; Fax. ++41 52 728 17 27
> > > > mailto:rbittkau@baumerelectric.com
> > > > http://www.baumerelectric.com
> > >
>