这个我想应该和标示符的定义有关,试想标示符都不是以数字开始的字符串
所以你可以采用这个规则判断a到底是number还是string

解决方案 »

  1.   

    标识符被定义成可由任何unicode码构成,除以下字符以外:空格,",[,],(,);而且不能要求该标识符本身的构成包含类型信息(因为该名称是由用户自由定义的,而用户并不知道类型);
       我想,编译原理中应该也有这种问题,希望那位编译方面的高手帮我开启一下思路。
      

  2.   

    这里该问题是JavaRanch上的回答:
    Joel McNary 
    bartender 
    Member # 19124 
      posted November 17, 2003 10:58 AM                      
    --------------------------------------------------------------------------------
    I don't know that you can do this syntactically. By eliminating the need to declare types for variables, you have eliminated the ability to enforce how a variable can be used.code:
    --------------------------------------------------------------------------------a * b--------------------------------------------------------------------------------
    is going to be valid no matter if a = 3 or a = "Hello, World"code:
    --------------------------------------------------------------------------------a=3a="Hello, World"a=someFunction()a*b--------------------------------------------------------------------------------The most that you can do here is have some sort of run-time exception that halts processing and states somethign like, "You cannot multiple "Hello, World" by anything." or something like that.--------------------Joel McNary
    It takes my kid to raze a village. 我想也许这确是一个不能解决的问题;