Language Processor Development Tools
- The two widely used language processor development tools are the lexical analyzer generator LEX and the parser generator YACC. The input to these tools are specifications of the lexical and syntactic constructs of a programming language L, and the semantic actions that should be
performed on recognizing the constructs. Figure shows a schematic for developing the analysis phase of a compiler for language L by using LEX and YACC.
LEX Language Processor Development Tools
- The input to LEX consists of two components.
- The first component is a specification of strings that represent the lexical units in L.
- Moreover, This specification is in the form of regular expressions.
- The second component a specification of semantic actions that are aimed at building the intermediate representation.
- The intermediated representation produced by a scanner would consist of a set of tables of lexical units. And a sequence of tokens for the lexical units occurring in a source statement.
- Moreover, The scanner generated by LEX would be invoked by a parser whenever the parser needs the next token.
- Accordingly, each semantic action would perform some table building actions and return a single token.
- Each translation rule input to YACC has a string specification that resembles a production of a grammar—it has a nonterminal on the LHS and a few alternatives on the RHS.
- Moreover, For simplicity, we will refer to a string specification as a production. YACC generates an LALR(1) parser for language L from the productions, which is a bottom-up parser.
- The parser would operate as follows:Moreover, For a shift action, it would invoke the scanner to obtain the next token and continue the parse by using that token. While performing a reduce action in accordance with a production, it would perform the semantic action associated with that production.
- Similarly, semantic actions associated with productions achieve the building of an intermediate representation or target code as follows: Every nonterminal symbol in the parser has an attribute.
- Moreover, The semantic action associated with a production can access attributes of nonterminal symbols used in that production—a symbol ‘$n’ in the semantic action, where n is an integer. designates the attribute of the nth nonterminal symbol in the RHS of the production and the symbol ‘$$’ designates the attribute of the LHS nonterminal symbol of the production. The semantic action uses the values of these attributes for building the intermediate representation or target code. The attribute type can declare in the specification input to YACC.