40 likes | 172 Views
Grammars. Grammars can get quite complex, but are essential. Syntax: the form of the text that is valid Semantics: the meaning of the form Sometimes semantics are needed to read syntax But, in this class we will keep things very simple…
E N D
Grammars • Grammars can get quite complex, but are essential. • Syntax: the form of the text that is valid • Semantics: the meaning of the form • Sometimes semantics are needed to read syntax • But, in this class we will keep things very simple… • Parsing: how to take a grammar and apply it to some input
Grammars • Grammar is important: • For understanding programming languages • Each language has a grammar • For dealing with input/output • Input/output usually obeys some rules • Parsing can vary in complexity • Reading very simple grammars often not even thought of as “parsing” • Our examples in this class get to a “moderate” level of complexity
Parsing • We saw examples of this previously with the calculator, and with some sentences in English. • Parsing is how you go from an input to something the computer can deal with.
Grammar/Parsing Example • Sentence: • Subject Verb Object • Subject Verb • Subject • Noun • Object • Adjective Object • Noun • Are these valid? • I read books • I read long books • I read long red books • Birds fly • Red birds fly • Birds fly fast