[mono-vb] A patch to the labeled statement

joao.carneiro@synapsing.com.br joao.carneiro@synapsing.com.br
Wed, 28 Jul 2004 01:10:30 -0700


This is a multi-part message in MIME format.

------=_NextPart_000_0011_01C4743F.AD019420
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

It=92s a small patch to the mb-parser.jay
and some related test cases that fix a
minor problem with labeled statements.
Thanks,

Test cases:
labelA.vb,labelB.vb and labelC.vb are positive tests (should compile and =
run
without runtime error)
labelD.vb is a negative test should not compile.

Jo=E3o Carneiro.

------=_NextPart_000_0011_01C4743F.AD019420
Content-Type: application/octet-stream;
	name="label.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="label.diff"

Index: mb-parser.jay=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mcs/mbas/mb-parser.jay,v=0A=
retrieving revision 1.100=0A=
diff -u -r1.100 mb-parser.jay=0A=
--- mb-parser.jay	26 Jul 2004 15:18:51 -0000	1.100=0A=
+++ mb-parser.jay	28 Jul 2004 03:40:00 -0000=0A=
@@ -2087,9 +2087,16 @@=0A=
 		$$ =3D $2;=0A=
 	  }=0A=
 	;=0A=
+label_name
+	: identifier
+	| LITERAL_INTEGER
+	{
+		$$ =3D $1.ToString();
+	}
+	;
 =0A=
 labeled_statement=0A=
-	: identifier COLON end_of_stmt =0A=
+	: label_name COLON end_of_stmt =0A=
 	  {=0A=
 		LabeledStatement labeled =3D new LabeledStatement ((string) $1, =
lexer.Location);=0A=
 =0A=
@@ -2228,7 +2235,7 @@=0A=
 	;=0A=
 	        =0A=
 goto_statement=0A=
-	: GOTO identifier  =0A=
+	: GOTO label_name  =0A=
 	  {=0A=
 		$$ =3D new Goto (current_block, (string) $2, lexer.Location);=0A=
 	  }=0A=

------=_NextPart_000_0011_01C4743F.AD019420
Content-Type: text/plain;
	name="labelD.vb"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="labelD.vb"

' Positive Test
' Test labels in functions
''''''''''''''''''''''''''''''''''
' vbc output
''''''''''''''''''''''''''''''''''
' Should be
'Error BC30451: Name 'y' is not declared
'Error BC30451: Name 'z' is not declared
''''''''''''''''''''''''''''''''''''''''
' mbas output
''''''''''''''''''''''''''''''''''''''''''
' syntax error, got token `IDENTIFIER', expecting EOL COLON
'flabel.vb(21,0) error BC29999: Line:     21 Col: 0
'VirtLine: 21 Token: 471
'Parsing error in flabel.vb
'Mono.MonoBASIC.yyParser.yyException: irrecoverable syntax error
'in <0x0081e> Mono.MonoBASIC.Parser:yyparse (Mono.MonoBASIC.yyParser.yyInput)
'in <0x002b0> Mono.MonoBASIC.Parser:parse ()
''''''''''''''''''''''''''''''''''''''''''''''
Imports System

Module labelD



    Function Abs1() As Integer

        Dim x As Integer
        x = 1
        If x >= 0 Then
            GoTo x
        End If

        x = -x

x:
y:
z:
        Return x

    End Function

    Sub Main()
        Dim x As Integer, y As Integer

        x = Abs1()
        y = Abs1()

        If x <> 1 Then
            Throw New Exception("#Lbl3")
        End If
        If y <> 1 Then
            Throw New Exception("#Lbl4")
        End If
    End Sub


End Module
------=_NextPart_000_0011_01C4743F.AD019420
Content-Type: text/plain;
	name="labelA.vb"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="labelA.vb"

' Positive Test
' Test labels in functions
' the prduction for LabelName is
' LabelName ::= Identifier | IntLiteral
' vide vbls71 section 10.1 Blocks
Imports System

Module labelA


    Function Abs(ByVal x As Integer) As Integer

        If x >= 0 Then
            GoTo 1234234
        End If

        x = -x

1234234:
        Return x

    End Function


    Sub Main()

        Dim x As Integer, y As Integer
        x = Abs(-1)

        y = Abs(1)

        If x <> 1 Then
            Throw New Exception("#Lbl1")
        End If
        If y <> 1 Then
            Throw New Exception("#Lbl2")
        End If

    End Sub


End Module
------=_NextPart_000_0011_01C4743F.AD019420
Content-Type: text/plain;
	name="labelB.vb"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="labelB.vb"

' Positive Test
' Test labels in functions
Imports System

Module labelB


    Function Abs(ByVal x As Integer) As Integer

        If x >= 0 Then
            GoTo x
        End If

        x = -x
x:      Return x

    End Function


    Sub Main()
        Dim x As Integer, y As Integer
        x = Abs(-1)
        y = Abs(1)

        If x <> 1 Then
            Throw New Exception("#Lbl1")
        End If
        If y <> 1 Then
            Throw New Exception("#Lbl2")
        End If


    End Sub


End Module
------=_NextPart_000_0011_01C4743F.AD019420
Content-Type: text/plain;
	name="labelC.vb"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="labelC.vb"

' Positive Test
' Test labels in functions
Imports System

Module labelC


    Function Abs(ByVal x As Integer) As Integer

        If x >= 0 Then
            GoTo x
        End If

        x = -x

x:
y:
z:
        Return x

    End Function


    Sub Main()
        Dim x As Integer, y As Integer
        x = Abs(-1)
        y = Abs(1)

        If x <> 1 Then
            Throw New Exception("#Lbl1")
        End If
        If y <> 1 Then
            Throw New Exception("#Lbl2")
        End If


    End Sub


End Module
------=_NextPart_000_0011_01C4743F.AD019420--