1-1 1 Syntax  Informal vs formal specification  Regular expressions  Backus Naur Form (BNF)  Extended Backus Naur Form (EBNF)  Case study: Calc syntax.

Slides:



Advertisements
Similar presentations
Grammars, constituency and order A grammar describes the legal strings of a language in terms of constituency and order. For example, a grammar for a fragment.
Advertisements

Grammars, Languages and Parse Trees. Language Let V be an alphabet or vocabulary V* is set of all strings over V A language L is a subset of V*, i.e.,
Chapter Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Slide 1 Chapter 2-b Syntax, Semantics. Slide 2 Syntax, Semantics - Definition The syntax of a programming language is the form of its expressions, statements.
1 Foundations of Software Design Lecture 23: Finite Automata and Context-Free Grammars Marti Hearst Fall 2002.
Programming Languages An Introduction to Grammars Oct 18th 2002.
Chapter 3: Formal Translation Models
Specifying Languages CS 480/680 – Comparative Languages.
Winter 2003/4Pls – syntax – Catriel Beeri1 SYNTAX Syntax: form, structure The syntax of a pl: The set of its well-formed programs The rules that define.
S YNTAX. Outline Programming Language Specification Lexical Structure of PLs Syntactic Structure of PLs Context-Free Grammar / BNF Parse Trees Abstract.
(2.1) Grammars  Definitions  Grammars  Backus-Naur Form  Derivation – terminology – trees  Grammars and ambiguity  Simple example  Grammar hierarchies.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Context-Free Grammars and Parsing 1.
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax.
Compiler Principle and Technology Prof. Dongming LU Mar. 7th, 2014.
Syntax Analysis (Chapter 4) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
CSI 3120, Grammars, page 1 Language description methods Major topics in this part of the course: –Syntax and semantics –Grammars –Axiomatic semantics (next.
Definition A string is a sequence of symbols. Examples “Hi, Mom.” “YAK” “abbababba” Question In what ways do programmers use strings?
Syntax Specification and BNF © Allan C. Milne Abertay University v
Syntax and Backus Naur Form
1 Chapter 3 Describing Syntax and Semantics. 3.1 Introduction Providing a concise yet understandable description of a programming language is difficult.
A sentence (S) is composed of a noun phrase (NP) and a verb phrase (VP). A noun phrase may be composed of a determiner (D/DET) and a noun (N). A noun phrase.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
CS 331, Principles of Programming Languages Chapter 2.
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
Grammars CPSC 5135.
PART I: overview material
3-1 Chapter 3: Describing Syntax and Semantics Introduction Terminology Formal Methods of Describing Syntax Attribute Grammars – Static Semantics Describing.
C H A P T E R TWO Syntax and Semantic.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
11 Chapter 4 Grammars and Parsing Grammar Grammars, or more precisely, context-free grammars, are the formalism for describing the structure of.
CMSC 330: Organization of Programming Languages Context-Free Grammars.
CPS 506 Comparative Programming Languages Syntax Specification.
Copyright © 2006 Addison-Wesley. All rights reserved. Ambiguity in Grammars A grammar is ambiguous if and only if it generates a sentential form that has.
Chapter 3 Describing Syntax and Semantics
Context Free Grammars CFGs –Add recursion to regular expressions Nested constructions –Notation expression  identifier | number | - expression | ( expression.
Syntax The Structure of a Language. Lexical Structure The structure of the tokens of a programming language The scanner takes a sequence of characters.
CS 331, Principles of Programming Languages Chapter 2.
Syntax and Grammars.
Unit-3 Parsing Theory (Syntax Analyzer) PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Syntax and Semantics Form and Meaning of Programming Languages Copyright © by Curt Hill.
Chapter 3 Context-Free Grammars Dr. Frank Lee. 3.1 CFG Definition The next phase of compilation after lexical analysis is syntax analysis. This phase.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
Programming Languages and Design Lecture 2 Syntax Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
LECTURE 4 Syntax. SPECIFYING SYNTAX Programming languages must be very well defined – there’s no room for ambiguity. Language designers must use formal.
C H A P T E R T W O Syntax and Semantic. 2 Introduction Who must use language definitions? Other language designers Implementors Programmers (the users.
©SoftMoore ConsultingSlide 1 Context-Free Grammars.
Spring 16 CSCI 4430, A Milanova 1 Announcements HW1 will be out this evening Due Monday, 2/8 Submit in HW Server AND at start of class on 2/8 A review.
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Autumn 2012 CSE
Syntax Analysis Or Parsing. A.K.A. Syntax Analysis –Recognize sentences in a language. –Discover the structure of a document/program. –Construct (implicitly.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Chapter 3 – Describing Syntax
PROGRAMMING LANGUAGES
Parsing & Context-Free Grammars
CS510 Compiler Lecture 4.
Chapter 3 – Describing Syntax
Syntax (1).
Compiler Construction
CSE 311: Foundations of Computing
R.Rajkumar Asst.Professor CSE
Lecture 4: Lexical Analysis & Chomsky Hierarchy
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Discrete Maths 13. Grammars Objectives
COMPILER CONSTRUCTION
Presentation transcript:

1-1 1 Syntax  Informal vs formal specification  Regular expressions  Backus Naur Form (BNF)  Extended Backus Naur Form (EBNF)  Case study: Calc syntax Programming Languages 3 © 2012 David A Watt, University of Glasgow

1-2 What is syntax?  The syntax of a PL is concerned with the form of programs: how expressions, commands, declarations, and other constructs are arranged to make a well-formed program.  When learning a new PL, we need to learn the PL’s syntax.  The PL’s syntax must be specified. Examples alone do not show the PL’s generality: if n > 0 : write( n ) What is allowed here? – a variable? – an arbitrary expression? What is allowed here? – a simple command? – a sequence of commands?

1-3 Informal vs formal specification  An informal specification is one expressed in natural language (such as English).  A formal specification is one expressed in a precise notation.  Pros and cons of formal specification: +more precise +usually more concise +less likely to be ambiguous, inconsistent, or incomplete –accessible only to those familiar with the notation.

1-4 Example: informal vs formal syntax  Informal syntax of some commands in a C-like language: A while-command consists of ‘ while ’, followed by an expression enclosed in parentheses, followed by a command. A sequential-command consists of a sequence of one or more commands, enclosed by ‘ { ’ and ‘ } ’.  Formal syntax (using EBNF notation): while-command=‘ while ’ ‘ ( ’ expression ‘ ) ’ command sequential-command=‘ { ’ command + ‘ } ’

1-5 Notations for formal specification of PL syntax  Regular expressions (REs) –good for specifying syntax of lexical elements of programs (such as identifiers, literals, comments).  Backus Naur Form (BNF) –good for specifying syntax of larger and nested program constructs (such as expressions, commands, declarations).  Extended Backus Naur Form (EBNF) –combination of BNF and REs, good for nearly everything.

1-6 Running example: Calc  Calc is a very simple calculator language, with: –variables named ‘ a ’, …, ‘ z ’ –expressions consisting of variables, numerals, and arithmetic operators –assignment and output commands.  Example Calc program: set x = 13 set y = x*(x+1) put x put y/2

1-7 Regular expressions  A regular expression (RE) is a kind of pattern.  Each RE matches a set of strings –possibly an infinite set of strings.  We can use REs for a variety of applications: –specifying a pattern of strings to be searched for in a text –specifying a pattern of filenames to be searched for in a file system –specifying the syntax of a PL’s lexical elements.

1-8 Example: REs  Examples: ‘ M ’(‘ r ’|‘ rs ’|‘ iss ’)–means ‘ M ’ followed by either ‘ r ’ or ‘ rs ’ or ‘ iss ’ –matches ‘ Mr ’, ‘ Mrs ’, ‘ Miss ’. ‘ b ’(‘ an ’)*‘ a ’–means ‘ b ’ followed by zero or more occurrences of ‘ an ’ followed by ‘ a ’ –matches ‘ ba ’, ‘ bana ’, ‘ banana ’, etc. (‘ x ’|‘ abc ’)*–means zero or more occurrences of ‘ x ’ or ‘ abc ’ –matches ‘’, ‘ x ’, ‘ abc ’, ‘ xx ’, ‘ xabc ’, ‘ abcx ’, ‘ abcabc ’, ‘ xxx ’, ‘ xxabc ’, ‘ xabcx ’, ‘ abcxx ’, etc.

1-9 RE notation (1)  Basic RE notation: –‘xyz’matches the string ‘xyz’ –RE 1 | RE 2 matches any string matched by either RE 1 or RE 2 –RE 1 RE 2 matches any string matched by RE 1 concatenated with any string matched by RE 2 –RE *matches the concatenation of zero or more strings, each of which is matched by RE –(RE)matches any string matched by RE (parentheses used for grouping)

1-10 RE notation (2)  Additional RE notation: –RE ? matches either the empty string or any string matched by RE –RE + matches the concatenation of one or more strings, each of which is matched by RE  These additional forms are useful but not essential. They can be expanded into basic RE notation: RE ? = RE | ‘’ RE + = RE RE *

1-11 Example: Calc lexicon (1)  A Calc identifier consists of a single lower-case letter.  The syntax of such identifiers is specified by the RE: ‘ a ’ | ‘ b ’ | ‘ c ’ | ‘ d ’ | ‘ e ’ | ‘ f ’ | ‘ g ’ | ‘ h ’ | ‘ i ’ | ‘ j ’ | ‘ k ’ | ‘ l ’ | ‘ m ’ | ‘ n ’ | ‘ o ’ | ‘ p ’ | ‘ q ’ | ‘ r ’ | ‘ s ’ | ‘ t ’ | ‘ u ’ | ‘ v ’ | ‘ w ’ | ‘ x ’ | ‘ y ’ | ‘ z ’

1-12 Example: Calc lexicon (2)  A Calc numeral consists of one or more decimal digits. E.g.:  The syntax of such numbers is specified by the RE: (‘ 0 ’ | ‘ 1 ’ | ‘ 2 ’ | ‘ 3 ’ | ‘ 4 ’ | ‘ 5 ’ | ‘ 6 ’ | ‘ 7 ’ | ‘ 8 ’ | ‘ 9 ’) +

1-13 Example: alphanumeric identifiers  Consider a PL in which an identifier consists of a sequence of one or more upper-case letters and digits, starting with a letter. E.g.: X A1 P2P SOS  The syntax of such identifiers is specified by RE: (‘ A ’ | ‘ B ’ | ‘ C ’ | ‘ D ’ | ‘ E ’ | ‘ F ’ | ‘ G ’ | ‘ H ’ | ‘ I ’ | ‘ J ’ | ‘ K ’ | ‘ L ’ | ‘ M ’ | ‘ N ’ | ‘ O ’ | ‘ P ’ | ‘ Q ’ | ‘ R ’ | ‘ S ’ | ‘ T ’ | ‘ U ’ | ‘ V ’ | ‘ W ’ | ‘ X ’ | ‘ Y ’ | ‘ Z ’) (‘ A ’ | ‘ B ’ | ‘ C ’ | ‘ D ’ | ‘ E ’ | ‘ F ’ | ‘ G ’ | ‘ H ’ | ‘ I ’ | ‘ J ’ | ‘ K ’ | ‘ L ’ | ‘ M ’ | ‘ N ’ | ‘ O ’ | ‘ P ’ | ‘ Q ’ | ‘ R ’ | ‘ S ’ | ‘ T ’ | ‘ U ’ | ‘ V ’ | ‘ W ’ | ‘ X ’ | ‘ Y ’ | ‘ Z ’ | ‘ 0 ’ | ‘ 1 ’ | ‘ 2 ’ | ‘ 3 ’ | ‘ 4 ’ | ‘ 5 ’ | ‘ 6 ’ | ‘ 7 ’ | ‘ 8 ’ | ‘ 9 ’)* one letter zero or more letters and digits

1-14 Application of REs: Unix shell (1)  The Unix shell scripting language uses an ad hoc pattern-matching notation in which: – [ … ] matches any one of the enclosed characters – ? (on its own) matches any single character – * (on its own) matches any string of 0 or more characters.  This a restricted variant of RE notation. (It lacks “RE 1 |RE 2 ” and “RE * ”.)

1-15 Application of REs: Unix shell (2)  Example commands: print bat.[chp] prints files whose names are ‘ bat.c ’, ‘ bat.h ’, or ‘ bat.p ’ print bat.? prints all files whose names are ‘ bat. ’ followed by any single character print *.c prints all files whose names end with ‘.c ’

1-16 Application of REs: egrep (1)  The Unix utility egrep uses the full pattern- matching notation, in which the following have their usual meanings: –RE 1 | RE 2 –RE * –RE + –RE ?  It also provides extensions such as: – [ … ] matches any one of the enclosed characters –. matches any single character.

1-17 Application of REs: egrep (2)  Example commands: egrep "b[aei]t" file finds all lines in file containing ‘ bat ’, ‘ bet ’, or ‘ bit ’ egrep "b.t" file finds all lines in file containing ‘ b ’ followed by any character followed by ‘ t ’. egrep "b(an)*a" file finds all lines in file containing ‘ b ’ followed by 0 or more occurrences of ‘ an ’ followed by ‘ a ’.

1-18 Application of REs: Java pattern matching  Some Java classes also use the full pattern- matching notation, with the same extensions as egrep : – [ … ] matches any one of the enclosed characters –. matches any single character.  Example code: String s = … ; if (s.matches("b.t")) … if (s.matches("b[aeiou]t")) … if (s.matches("M(r|rs|iss)")) … if (s.matches("b(an)*a")) …

1-19 Limitations of REs  REs are not powerful enough to express the syntax of nested (embedded) phrases.  In every PL, expressions can be nested: n * ( n + 1 )  In nearly every PL, commands can be nested: while (r>0) { m = n; n = r; r = m-(n*(m/n)); }

1-20 Grammars  To specify the syntax of nested phrases such as expressions and commands, we need a (context- free) grammar.  The grammar of a language is a set of rules specifying how the phrases of that language are formed.  Each rule specifies how each phrase may be formed from symbols (such as words and punctuation) and simpler phrases.

1-21 Example: mini-English grammar (1)  Mini-English consists of simple sentences like: I smell a rat. the cat sees me.  The following symbols occur in mini-English sentences: ‘ a ’ ‘ cat ’ ‘ I ’ ‘ mat ’ ‘ me ’ ‘ rat ’ ‘ see ’ ‘ sees ’ ‘ smell ’ ‘ smells ’ ‘ the ’ ‘. ’  The grammar uses the following symbols to denote mini-English phrases: sentence subject object noun verb terminal symbols nonterminal symbols

1-22 Example: mini-English grammar (2)  Production rules of the mini-English grammar: sentence=subject verb object ‘. ’ subject=‘ I ’ | ‘ a ’ noun | ‘ the ’ noun object=‘ me ’ | ‘ a ’ noun | ‘ the ’ noun noun=‘ cat ’ | ‘ mat ’ | ‘ rat ’ verb=‘ see ’ | ‘ sees ’ | ‘ smell ’ | ‘ smells ’ read as “A sentence consists of a subject followed by a verb followed by an object followed by ‘. ’.” read as “A subject consists of the word ‘ I ’ alone, or the word ‘ a ’ followed by a noun, or the word ‘ the ’ followed by a noun.”

1-23 Example: mini-English grammar (3)  How sentences are structured: ratasmellI. sentence subject verbnoun object cattheseesme. sentence object verbnoun subject  The structure of a sentence can be shown by a syntax tree (see later).

1-24 Grammars, symbols, production rules  A context-free grammar (or just grammar) consists of: –a set of terminal symbols –a set of nonterminal symbols –a sentence symbol –a set of production rules. Each terminal symbol is a symbol that may occur in a sentence. Each nonterminal symbol stands for a phrase that may form part of a sentence. The sentence symbol is the nonterminal symbol that stands for a complete sentence. Each production rule specifies how phrases are composed from terminal symbols and sub-phrases.

1-25 BNF notation (1)  Backus Naur Form (BNF) is a notation for expressing a grammar.  A simple production rule in BNF looks like this: N = α N is a nonterminal symbol α is a sequence of terminal and nonterminal symbols “=” is read as “consists of”  Example (mini-English): sentence = subject verb object ‘. ’

1-26 BNF notation (2)  More generally, a production rule in BNF may have several alternatives on its right-hand side: N = α | β | γ each of α, β, γ is a sequence of terminal and nonterminal symbols “|” is read as “or”.  Example (mini-English): subject = ‘ I ’ | ‘ a ’ noun | ‘ the ’ noun

1-27 Example: Calc grammar in BNF (1)  Terminal symbols: ‘ put ’ ‘ set ’ ‘ = ’ ‘ + ’ ‘ - ’ ‘ * ’ ‘ ( ’ ‘ ) ’ ‘ \n ’ ‘ a ’ ‘ b ’ ‘ c ’ … ‘ z ’ ‘ 0 ’ ‘ 1 ’ … ‘ 9 ’  Nonterminal symbols: prog com expr prim num id  Sentence symbol: prog

1-28 Example: Calc grammar in BNF (2)  Production rules: prog=eof |com prog com=‘ put ’ expr eol |‘ set ’ id ‘ = ’ expr eol expr=prim |expr ‘ + ’ prim |expr ‘ - ’ prim |expr ‘ * ’ prim prim=num |id |‘ ( ’ expr ‘ ) ’ A prog consists of just an eof, or alternatively a com followed by a prog. In other words, a prog consists of a sequence of zero or more coms followed by an eof.

1-29 Example: Calc grammar in BNF (3)  Production rules (continued): num=digit | num digit id=letter letter=‘ a ’ | ‘ b ’ | ‘ c ’ | … | ‘ z ’ digit=‘ 0 ’ | ‘ 1 ’ | … | ‘ 9 ’ eol=‘ \n ’

1-30 Phrase structure  A grammar defines how phrases may be formed from sub-phrases in the language. This is called phrase structure.  Every phrase in the language has a syntax tree that explicitly represents its phrase structure.

1-31 Example: mini-English syntax trees  Syntax trees of mini-English sentences:.Ismellarat sentence subjectobjectverb noun thecatseesme. sentence subjectobjectverb noun

1-32 Example: Calc syntax trees (1)  Syntax trees of Calc expressions: prim idnum n+1 expr opexpr prim *x id prim expr id num y-22)( prim expr op expr

1-33 Example: Calc syntax trees (2)  Syntax trees of Calc commands: putn id expr \n prim com =42\n num expr prim setn id com

1-34 Syntax trees  Consider a grammar G.  A syntax tree of G is a tree with the following properties: –Every terminal node is labeled by a terminal symbol of G. –Every nonterminal node is labeled by a nonterminal symbol of G. –A nonterminal node labeled N may have children labeled X, Y, Z (from left to right) only if G has a production rule N = X Y Z or N = … | X Y Z | … N X ZY

1-35 Phrases  If N is a nonterminal symbol of G, a phrase of class N is a string of terminal symbols labeling the terminal nodes of a syntax tree whose root node is labeled N. –Note: The terminal nodes must be visited from left to right.  E.g., phrases in Calc: –‘ x*(22-y) ’ is a phrase of class expr –‘ set n = 42 \n ’ is a phrase of class com –‘ set n = 42 \n put x*(22-y) \n ’ is a phrase of class prog.

1-36 Sentences and languages  If S is the sentence symbol of G, a sentence of G is a phrase of class S. E.g.: –‘ set n = 42 \n put x*(22-y) \n ’ is a sentence of Calc.  The language generated by G is the set of all sentences of G.  Note: The language generated by G is typically infinite (although G itself is finite).

1-37 Phrase structure and semantics  The above definition of a language is narrowly syntactic: a set of sentences.  We are also interested in the language ’ s semantics (i.e., the meaning of each sentence).  A grammar does more than generate a set of sentences: it also imposes a phrase structure on each sentence (embodied in the sentence ’ s syntax tree).  Once we know a sentence ’ s phrase structure, we can use it to ascribe a meaning to that sentence.

1-38 Example: expression structure (1)  Consider this grammar (similar to Calc): expr=prim |expr ‘ + ’ prim |expr ‘ - ’ prim |expr ‘ + ’ prim prim=num |id |‘ ( ’ expr ‘ ) ’

1-39 Example: expression structure (2)  In this grammar, operators ‘ + ’, ‘ - ’, and ‘ * ’ all have the same precedence. E.g.: x-y*2 will be evaluated as (x-y)*2 prim expr prim id num expr y*2- prim id x expr

1-40 Example: expression structure (3)  But note that parentheses can always be used to control the evaluation: prim id num prim id expr prim expr ()y * 2-x

1-41 Example: expression structure (4)  Consider this different grammar: expr=term |expr ‘ + ’ term |expr ‘ - ’ term term=prim |term ‘ * ’ prim prim=num |id |‘ ( ’ expr ‘ ) ’  This grammar is typical of most PLs such as C and Java. It leads to a different phrase structure.

1-42 Example: expression structure (5)  In this grammar, operator ‘ * ’ has higher precedence than ‘ + ’ and ‘ - ’. E.g.: x-y*2 will be evaluated as x-(y*2) prim expr prim id num term y*2- id x term prim term expr

1-43 Ambiguity  A phrase is ambiguous if it has more than one syntax tree.  A grammar is ambiguous if any of its phrases is ambiguous.  Ambiguity is common in natural languages such as English: –The peasants are revolting. –Time flies like an arrow. Fruit flies like a banana.  The grammar of a PL should be unambiguous, otherwise the meaning of some programs would be uncertain.

1-44 Example: dangling “else” ambiguity (1)  Part of the grammar of a fictional PL: com=‘ put ’ expr |‘ if ’ expr ‘ then ’ com |‘ if ’ expr ‘ then ’ com ‘ else ’ com |…  This makes some if-commands ambiguous, such as: if b then if c then put 1 else put 2

1-45 Example: dangling “else” ambiguity (2)  The above if-command has two syntax trees: bifelsecifthen expr com put 1 com put 2 com bifc then expr com elseput 1 com put 2 com

1-46 ENBF notation  Extended Backus Naur Form (EBNF) is a combination of BNF and RE notation.  An EBNF production rule has the form: N = RE where RE is a regular expression, expressed in terms of both terminal and nonterminal symbols.  Example: sequential-command = ‘ { ’ command + ‘ } ’  EBNF is convenient for specifying all aspects of syntax.

1-47 Example: Calc syntax in EBNF (1)  Production rules: prog=com * eof com=‘ put ’ expr eol |‘ set ’ id ‘ = ’ expr eol expr=prim ( ‘ + ’ prim | ‘ - ’ prim | ‘ * ’ prim )* prim=num |id |‘ ( ’ expr ‘ ) ’

1-48 Example: Calc syntax in EBNF (2)  Production rules (continued): id=‘ a ’ | ‘ b ’ | ‘ c ’ | … | ‘ z ’ num=(‘ 0 ’ | ‘ 1 ’ | … | ‘ 9 ’) + eol=‘ \n ’