ArticleslgStudy

computer science

Abstract semantic graph

Abstract semantic graph is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Abstract semantic graph rather than just read about it. In short: In computer science, an abstract semantic graph (ASG) or term graph is a form of abstract syntax in which an expression of a formal or programming language is represented by a graph whose vertices are the expression's subterms. An ASG is at a higher level of abstraction than an abstract syntax tree (or AST), which is used to express the syntactic structure of an expression or program.

Key takeaways

  • Abstract semantic graph belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Abstract semantic graph to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Abstract semantic graph from memory before moving on to harder problems.

Reference excerpt

In computer science, an abstract semantic graph (ASG) or term graph is a form of abstract syntax in which an expression of a formal or programming language is represented by a graph whose vertices are the expression's subterms. An ASG is at a higher level of abstraction than an abstract syntax tree (or AST), which is used to express the syntactic structure of an expression or program. ASGs are more complex and concise than ASTs because they may contain shared subterms (also known as "common subexpressions"). Abstract semantic graphs are often used as an intermediate representation by compilers to store the results of performing common subexpression elimination upon abstract syntax trees. ASTs are trees and are thus incapable of representing shared terms. ASGs are usually directed acyclic graphs (DAG), although in some applications graphs containing cycles may be permitted. For example, a graph containing a cycle might be used to represent the recursive expressions that are commonly used in functional programming languages as non-looping iteration constructs. The mutability of these types of graphs, is studied in the field of graph rewriting. The nomenclature term graph is associated with the field of term graph rewriting, which involves the transformation and processing of expressions by the specification of rewriting rules, whereas abstract semantic graph is used when discussing linguistics, programming languages, type systems and compilation. Abstract syntax trees are not capable of sharing subexpression nodes because it is not possible for a node in a proper tree to have more than one parent. Although this conceptual simplicity is appealing, it may come at the cost of redundant representation and, in turn, possibly inefficiently duplicating the computation of identical terms. For this reason ASGs are often used as an intermediate language at a subsequent compilation stage to abstract syntax tree construction via parsing. An abstract semantic graph is typically constructed from an abstract syntax tree by a process of enrichment and abstraction. The enrichment can for example be the addition of back-pointers, edges from an identifier node (where a variable is being used) to a node representing the declaration of that variable. The abstraction can entail the removal of details which are relevant only in parsing, not for semantics.

Example: Code Refactoring For example, consider the case of code refactoring. To represent the implementation of a function that takes an input argument, the received parameter is conventionally given an arbitrary, distinct name in the source code so that it can be referenced. The abstract representation of this conceptual entity, a "function argument" instance, will likely be mentioned in the function signature, and also one or more times within the implementation code body. Since the function as a whole is the parent of both its header or "signature" information as well as its implementation body, an AST would not be able to use the same node to co-identify the multiple uses or appearances of the argument entity. This is solved by the DAG nature of an ASG. A key advantage of having a single, distinct node identity for any given code element is that each element's properties are, by definition, uniquely stored. This simplifies refactoring operations, because there is exactly one existential nexus for any given property instantiation. If the developer decides to change a property value such as the "name" of any code element (the "function argument" in this example), the ASG inherently exposes that value in exactly one place, and it follows that any such property changes are implicitly, trivially, and immediately propagated globally.

See also Ontology (computer science) Semantic Web Semantic Grid

References

Further reading Dean, Tom. "CPPX — C/C++ Fact Extractor". Devanbu, Premkumar T.; Rosenblum, David S.; Wolf, Alexander L. "Generating Testing and Analysis Tools with Aria". Archived from the original on 2006-05-27.{{cite web}}: CS1 maint: miscellaneous url (link) Mamas, Evan; Kontogiannis, Kostas (2000). Towards Portable Source Code Representations Using XML. Seventh Working Conference on Reverse Engineering. pp. 172–182. doi:10.1109/WCRE.2000.891464. S2CID 17403365. Raghavan, Shruti; Rohana, Rosanne; Leon, David; Podgurski, Andy; Augustine, Vinay (2004). "Dex: a semantic-graph differencing tool for studying changes in large code bases". 20th IEEE International Conference on Software Maintenance, 2004. Proceedings. IEEE International Conference on Software Maintenance. pp. 188–197. doi:10.1109/icsm.2004.1357803. ISBN 0-7695-2213-0. Archived from the original on 2008-01-17. Retrieved 2007-05-01.

Worked examples

Example 1 — a first encounter with Abstract semantic graph

Start with the simplest possible case. Write down what Abstract semantic graph claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Abstract semantic graph before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Abstract semantic graph ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Abstract semantic graph

In research
Abstract semantic graph appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Abstract semantic graph in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Abstract semantic graph is common in secondary-school and first-year university syllabi. It links to neighbouring topics Formal languages, Graph data structures, so understanding it makes those chapters shorter.
In everyday life
Look for Abstract semantic graph outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Abstract semantic graph” →

How to study Abstract semantic graph in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Abstract semantic graph means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Abstract semantic graph out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Abstract semantic graph in simple terms?

In computer science, an abstract semantic graph (ASG) or term graph is a form of abstract syntax in which an expression of a formal or programming language is represented by a graph whose vertices are the expression's subterms. An ASG is at a higher level of abstraction than an abstract syntax tree…

Why does Abstract semantic graph matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Abstract semantic graph?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Abstract semantic graph.

Tags

  • Formal languages
  • Graph data structures

Keep exploring