View previous topic :: View next topic |
Author |
Message |
BLS
Joined: 28 Mar 2006 Posts: 44 Location: France
|
Posted: Wed Aug 22, 2007 12:12 pm Post subject: TryCtachStatement EBNF |
|
|
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
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 |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Wed Aug 22, 2007 2:41 pm Post subject: |
|
|
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. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Wed Aug 22, 2007 3:00 pm Post subject: |
|
|
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 |
|
|
BLS
Joined: 28 Mar 2006 Posts: 44 Location: France
|
Posted: Thu Aug 23, 2007 3:27 am Post subject: Switch-Case/ Try-Catch |
|
|
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 |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Thu Aug 23, 2007 6:13 am Post subject: |
|
|
Code: | "try" Statement "catch" Statement | |
should be
Code: | "try" Statement "catch" "(" <md_identifier> ")" Statement | |
|
|
Back to top |
|
|
BLS
Joined: 28 Mar 2006 Posts: 44 Location: France
|
Posted: Thu Aug 23, 2007 6:43 am Post subject: |
|
|
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 |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Thu Aug 23, 2007 9:02 am Post subject: |
|
|
Nu-uh! |
|
Back to top |
|
|
BLS
Joined: 28 Mar 2006 Posts: 44 Location: France
|
Posted: Thu Aug 23, 2007 12:32 pm Post subject: MiniD Grammar |
|
|
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 |
|
|
|