Grammars - Grammars Grammars are used to define the syntax of a language Grammars are often encountered in the context of natural languages where

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2984: Computational Thinking 1 Course Notes Spring, 2011 Grammars Grammars are used to define the syntax of a language. Grammars are often encountered in the context of natural languages where the “English grammar” means, for example, the rules that say whether a list of words is or is not a correct sentence in English. Syntax is a structural description without regard for meaning. Sentences that are grammatically correct may also be meaningless. For example, the correctly formed English sentence “Red is blue.” is not meaningful (at least in the ordinary interpretation of the words). The syntax of properly formed data can also be expressed in a grammatical form. The grammar defines which patterns of symbols are valid in the language of the data and which patterns are not valid. As noted above, the grammar for some kind of data can tell whether a string of symbols is syntactically valid without saying what the symbols might “mean” (i.e., it does not give us any information about the semantics of the data). A common way of defining a grammar in computationally-related situations is the Backus-Naur Form (BNF) and its extension (EBNF). BNF can be used to describe how to perform two different, though related tasks: to generate expressions that are valid in the grammar to recognize whether a given expression is valid in the grammar BNF will be explained by using it to generate valid expressions. A BNF grammar is a set of production rules that have the general form: term ::= expansion where the symbols “::=” are special in BNF. The production rule means that wherever a “term” occurs in the sentence being generated it can be replace by “expansion”. The expansion by consist of two forms:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/23/2012 for the course CS 2984 taught by Professor Lewis during the Spring '08 term at Virginia Tech.

Page1 / 3

Grammars - Grammars Grammars are used to define the syntax of a language Grammars are often encountered in the context of natural languages where

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online