|
|
|
|
|
|
|
|
|
|
|
|
Lexical Conventions
|
|
|
Since e language was developed based on other programming languages, Most of the syntax is more or less same as other programming language. So if you know lexical conventions of C++ or C, then you can follow e language without any problem.
|
|
|
|
|
|
|
|
|
|
|
|
File Structures
|
|
|
e files should have .e as extension.
|
|
|
|
|
|
Example
|
|
|
|
|
|
|
|
|
When the code size is big, it is better to have code organized into multiple files. This is same as any programming language.When importing other file in C++ or C language we use #include, in e language we use import filename, below example shows how it is done.
|
|
|
|
|
|
1 <'
2
3 import hello_world.e;
4 import memory;
5
6 // Rest of the code
7
8
9 '>
You could download file e_basics1.e
here
|
|
|
|
|
|
As you see, first file has .e extension and second file does not. Well in e language, we don't need to specify the extension of e file, the compiler assumes .e as extension.
|
|
|
|
|
|
Within file, we can have code segments. Beginning of code segment is marked with <' and end of code segment is marked with '> . And code that does not fall within this code segments are treated as comments
|
|
|
|
|
|
1 // Anything here is comment
2 <'
3 //Code here
4
5
6
7 '>
8
9 //This is also comment
10
11 <'
12 //Code continue
13
14 '>
You could download file e_basics2.e
here
|
|
|
|
|
|
White Spaces and Comments
|
|
|
White spaces are same as in any programming languages, you can refer to Verilog tutorial section if you need to know more on this.
|
|
|
|
|
|
As of comments, in e language, we can comment code in three ways
|
|
|
|
|
|
- // : This is same as in Verilog and C language
- -- : This is same as in VHDL language
- <' '> : This is block comment, any text that falls outside <' and '> is treated as comment.
|
|
|
|
|
|
1 <'
2 -- Single line comment
3 // This is also single line comment
4
5 //Code here
6
7 '>
8 Multipe line comment
9 So ignored
10
11 <'
12 //Code continue..
13
14 '>
You could download file e_basics3.e
here
|
|
|
|
|
|
Literals and Constants
|
|
|
Literals are numeric, character and string values. Following literals and constants are in e language.
|
|
|
|
|
|
- Unsized Numbers: As name implies, they are unsized, can be both positive and negative
- Hexadecimal numbers start with 0x
- Binary numbers start with 0b
- Octal number start with 0o
- Example : 32, 44, 0x20, 0b101010101, 0o11_11, 0xDEAD_BEEF, -1, -0x44
- Kilo or Muliple of 1024 : 1K, 10K
- Mega or 1024*1024 : 1M, 10M
- Sized Numbers:
- Hexadecimal numbers start with 'h
- Binary numbers start with 'b
- Decimal numbers start with 'd
- Octal number start with 'o
- If the value number is more than the specified size in bits, its most significant bits are ignored.
- If the value number is less that the specified size, it is padded by zeros.
- Example : 16'd32, 32'd44, 8'h20, 8'b0101_0101, 12'o1111, 32'hDEAD_BEEF, -4'h1
- Predefined Constants: There are few list of pre defined constants a below.
- TRUE For Boolean variables and expressions.
- FALSE For Boolean variables and expressions.
- NULL For structs, specifies a NULL pointer.
- NULL For structs, specifies a NULL pointer.
- MAX_INT Represents the largest 32-bit int (2^31 -1)
- MAX_INT Represents the largest 32-bit int (2^31 -1)
- MAX_UINT Represents the largest 32-bit uint (2^32 -1).
- Literal String:A literal string is a sequence of zero or more ASCII characters enclosed by double quotes (" ").
- Example : "This is sample string"
- Example : "" -Empty string
- Escape sequence in e is same as in any other programming lanuage \n, \t, \\ etc
- Literal Character: We really don't care about this type
|
|
|
|
|
|
1
2 <'
3 // Example of numeric values
4 struct abc {
5 data : int ;
6
7 my_method () is {
8 // Unsigned numbers
9 data = 0x1; // Hexadecimal
10 data = 33; // Decimal
11 data = 0b11111_00000;//Binary
12 data = 0o777_333; // Octal
13 // Signed numbers
14 data = 32'hDEAD_BEAF; // 32 bit Hexadecimal
15 data = 8'd33; // 8 bit decimal
16 data = 9'b1111_0000; // 8 bit binary
17 data = 18'o777_333; // 18 bit Octal
18 // Kilo and Mega
19 data = 1K; // 1024
20 data = 5M; // 1024*1024*5
21 };
22
23 };
24 '>
You could download file e_basics4.e
here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|