Ruby词法分析器和新闻1则

团购巨头LivingSocial目前已经从风投融资2.32亿美元,最近和Groupon一样都展开了大规模的收购行动。该公司称,InfoEther的灵活性和专业知识能更增强该公司更高效地创新的能力。收购协议条款尚未透露。

InfoEther是专业从事开源Ruby软件开发语言及其相关Web开发框架 Ruby on Rails的领先技术咨询公司。该开发框架正是LivingSocial所采用的技术的基础。Hadoop的期货价格结构的大数据:DataStax轻灵,EMC和MapR

InfoEther成立于 2001年,据称是美国第一家依靠Ruby(创造于日本)语言创收的公司。2007年后,该公司专门为全球40多家客户进行Rails框架的开发。

对于这次收购,InfoEther首席技术官Chad Fowler评价称:“我们非常高兴能将我们咨询工作中的灵活性和精力带到才华横溢的LivingSocial团队中来,帮助改变地方性商业的面貌。”

LivingSocial最近收购了Let’s Bonus的大部分股权,2010年收购了Urban Escapes。该公司称期望今年能扩张到300个市场。
class WordAnalysis 
  def analysis(filename, outfilename)
    @outfile= File.new(outfilename, "w")
    File.open(filename) do |file|
      while line = file.gets
        analysisHandler(line)
      end
    end
    @outfile.close
  end

  def analysisHandler(line)
    @line = line
    @max = line.length
    @ptr = 0
    @word = ""

    while @ptr<@max
      getChar()
      if isLetter()
        if @ch==105
          getChar()
          if @ch==102
            handlerResult("(1, if )")
          elsif @ch==110
            getChar()
            if @ch==116
              handlerResult("(1, int )")
            else
              idhandler()
            end
          else
            idHandler()
          end
        elsif @ch==109
          getChar()
          if @ch==97
            getChar()
            if @ch==105
              getChar()
              if @ch==110
                handlerResult("(1, main )")
              else
                idHandler()
              end
            else
              idHandler()
            end
          else
            idHandler()
          end
        elsif @ch==99
          getChar()
          if @ch==111
            getChar()
            if @ch==110
              getChar()
              if @ch==115
                getChar()
                if @ch==116
                  handlerResult("(1, const )")
                else
                  idHandler()
                end
              else
                idHandler()
              end
            else
              idHandler()
            end

          else
            idHandler()
          end
        elsif @ch==102
          getChar()
          if @ch==111
            getChar()
            if @ch==114
              handlerResult("(1, for )")
            else
              idHandler()
            end
          else
            idHandler()
          end
        elsif @ch==119
          getChar()
          if @ch==104
            getChar()
            if @ch==105
              getChar()
              if @ch==108
                getChar()
                if @ch==101
                  handlerResult("(1 while )")
                else
                  idHandler()
                end
              else
                idHandler()
              end
            else
              idHandler()
            end
          else
            idHandler()
          end

        elsif @ch==101
          getChar()
          if @ch==108
            getChar()
            if @ch==115
              getChar()
              if @ch==101
                handlerResult("(1, else )")
              else
                idHandler()
              end
              idHandler()
            end
          else
            idHandler()
          end
        elsif @ch==114
          getChar()
          if @ch==101
            getChar()
            if @ch==116
              getChar()
              if @ch==117
                getChar()
                if @ch==114
                  getChar()
                  if @ch==110
                    handlerResult("(1, return )")
                  else
                    idHandler()
                  end
                else
                  idHandler()
                end
              else
                idHandler()
              end
            else
              idHandler()
            end
          else
            idHandler()
          end
        else
          idHandler()

        end


      elsif isDigit()
        intHandler()

      elsif @ch==61 #=
        handlerResult("(4, = )")
      elsif @ch==45 #=
        handlerResult("(4, - )")
      elsif @ch==43 #+
        handlerResult("(4, + )")
      elsif @ch==42 #*
        handlerResult("(5, * )")
      elsif @ch==47 #/
        handlerResult("(5, / )")
      elsif @ch==44 #,
        handlerResult("(5, , )")
      elsif @ch==59 #;
        @word[@word.length-1]=""
        handlerResult("(5, ; )")
      elsif @ch==40 #(
        handlerResult("(5, ( )")
      elsif @ch==41 #)
        handlerResult("(5, ) )")
      elsif @ch==123 #{
        handlerResult("(5, { )")
      elsif @ch==125 #}
        handlerResult("(5, } )")
      elsif isWhitespace()
        @word[@word.length-1]=""
      else
        procError()


      end


    end

  end

  def idHandler()
    while isLetter()||isDigit()
      getChar()
    end
    if !isLetter()||!isDigit()
      retract()
    end

    handlerResult("(2, #{@word} )")


  end

  def intHandler()
    while isDigit()
      getChar()
    end
    if !isDigit()
      if (@ch==61||@ch==43||@ch==42||@ch==44||isWhitespace()||@ch==59)
        retract()
      else
        while !(@ch==61||@ch==43||@ch==42||@ch==44||isWhitespace()||@ch==59)
          getChar()
        end
        if (@ch==61||@ch==43||@ch==42||@ch==44||isWhitespace()||@ch==59)

          retract()
        end
        procWordError()
        return
      end
    end
    handlerResult("(3, #{@word} )")
  end


  def isLetter()
    if (@ch>=65&&@ch<=90)||(@ch>=97&&@ch<=122)
      return true
    else
      return false
    end
  end

#48-57(0-9)
  def isDigit()
    if (@ch>=48&&@ch<=57)
      return true
    else
      return false
    end
  end

  def isWhitespace()
    tempSpace = ""
    tempSpace<<@ch
    delim = /\s+/
    if tempSpace=~ delim
      return true
    else
      return false
    end
  end

  def getChar()
    if @ptr < @max
      @ch = @line[@ptr]
      @word<<@ch
      @ptr = @ptr+1
    else
      @ch = 32
    end
  end

  def retract()
    @word[@word.length-1]=''
    @ptr = @ptr-1
    @ch = @line[@ptr]
  end

  def handlerResult(val)
    puts val
    @outfile.syswrite(val+"\n")
    @word=""
  end

  def procError()
    val=""
    val<<@ch
    puts "return(error,#{val})"
    @outfile.syswrite("return(error,#{val}) \n")
    @word=""
  end

  def procWordError()
    puts "return(error,#{@word})"
    @outfile.syswrite("return(error,#{@word}) \n")
    @word=""
  end

end


word = WordAnalysis.new
word.analysis("/input.txt", "/output.txt")

转载于:https://my.oschina.net/linuxred/blog/14771

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值