Upload
jose-enrique-alvarez-estrada
View
44
Download
0
Embed Size (px)
Citation preview
A grammar is a formulato build phrases
in a given language
The nature of the
language is
not important
Languages
ProgrammingLanguages
UML
Mind Maps
GraphicalLanguages
SymbolicLanguages
BooleanLogic
Python
NaturalLanguagesEnglish
Conceptual Maps
Java
Spanish
Math
There are two basic forms
to describe (document)
a grammar
Graphically → Syntax Diagrams
bubblesdescribes
lexems
bubblesdescribes
lexems
boxesdescribessyntagms
bubblesdescribes
lexems
boxesdescribessyntagms
arrowsdescribes
correct paths
a Compulsory (1 time)
a
a
Compulsory (1 time)
Optional (0 or 1 times)
a
b
a
a
Compulsory (1 time)
Optional (0 or 1 times)
Selection (“a” or “b”)
a
b
a
a
a
Compulsory (1 time)
Optional (0 or 1 times)
Selection (“a” or “b”)
Repetition (1 or more times)
a
b
a
a
a
a
Compulsory (1 time)
Optional (0 or 1 times)
Selection (“a” or “b”)
Repetition (1 or more times)
Repetition (0 or more times)
Textually → EBNF Notation
syntagm
syntagm lexem
syntagm lexem
is defined as
a
b
a
a
a
a
Compulsory (1 time)
Optional (0 or 1 times)
Selection (“a” or “b”)
Repetition (1 or more times)
Repetition (0 or more times)
[ a ]
a
[ a | b ]
{ a }+
{ a }*
for example...
<boolean_expr> ::= <boolean_term> | <boolean_expr> v <boolean_term>
<boolean_term> ::= <boolean_element> | <boolean_element> ^ <boolean_element>
<boolean_element> ::= true | false | variable |~ ( <boolean_expr> ) | ( <boolean_expr> )
~ A ^ B v A ^ ~ B
~ A ^ B v A ^ ~ B
we run theexpression from
left to right
~ A ^ B v A ^ ~ B
negationfirst
~
~ A ^ B v A ^ ~ B
~
A ^ B v A ^ ~ B
~
A ^ B v A ^ ~ B
then the othernegation
~
A ^ B v A ^ ~ B
~
~
A ^ B v A ^ B
~
~
A ^ B v A ^ B
~
thenthe ANDconjuntion
~
^
A ^ B v A ^ B
~
~
^
A B v A ^ B
~
~
^
A B v A ^ B
~
and the otherAND
conjunción
~
^
A B v A ^ B
~
^
~
^
A B v A B
~
^
~
^
A B v A B
~
^The OR
disyuntionat the last
~
^
A B v A B
~
^
v
~
^
A B A B
~
^
v
~
^
A B A B
~
^
v finishedtree!
~
^
A B A B
~
^
v
Homework
Define a simple grammar for the sentences in English. Then test it with this phrases:
My friend runs slowly.The cat ate a mouse.