Re: Escape Sequences

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.21cf9999a727a1a970c@xxxxxxxxxxxxxxxxxxxxxxx
Liz <liz@xxxxxxxxxxxxxxx> wrote:
Why would it be a compiler bug? The C# compiler has been passed this:

void Page_Load()
{
if (!Page.IsPostBack)
{
litYear.Text = DateTime.Now.Year.ToString();
string jScript = "<script>document.forms[0].submit();</script>

That piece of code has all the problems which are reported.


no, it was passed:

string jScript = "<script>document.forms[0].submit();</script>";

What makes you say that? That wouldn't explain the errors that were
produced, whereas my (corrected below) version does.

because that was the code the OP posted ... and it does produce the errors
originally reported when in it resides in an .ASPX file

I do have a correction, though: I believe it was actually passed:

void Page_Load()
{
if (!Page.IsPostBack)
{
litYear.Text = DateTime.Now.Year.ToString();
string jScript = "<script>document.forms[0].submit();

In other words, everything before the </script>.


I'm not clear what you mean, Jon ... that you "have a correction" ... what
you think the OP really meant to say? the code above has an unclosed quote
.... ??


why should that generate an error, anymore than:

void myMethod()
{
string s = "I put a } character in here;";
}

should generate an error?


That's *just* C# code - the only thing that has to work with it is the
C# compiler. Compare that with the ASP.NET situation: the ASP.NET
engine has to pick out bit of code within <script runat="server"> and
</script> tags, and pass those off to another compiler. It doesn't
understand the contents of the element.

right ... and doesn't really need to; the string assigned to the variable
jScript was intended to run on the client (although the implementation was
never fully spelled out in this thread)

So, without any direct knowledge of the language it's working with, how
should it find out which is a "real" </script> and which is one which
actually just happens to be part of the code?

again, it's not working with a language here; it's only working with a
string of characters comprising some Javascript code

This is always going to be a problem when embedding code from one
language within another - there has to be a way of detecting where the
embedded code ends. It looks like the ASP.NET engine just looks for the
first </script> after the opening tag, and passes everything between
the two to the appropriate language compiler.

which seems to make the ASP.NET engine a little dumber than it might be, no?
it should have ignored the first </script> it encountered because it was
between quotation marks

Compared with any other mechanism it would have to use to find the end
of the code block, I'm pretty comfortable with the decision that's been
made.

well, I don't know that I'm "uncomfortable" with any of this but I am
puzzled why it has any particular difficulty in simply recognizing a quoted
literal being assigned to a string var and ignoring it for purposes of
identifying the begin/end of the <script></script> block










.



Relevant Pages

  • Re: PL/I string representations
    ... >> of the language, so it was interesting to me, hopefully it will be to ... I found a workable compiler for Fortran in 1971 (with a bug ... >> The specified length is the minimum, and each time a character ... >> string is assigned to E, the length is stored with it. ...
    (comp.programming)
  • Why C Is Not My Favourite Programming Language
    ... C has no string type. ... compiler take care of the rest. ... Why does any normal language ... the programmer fail. ...
    (comp.lang.c)
  • Re: Code Review - is this code shit
    ... a matter of language only. ... Richard Heathfield constantly abuses and harasses unsuspecting users ... mainframe (I had had to debug the compiler in object code form). ... "proposed a real string data type" they would have invented Java or C ...
    (comp.lang.c)
  • Re: Escape Sequences
    ... what's being passed from the ASP.NET engine to the C# compiler. ... the string assigned to the variable ... it still needs to understand the language. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: SQL
    ... The "expression engine" can be logically seperated from a relational ... query language, in theory they could without busting relational. ... They all are typed, as well as SQL. ... everything as pretty much a string. ...
    (comp.object)