Saturday, February 23, 2013
Wednesday, February 13, 2013
Syntax vs Semantics
Semantics ~ Meaning
Syntax ~ Symbolic representation
So two programs written in different languages could do the same thing (semantics) but the symbols used to write the program would be different (syntax).
A compiler will check your syntax for you (compile-time errors), and derive the semantics from the language rules (mapping the syntax to machine instructions say), but won't find all the semantic errors (run-time errors, e.g. calculating the wrong result because the code says add 1 instead of add 2).
Actually there are not two levels but three:
- lexical level: how characters are combined to produce language elements (
i
andf
producesif
) - syntactical level: how language elements are combined to produce language expressions (
if
,(
,42
,==
,answer
and)
produces a conditional statement) - semantic level: how language expressions are converted to CPU instructions in order to form a meaning (a conditional statement allows to execute one branch or the other depending on the result of the boolean expression)
Syntax refers to formal rules governing the construction of valid statements in a language.
Semantics refers to the set of rules which give the meaning of a statement.
Semantics refers to the set of rules which give the meaning of a statement.
Sources: http://programmers.stackexchange.com/questions/113800/whats-the-difference-between-syntax-and-semantics
What Does Parsing Mean?
This may not be complete explanation but i find it helpful to understand:
Parsing is the process of analyzing text made of a sequence of tokens to determine its grammatical structure with respect to a given (more or less) formal grammar.
The parser then builds a data structure based on the tokens. This data structure can then be used by a compiler, interpreter or translator to create an executable program or library.
If I gave you an english sentence, and asked you to break down the sentence into its parts of speech (nouns, verbs, etc.), you would be parsing the sentence.
That's the simplest explanation of parsing I can think of.
That said, parsing is a non-trivial computational problem. You have to start with simple examples, and work your way up to the more complex.
Source: http://stackoverflow.com/questions/2933192/whats-the-best-way-to-explain-parsing-to-a-new-programmer
Subscribe to:
Posts (Atom)