Skip to main content

Syntax Analysis

  • Chapter
  • 7048 Accesses

Part of the book series: Undergraduate Topics in Computer Science ((UTICS))

Abstract

Where lexical analysis splits the input into tokens, the purpose of syntax analysis (also known as parsing) is to recombine these tokens. Not back into a list of characters, but into something that reflects the structure of the text. This “something” is typically a data structure called the syntax tree of the text. As the name indicates, this is a tree structure. The leaves of this tree are the tokens found by the lexical analysis, and if the leaves are read from left to right, the sequence is the same as in the input text. Hence, what is important in the syntax tree is how these leaves are combined to form the structure of the tree and how the interior nodes of the tree are labelled. In addition to finding the structure of the input text, the syntax analysis must also reject invalid texts by reporting syntax errors. As syntax analysis is less local in nature than lexical analysis, more advanced methods are required. We, however, use the same basic strategy: A notation suitable for human understanding is transformed into a machine-like low-level notation suitable for efficient execution. This process is called parser generation.

“Syntax and vocabulary are overwhelming constraints—the rules that run us. Language is using us to talk—we think we’re using the language, but language is doing the thinking, we’re its slavish agents.”

Harry Mathews (1930–)

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   29.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    The name refers to the fact that derivation is independent of context.

  2. 2.

    The mathematically inclined will recognise that derivation is a preorder on sequences of grammar symbols.

  3. 3.

    We have omitted the production for semicolon, as that would only muddle the issue by introducing more ambiguity.

  4. 4.

    Using several operators with declared priorities in the same production should be done with care.

References

  1. Aasa, A.: Precedences in specification and implementations of programming languages. In: Maluszyński, J., Wirsing, M. (eds.) Proceedings of the Third International Symposium on Programming Language Implementation and Logic Programming. LNCS, vol. 528, pp. 183–194. Springer, Berlin (1991). citeseer.ist.psu.edu/article/aasa91precedences.html

    Chapter  Google Scholar 

  2. Aho, A.V., Lam, M.S., Sethi, R., Ullman, J.D.: Compilers; Principles, Techniques and Tools. Addison-Wesley, Reading (2007)

    Google Scholar 

  3. Chomsky, N.: Three models for the description of language. IRE Trans. Inf. Theory 2(3), 113–124 (1956)

    Article  MATH  Google Scholar 

  4. Backus, J.W., Bauer, F.L., Green, J., Katz, C., McCarthy, J., Perlis, A.J., Rutishauser, H., Samelson, K., Vauquois, B., Wegstein, J.H., van Wijngaarden, A., Woodger, M.: Revised report on the algorithmic language Algol 60. Commun. ACM 6(1), 1–17 (1963)

    Article  Google Scholar 

  5. Hopcroft, J.E., Motwani, R., Ullman, J.D.: Introduction to Automata Theory, Languages and Computation, 2nd edn. Addison-Wesley, Reading (2001)

    MATH  Google Scholar 

  6. Jensen, K., Wirth, N.: Pascal User Manual and Report, 2nd edn. Springer, Berlin (1975)

    Book  MATH  Google Scholar 

  7. Kerninghan, B.W., Ritchie, D.M.: The C Programming Language. Prentice-Hall, New York (1978)

    Google Scholar 

  8. Parr, T.: The Definitive ANTLR Reference: Building Domain-Specific Languages, 1st edn. Pragmatic Programmers. The Pragmatic Bookshelf, Lewisville (2007)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Torben Ægidius Mogensen .

Rights and permissions

Reprints and permissions

Copyright information

© 2011 Springer-Verlag London Limited

About this chapter

Cite this chapter

Mogensen, T.Æ. (2011). Syntax Analysis. In: Introduction to Compiler Design. Undergraduate Topics in Computer Science. Springer, London. https://doi.org/10.1007/978-0-85729-829-4_2

Download citation

  • DOI: https://doi.org/10.1007/978-0-85729-829-4_2

  • Publisher Name: Springer, London

  • Print ISBN: 978-0-85729-828-7

  • Online ISBN: 978-0-85729-829-4

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics