And that have the correct meaning according

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the words are correct. In a parser level there is an error. According with the “grammar” of the language the “{“ and “}” are misplaced. Example 2. Consider the following code in Java int x = “hello”; In a lexical and parser level this code is correct. However, in a semantic level it is not correct due to the fact there is an integer variable that is being assigned with a String value. Example 3. These are examples of lexical level. int @x = 7; - - a variable can not start with a “@” int x = 77_; - - a number can not end with a “_” float x = 7.7.5; - - the format of the number is not correct. Example 4. main ( ) { x = 5; } There are 9 words in the code. Lexically there is not a problem. Now in term of syntax (grammar), there is not a problem either, all the words are in the correct order and are following the rules of combining words. In terms of semantic (meaning) there is a mistake. It is not possible to know the meaning of the code because it is not complete; there is not a defined type for variable “x”. main ( ) { foo (1,2); x = 5; } imagine we have the declaration of the foo method –> foo (int x) { } The problem with this piece of code is in a semantic level, due to the fact that according with the definition of the foo method, it is expected to have only one parameter and not two. Once you understand the original program (text) then it is possible to translate. The most complex thing to do is understand the code. 4. Language Paradigms What make a programing language different from another are the rules that define the language. For example, for the case of an object- oriented language the main difference is that it has classes to define and handle objects. Classes are a particular kind of rule for object- oriented programming languages that differentiate them from other types of languages. 5. Project course For the course, we will be developing an imperative programing language (these are the simple ones). In order to implement the compiler for this programming language we are going to use an object- oriented language. CSE 340 Principles of Programming Languages Summer...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online