FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TryCtachStatement EBNF

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
BLS



Joined: 28 Mar 2006
Posts: 44
Location: France

PostPosted: Wed Aug 22, 2007 12:12 pm    Post subject: TryCtachStatement EBNF Reply with quote

Hi ,
Code:

TryCatchStatement:
   'try' Statement (('catch' '(' Identifier ')' Statement) || ('finally' Statement))


I have problems to understand the || in front of finally. What does it mean ?

I have to use the following Grammar rules :

WhileStatement nonterminal
( expression )* repeat expression zero or more time
( expression )+ repeat expression one or more time
[ expression ] expression once or not at all
"if" value of token (regardless of token type)
<identifier> type of token (regardless of token value)
<keyword,"if"> token type and value


FOR EXAMPLE SWITCH CASE :
Code:

SwitchStatement = "switch" "(" Expression ")" "{" (CaseClause)* [DefaultClause] (CaseClause)* "}";
CaseClause = "case" Expression ("," Expression)* ":" (Statement)*;
DefaultClause = "default" ":" (Statement)*;


So my current TryCatchStatement looks like :
Code:

TryCatchStatement = "try" Block [Catch] [Finally];
Catch = "catch" "(" <md_identifier> ")" Block;
Finally = "finally" Block;


But I am pretty sure this a mess Embarassed

Later, Next Try, probabely better :

Code:

TryCatchStatement =
    "try" Block "catch" "(" <md_identifier> ")" Block "finally" Block |
    "try" Block "finally" Block;       



Any ideas ? Thanks in advance. Bjoern
Beside Grammar rules for the Netbeans Generic language framework at:
http://wiki.netbeans.org/wiki/view/SchliemannNBSLanguageDescription
Back to top
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Wed Aug 22, 2007 2:41 pm    Post subject: Reply with quote

The || is an OR, but the actual rule is one optional Catch and one optional Finally. So I think your current one is actually correct. Smile
_________________
Chris Nicholson-Sauls
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Wed Aug 22, 2007 3:00 pm    Post subject: Reply with quote

I don't profess to be an expert on EBNF so in some cases I've .. come up with my own symbols. It's OR, but an inclusive OR. That is, whereas (a | b) is exclusive, meaning a or b but not both, (a || b) means, a, b, or a followed by b.

Mostly it was so I didn't have to write the rule as:

TryCatchStatement:
try ... catch ...
try ... finally ...
try ... catch ... finally ...

Also, your grammar for switch is a bit wrong - [DefaultClause] should be the last item inside the switch; you can't have cases after the default, and there needs to be at least one case. So it'd look more like "{" (CaseClause)+ [DefaultClause] "}".
Back to top
View user's profile Send private message
BLS



Joined: 28 Mar 2006
Posts: 44
Location: France

PostPosted: Thu Aug 23, 2007 3:27 am    Post subject: Switch-Case/ Try-Catch Reply with quote

Thanks Jarret, Thanks Chris,

(CaseStatement)+ means : repeat expression one or more time
Code:

#SWITCH-CASE STATEMENT

SwitchStatement =
    "switch" "(" Expression ")" "{" (CaseStatement)+ [DefaultStatement] "}";
CaseStatement =
    "case" Expression ("," Expression)* ":" (Statement)*;
DefaultStatement =
    "default" ":" (Statement)*;

#TRY-CATCH STATEMENT

TryCatchStatement =
    "try" Statement "catch" Statement |
    "try" Statement "finally" Statement |       
    "try" Statement "catch" "(" <md_identifier> ")" Statement "finally" Statement;


I hope now it's correct. Or ?

Thanks in advance, Bjoern
Not nessesary to say that I am a MiniD noob and NOT an EBNF expert Sad
Back to top
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Thu Aug 23, 2007 6:13 am    Post subject: Reply with quote

Code:
"try" Statement "catch" Statement |


should be

Code:
"try" Statement "catch" "(" <md_identifier> ")" Statement |
Back to top
View user's profile Send private message
BLS



Joined: 28 Mar 2006
Posts: 44
Location: France

PostPosted: Thu Aug 23, 2007 6:43 am    Post subject: Reply with quote

JarrettBillingsley wrote:
Code:
"try" Statement "catch" Statement |


should be

Code:
"try" Statement "catch" "(" <md_identifier> ")" Statement |


I am such an idiot...........
Regards, Bjoern
Back to top
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Thu Aug 23, 2007 9:02 am    Post subject: Reply with quote

Nu-uh!
Back to top
View user's profile Send private message
BLS



Joined: 28 Mar 2006
Posts: 44
Location: France

PostPosted: Thu Aug 23, 2007 12:32 pm    Post subject: MiniD Grammar Reply with quote

Hi, just to keep you informed...
The Grammar Description is done. What remains is to transform

Code:

IntLiteral:
   Decimal
   Binary
   Octal
   Hexadecimal


into regular expressions.. quit straightforward so far ...

just JavaScript as example :
TOKEN:js_number: (
    ["0"-"9"] ['l' 'L']? |
    ["1"-"9"] ["0"-"9"]* ['l' 'L']? |
    "0" ["0"-"7"]+ ['l' 'L']? |
    "0" ["x" "X"] ["0"-"9" "a"-"f" "A"-"F"]+ ['l' 'L']? |
    ["0"-"9"]+ "." ["0"-"9"]* (["e" "E"] ["+" "-"]? ["0"-"9"]+)? ["f" "F" "d" "D"]? |
    "." ["0"-"9"]+ (["e" "E"] ["+" "-"]? ["0"-"9"]+)? ["f" "F" "d" "D"]? |
    ["0"-"9"]+ ["e" "E"] ["+" "-"]? ["0"-"9"]+ ["f" "F" "d" "D"]? |
    ["0"-"9"]+ (["e" "E"] ["+" "-"]? ["0"-"9"]+)? ["f" "F" "d" "D"]
)



The most complicated (I think impossible) thing is to describe nested comments as regular expression.
Regards Bjoern
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group