linukso吧 关注:1,482贴子:173,694
  • 6回复贴,共1

[help] 词法分析要处理什么样的错误?

只看楼主收藏回复

设计的一个非常简单的c语言词法分析器:一次扫描全部单词完成
编译器的独立一遍任务。
这样的词法分析器要检测什么错误呢?
e.g. 这个错误要检测
line0:int a# = 0;
那么
line1: b
这个错误要检测么。感觉应该语法分析器检测
line2: main)
这个呢,感觉也是语法分析器干的事。I


1楼2013-10-31 00:41回复
    看网上的词法分析器,还要检测变量类型神马的
    这应该不需要吧I


    2楼2013-10-31 00:49
    回复
      lexical analysis is the process of converting a sequence of characters into a sequence of tokens.
      A token is a string of one or more characters that is significant as a group
      Tokens are often categorized by character content or by context within the data stream. Categories are defined by the rules of the lexer. Categories often involve grammar elements of the language used in the data stream.
      Programming languages often categorize tokens as identifiers, operators, grouping symbols, or by data type.
      Ref:https://en.wikipedia.org/wiki/Lexical_analysisI


      IP属地:美国3楼2013-10-31 05:34
      收起回复
        编译原理吗?好高深。


        IP属地:辽宁来自Android客户端4楼2013-11-01 10:29
        回复
          高端大气上档次。。大神收我为徒吧


          来自Android客户端5楼2013-11-01 11:11
          收起回复