├── .gitignore
├── bin
├── build.sh
├── oberonc
├── gas
│ ├── as.exe
│ ├── crt2.o
│ ├── ld.exe
│ ├── crtend.o
│ ├── crtbegin.o
│ └── lib
│ │ ├── libgcc.a
│ │ ├── libmingw32.a
│ │ ├── libmsvcrt.a
│ │ └── libkernel32.a
├── oberonc.exe
├── run.cmd
├── assemble.cmd
├── build.cmd
└── HowToUse.txt
├── Semantica.pdf
├── Oberon-0 (BNF).pdf
├── resources
├── minus.gif
├── plus.gif
├── bullet.gif
└── mktree.css
├── samples
├── P0.OBE
├── tests
│ ├── P0.OBE
│ ├── P1.OBE
│ ├── P2.OBE
│ ├── P3.OBE
│ ├── p16.OBE
│ ├── p17.OBE
│ ├── p18.OBE
│ ├── P9.OBE
│ ├── P4.OBE
│ ├── P7.OBE
│ ├── P8.OBE
│ ├── p14.OBE
│ ├── p15.OBE
│ ├── p19.OBE
│ ├── P10.OBE
│ ├── P12.OBE
│ ├── P5.OBE
│ ├── P6.OBE
│ ├── P13.OBE
│ ├── P11.OBE
│ ├── p20.OBE
│ ├── P25.OBE
│ ├── P26.OBE
│ ├── p21.OBE
│ ├── p27.OBE
│ └── p28.OBE
├── P1.OBE
├── P2.OBE
├── P3.OBE
├── p16.OBE
├── p17.OBE
├── p18.OBE
├── P9.OBE
├── P7.OBE
├── P8.OBE
├── p19.OBE
├── P10.OBE
├── P4.OBE
├── P12.OBE
├── p14.OBE
├── p15.OBE
├── p22.OBE
├── P13.OBE
├── P5.OBE
├── P11.OBE
├── p20.OBE
├── P6.OBE
├── P25.OBE
├── P26.OBE
├── p21.OBE
├── p27.OBE
├── p28.OBE
├── p23.OBE
└── P29.obe
├── source
├── parser
│ ├── yy_parser.y
│ ├── yy_parser.cpp
│ ├── parser_exception.h
│ ├── parser_exception.cpp
│ └── parser.h
├── scanner
│ ├── scanner_lex.l
│ ├── scanner_lex.cpp
│ ├── scanner_exception.h
│ ├── scanner_exception.cpp
│ └── token_type.h
├── oberonc
│ ├── oberonc_exception.h
│ └── oberonc_exception.cpp
├── code_generator
│ ├── code_generator_exception.h
│ ├── machine
│ │ ├── mips_architecture.cpp
│ │ ├── x86_architecture.cpp
│ │ ├── register_descriptor.h
│ │ ├── variable_descriptor.h
│ │ └── basic_block.h
│ ├── intermediate
│ │ ├── instruction
│ │ │ ├── instruction.h
│ │ │ ├── nop_instruction.h
│ │ │ ├── goto_instruction.h
│ │ │ ├── return_instruction.h
│ │ │ ├── write_instruction.h
│ │ │ ├── read_instruction.h
│ │ │ ├── parameter_instruction.h
│ │ │ ├── instruction.cpp
│ │ │ ├── copy_instruction.h
│ │ │ ├── negation_instruction.h
│ │ │ ├── nop_instruction.cpp
│ │ │ ├── call_instruction.h
│ │ │ └── conditional_goto_instruction.h
│ │ └── instruction_argument
│ │ │ ├── label_argument.cpp
│ │ │ ├── instruction_argument.cpp
│ │ │ ├── label_argument.h
│ │ │ ├── immediate_argument.h
│ │ │ ├── string_argument.h
│ │ │ ├── instruction_label.h
│ │ │ ├── function_label.h
│ │ │ ├── identifier_argument.h
│ │ │ ├── temporary_argument.h
│ │ │ ├── argument_information.h
│ │ │ ├── identifier_argument.cpp
│ │ │ ├── instruction_label.cpp
│ │ │ ├── immediate_argument.cpp
│ │ │ ├── instruction_argument.h
│ │ │ ├── temporary_argument.cpp
│ │ │ ├── string_argument.cpp
│ │ │ └── function_label.cpp
│ └── code_generator_exception.cpp
├── ast
│ ├── node.cpp
│ ├── declaration
│ │ ├── declaration_node.cpp
│ │ ├── skip_declaration_node.h
│ │ ├── skip_declaration_node.cpp
│ │ ├── constant_list_node.h
│ │ ├── variable_list_node.h
│ │ ├── declaration_node.h
│ │ ├── variable_node.h
│ │ ├── module_node.h
│ │ ├── declaration_sequence_node.h
│ │ ├── formal_parameter_list_node.h
│ │ ├── formal_parameter_node.h
│ │ ├── constant_node.h
│ │ └── function_node.h
│ ├── expression
│ │ ├── arithmetic_operator.h
│ │ ├── relational_operator.h
│ │ ├── not_node.h
│ │ ├── negation_node.h
│ │ ├── boolean_literal_node.h
│ │ ├── string_literal_node.h
│ │ ├── and_node.h
│ │ ├── or_node.h
│ │ ├── integer_literal_node.h
│ │ ├── arithmetic_node.h
│ │ ├── relational_node.h
│ │ ├── arithmetic_operator.cpp
│ │ ├── actual_parameter_list_node.h
│ │ ├── function_call_node.h
│ │ └── identifier_node.h
│ └── statement
│ │ ├── write_line_node.h
│ │ ├── skip_statement_node.h
│ │ ├── break_node.h
│ │ ├── continue_node.h
│ │ ├── write_node.h
│ │ ├── pre_test_loop_node.h
│ │ ├── post_test_loop_node.h
│ │ ├── read_node.h
│ │ ├── return_node.h
│ │ ├── skip_statement_node.cpp
│ │ ├── assignment_node.h
│ │ ├── procedure_call_node.h
│ │ ├── statement_sequence_node.h
│ │ ├── conditional_node.h
│ │ ├── write_line_node.cpp
│ │ └── loop_node.h
├── debugger
│ ├── debugger_interfaces.h
│ ├── debugger_utils.h
│ ├── debugger_interfaces
│ │ ├── code_generator_debugger.h
│ │ ├── ast_debugger.h
│ │ └── symbol_table_debugger.h
│ ├── debugger_implementations
│ │ ├── simple_code_generator_debugger.h
│ │ ├── simple_ast_debugger.h
│ │ ├── simple_parser_debugger.h
│ │ ├── formatted_ast_debugger.h
│ │ ├── simple_scanner_debugger.h
│ │ └── simple_symbol_table_debugger.h
│ ├── debugger.h
│ ├── debugger.cpp
│ └── debugger_utils.cpp
├── README.txt
├── global
│ └── global.cpp
└── symbol_table
│ ├── identifier_category
│ ├── module_information.h
│ ├── temporary_information.h
│ ├── variable_information.h
│ ├── formal_parameter_information.h
│ ├── constant_information.h
│ ├── temporary_information.cpp
│ ├── module_information.cpp
│ ├── function_information.h
│ ├── identifier_category_type.h
│ └── identifier_category_type.cpp
│ ├── data_type.cpp
│ ├── data_type.h
│ └── scope.h
├── clean_linux.sh
├── clean.cmd
├── pre_build.cmd
└── README.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *.o
3 |
--------------------------------------------------------------------------------
/bin/build.sh:
--------------------------------------------------------------------------------
1 | ./oberonc $1 -x86
2 | gcc "${1%%.*}.s" -o "${1%%.*}"
3 |
--------------------------------------------------------------------------------
/bin/oberonc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/oberonc
--------------------------------------------------------------------------------
/Semantica.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/Semantica.pdf
--------------------------------------------------------------------------------
/bin/gas/as.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/gas/as.exe
--------------------------------------------------------------------------------
/bin/gas/crt2.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/gas/crt2.o
--------------------------------------------------------------------------------
/bin/gas/ld.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/gas/ld.exe
--------------------------------------------------------------------------------
/bin/gas/crtend.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/gas/crtend.o
--------------------------------------------------------------------------------
/bin/oberonc.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/oberonc.exe
--------------------------------------------------------------------------------
/Oberon-0 (BNF).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/Oberon-0 (BNF).pdf
--------------------------------------------------------------------------------
/bin/gas/crtbegin.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/gas/crtbegin.o
--------------------------------------------------------------------------------
/resources/minus.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/resources/minus.gif
--------------------------------------------------------------------------------
/resources/plus.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/resources/plus.gif
--------------------------------------------------------------------------------
/bin/gas/lib/libgcc.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/gas/lib/libgcc.a
--------------------------------------------------------------------------------
/resources/bullet.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/resources/bullet.gif
--------------------------------------------------------------------------------
/bin/gas/lib/libmingw32.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/gas/lib/libmingw32.a
--------------------------------------------------------------------------------
/bin/gas/lib/libmsvcrt.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/gas/lib/libmsvcrt.a
--------------------------------------------------------------------------------
/samples/P0.OBE:
--------------------------------------------------------------------------------
1 | module Programa0;
2 | begin
3 | writeln("Hello World!");
4 | end Programa0.
--------------------------------------------------------------------------------
/bin/gas/lib/libkernel32.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/bin/gas/lib/libkernel32.a
--------------------------------------------------------------------------------
/samples/tests/P0.OBE:
--------------------------------------------------------------------------------
1 | module Programa0;
2 | begin
3 | writeln("Hello World!");
4 | end Programa0.
--------------------------------------------------------------------------------
/source/parser/yy_parser.y:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/parser/yy_parser.y
--------------------------------------------------------------------------------
/source/parser/yy_parser.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/parser/yy_parser.cpp
--------------------------------------------------------------------------------
/source/scanner/scanner_lex.l:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/scanner/scanner_lex.l
--------------------------------------------------------------------------------
/source/scanner/scanner_lex.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/scanner/scanner_lex.cpp
--------------------------------------------------------------------------------
/source/oberonc/oberonc_exception.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/oberonc/oberonc_exception.h
--------------------------------------------------------------------------------
/source/parser/parser_exception.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/parser/parser_exception.h
--------------------------------------------------------------------------------
/source/scanner/scanner_exception.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/scanner/scanner_exception.h
--------------------------------------------------------------------------------
/source/oberonc/oberonc_exception.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/oberonc/oberonc_exception.cpp
--------------------------------------------------------------------------------
/source/scanner/scanner_exception.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/scanner/scanner_exception.cpp
--------------------------------------------------------------------------------
/samples/P1.OBE:
--------------------------------------------------------------------------------
1 | module Programa1;
2 | var a, b : integer;
3 |
4 | begin
5 | a := 77;
6 | b := a;
7 | writeln(b);
8 | end Programa1.
--------------------------------------------------------------------------------
/samples/tests/P1.OBE:
--------------------------------------------------------------------------------
1 | module Programa1;
2 | var a, b : integer;
3 |
4 | begin
5 | a := 77;
6 | b := a;
7 | writeln(b);
8 | end Programa1.
--------------------------------------------------------------------------------
/source/code_generator/code_generator_exception.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/code_generator/code_generator_exception.h
--------------------------------------------------------------------------------
/source/code_generator/machine/mips_architecture.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/code_generator/machine/mips_architecture.cpp
--------------------------------------------------------------------------------
/source/code_generator/machine/x86_architecture.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/code_generator/machine/x86_architecture.cpp
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/instruction.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rcorcs/OberonC/HEAD/source/code_generator/intermediate/instruction/instruction.h
--------------------------------------------------------------------------------
/samples/P2.OBE:
--------------------------------------------------------------------------------
1 | module Programa2;
2 | var a : integer;
3 | begin
4 | write("Digite um valor: ");
5 | read( a );
6 | write("O valor digitado foi ");
7 | writeln( a );
8 | end Programa2.
9 |
--------------------------------------------------------------------------------
/samples/tests/P2.OBE:
--------------------------------------------------------------------------------
1 | module Programa2;
2 | var a : integer;
3 | begin
4 | write("Digite um valor: ");
5 | read( a );
6 | write("O valor digitado foi ");
7 | writeln( a );
8 | end Programa2.
9 |
--------------------------------------------------------------------------------
/samples/P3.OBE:
--------------------------------------------------------------------------------
1 | module Programa2;
2 | var a, b, c : integer;
3 | begin
4 | a := 2;
5 | b := 4 + 4 + a;
6 | c := a + b;
7 | writeln(a);
8 | writeln(b);
9 | writeln(c);
10 | end Programa2.
11 |
--------------------------------------------------------------------------------
/clean_linux.sh:
--------------------------------------------------------------------------------
1 | clear
2 |
3 | rm bin/oberonc
4 |
5 | rm source/scanner/scanner_lex.cpp
6 |
7 | rm source/parser/yy_parser.cpp
8 | rm source/parser/yy_parser.h
9 | rm source/parser/yy_parser.output
10 |
11 |
--------------------------------------------------------------------------------
/samples/tests/P3.OBE:
--------------------------------------------------------------------------------
1 | module Programa2;
2 | var a, b, c : integer;
3 | begin
4 | a := 2;
5 | b := 4 + 4 + a;
6 | c := a + b;
7 | writeln(a);
8 | writeln(b);
9 | writeln(c);
10 | end Programa2.
11 |
--------------------------------------------------------------------------------
/samples/p16.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a : boolean;
3 |
4 | begin
5 | a := false;
6 |
7 | if( a ) then
8 | writeln("true");
9 | else
10 | writeln("false");
11 | end;
12 |
13 | end Programa9.
14 |
--------------------------------------------------------------------------------
/samples/tests/p16.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a : boolean;
3 |
4 | begin
5 | a := false;
6 |
7 | if( a ) then
8 | writeln("true");
9 | else
10 | writeln("false");
11 | end;
12 |
13 | end Programa9.
14 |
--------------------------------------------------------------------------------
/samples/p17.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a : boolean;
3 |
4 | begin
5 | a := true;
6 |
7 | if( a and ( not a )) then
8 | writeln("true");
9 | else
10 | writeln("false");
11 | end;
12 |
13 | end Programa9.
14 |
--------------------------------------------------------------------------------
/samples/p18.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a : boolean;
3 |
4 | begin
5 | a := true;
6 |
7 | if( a or ( not a )) then
8 | writeln("true");
9 | else
10 | writeln("false");
11 | end;
12 |
13 | end Programa9.
14 |
--------------------------------------------------------------------------------
/samples/P9.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : integer;
3 |
4 | begin
5 | write("Digite um numero: ");
6 | read(a);
7 |
8 | while ( a >= 0) do
9 | writeln(a);
10 | a := a - 1;
11 | end;
12 |
13 | end Programa9.
14 |
--------------------------------------------------------------------------------
/samples/tests/p17.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a : boolean;
3 |
4 | begin
5 | a := true;
6 |
7 | if( a and ( not a )) then
8 | writeln("true");
9 | else
10 | writeln("false");
11 | end;
12 |
13 | end Programa9.
14 |
--------------------------------------------------------------------------------
/samples/tests/p18.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a : boolean;
3 |
4 | begin
5 | a := true;
6 |
7 | if( a or ( not a )) then
8 | writeln("true");
9 | else
10 | writeln("false");
11 | end;
12 |
13 | end Programa9.
14 |
--------------------------------------------------------------------------------
/clean.cmd:
--------------------------------------------------------------------------------
1 | cls
2 |
3 | del bin\oberonc.exe
4 |
5 | del source\scanner\scanner_lex.cpp
6 |
7 | del source\parser\yy_parser.cpp
8 | del source\parser\yy_parser.h
9 | del source\parser\yy_parser.output
10 |
11 | pause
12 |
13 |
--------------------------------------------------------------------------------
/samples/tests/P9.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : integer;
3 |
4 | begin
5 | write("Digite um numero: ");
6 | read(a);
7 |
8 | while ( a >= 0) do
9 | writeln(a);
10 | a := a - 1;
11 | end;
12 |
13 | end Programa9.
14 |
--------------------------------------------------------------------------------
/samples/P7.OBE:
--------------------------------------------------------------------------------
1 | module Programa5;
2 | var a, b : integer;
3 |
4 | function test() : integer;
5 | begin
6 | return 5;
7 | end test;
8 |
9 | begin
10 | a := test();
11 | b := a;
12 | writeln(a);
13 | writeln(b);
14 | end Programa5.
15 |
--------------------------------------------------------------------------------
/samples/tests/P4.OBE:
--------------------------------------------------------------------------------
1 | module Programa4;
2 | var a, b, c, d : integer;
3 | begin
4 | a := 2;
5 | b := 4 + 4 + a;
6 | c := a + b;
7 | d := c / 4;
8 | writeln(a);
9 | writeln(b);
10 | writeln(c);
11 | writeln(d);
12 | end Programa4.
13 |
--------------------------------------------------------------------------------
/samples/P8.OBE:
--------------------------------------------------------------------------------
1 | module Programa8;
2 | var a, b : integer;
3 |
4 | begin
5 | write("Digite um numero: ");
6 | read(a);
7 | if(a>10) then
8 | b := 1;
9 | else
10 | b := 2;
11 | end;
12 | writeln(a);
13 | writeln(b);
14 | end Programa8.
15 |
--------------------------------------------------------------------------------
/samples/p19.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : boolean;
3 |
4 | begin
5 | a := true;
6 | b := ( a and ( not a ));
7 |
8 | if ( a or b ) then
9 | writeln("true");
10 | else
11 | writeln("false");
12 | end;
13 |
14 | end Programa9.
15 |
--------------------------------------------------------------------------------
/samples/tests/P7.OBE:
--------------------------------------------------------------------------------
1 | module Programa5;
2 | var a, b : integer;
3 |
4 | function test() : integer;
5 | begin
6 | return 5;
7 | end test;
8 |
9 | begin
10 | a := test();
11 | b := a;
12 | writeln(a);
13 | writeln(b);
14 | end Programa5.
15 |
--------------------------------------------------------------------------------
/samples/P10.OBE:
--------------------------------------------------------------------------------
1 | module Programa10;
2 | var a : integer;
3 |
4 | procedure println( x : integer );
5 | begin
6 | writeln(x);
7 | end println;
8 |
9 | begin
10 | write("Digite um numero: ");
11 | read( a );
12 | println( a );
13 | end Programa10.
14 |
--------------------------------------------------------------------------------
/samples/tests/P8.OBE:
--------------------------------------------------------------------------------
1 | module Programa8;
2 | var a, b : integer;
3 |
4 | begin
5 | write("Digite um numero: ");
6 | read(a);
7 | if(a>10) then
8 | b := 1;
9 | else
10 | b := 2;
11 | end;
12 | writeln(a);
13 | writeln(b);
14 | end Programa8.
15 |
--------------------------------------------------------------------------------
/samples/tests/p14.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : integer;
3 |
4 | begin
5 | read(a);
6 |
7 | while ( a >= 0) do
8 | if( a = 2 ) then
9 | break;
10 | end;
11 | writeln(a);
12 | a := a - 1;
13 | end;
14 |
15 | end Programa9.
16 |
--------------------------------------------------------------------------------
/samples/tests/p15.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : integer;
3 |
4 | begin
5 | read(a);
6 |
7 | while ( a >= 0) do
8 | a := a - 1;
9 | if( a = 2 ) then
10 | continue;
11 | end;
12 | writeln(a);
13 | end;
14 |
15 | end Programa9.
16 |
--------------------------------------------------------------------------------
/samples/tests/p19.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : boolean;
3 |
4 | begin
5 | a := true;
6 | b := ( a and ( not a ));
7 |
8 | if ( a or b ) then
9 | writeln("true");
10 | else
11 | writeln("false");
12 | end;
13 |
14 | end Programa9.
15 |
--------------------------------------------------------------------------------
/samples/tests/P10.OBE:
--------------------------------------------------------------------------------
1 | module Programa10;
2 | var a : integer;
3 |
4 | procedure println( x : integer );
5 | begin
6 | writeln(x);
7 | end println;
8 |
9 | begin
10 | write("Digite um numero: ");
11 | read( a );
12 | println( a );
13 | end Programa10.
14 |
--------------------------------------------------------------------------------
/samples/P4.OBE:
--------------------------------------------------------------------------------
1 | module Programa4;
2 | var a, b, c, d, e : integer;
3 | begin
4 | a := 2;
5 | b := 4 + 4 + a;
6 | c := a + b;
7 | d := c / 4;
8 | e := c * 4;
9 | writeln(a);
10 | writeln(b);
11 | writeln(c);
12 | writeln(d);
13 | writeln(e);
14 | end Programa4.
15 |
--------------------------------------------------------------------------------
/samples/P12.OBE:
--------------------------------------------------------------------------------
1 | module Programa10;
2 | var a : integer;
3 |
4 | procedure println();
5 | var x : integer;
6 | begin
7 | x := 2;
8 | writeln(x);
9 | end println;
10 |
11 | begin
12 | //write("Digite um numero: ");
13 | //read( a );
14 | println();
15 | end Programa10.
16 |
--------------------------------------------------------------------------------
/samples/p14.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : integer;
3 |
4 | begin
5 | write("Digite um numero: ");
6 | read(a);
7 |
8 | while ( a >= 0) do
9 | if( a = 2 ) then
10 | break;
11 | end;
12 | writeln(a);
13 | a := a - 1;
14 | end;
15 |
16 | end Programa9.
17 |
--------------------------------------------------------------------------------
/samples/p15.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : integer;
3 |
4 | begin
5 | write("Digite um numero: ");
6 | read(a);
7 |
8 | while ( a >= 0) do
9 | a := a - 1;
10 | if( a = 2 ) then
11 | continue;
12 | end;
13 | writeln(a);
14 | end;
15 |
16 | end Programa9.
17 |
--------------------------------------------------------------------------------
/samples/tests/P12.OBE:
--------------------------------------------------------------------------------
1 | module Programa10;
2 | var a : integer;
3 |
4 | procedure println();
5 | var x : integer;
6 | begin
7 | x := 2;
8 | writeln(x);
9 | end println;
10 |
11 | begin
12 | //write("Digite um numero: ");
13 | //read( a );
14 | println();
15 | end Programa10.
16 |
--------------------------------------------------------------------------------
/samples/p22.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b, i : integer;
3 |
4 | begin
5 |
6 | write("Inicial: ");
7 | read(a);
8 |
9 | write("Final: ");
10 | read(b);
11 |
12 | for i := a To b Do
13 | write("i: ");
14 | writeln(i);
15 | end;
16 |
17 | end Programa9.
18 |
--------------------------------------------------------------------------------
/samples/tests/P5.OBE:
--------------------------------------------------------------------------------
1 | module Programa5;
2 | var a, b, c, d : integer;
3 |
4 | procedure P1();
5 | begin
6 | a := 2;
7 | b := 4 + 4 + a;
8 | c := a + b;
9 | d := c / 4;
10 | end P1;
11 |
12 | begin
13 | P1();
14 | writeln(a);
15 | writeln(b);
16 | writeln(c);
17 | writeln(d);
18 | end Programa5.
19 |
--------------------------------------------------------------------------------
/samples/tests/P6.OBE:
--------------------------------------------------------------------------------
1 | module Programa5;
2 | var a, b, c, d : integer;
3 |
4 | procedure P1();
5 | begin
6 | a := 2;
7 | b := 4 + 4 + a;
8 | c := a + b;
9 | d := c / 4;
10 | end P1;
11 |
12 | begin
13 | P1();
14 | writeln(a);
15 | writeln(b);
16 | writeln(c);
17 | writeln(d);
18 | end Programa5.
19 |
--------------------------------------------------------------------------------
/samples/P13.OBE:
--------------------------------------------------------------------------------
1 | module Programa10;
2 | var a, b : integer;
3 |
4 | procedure swap();
5 | var x, y : integer;
6 | begin
7 | x := b;
8 | y := a;
9 | a := x;
10 | b := y;
11 | end swap;
12 |
13 | begin
14 | a := 2;
15 | b := 7;
16 | swap();
17 | writeln( a );
18 | writeln( b );
19 | end Programa10.
20 |
--------------------------------------------------------------------------------
/samples/tests/P13.OBE:
--------------------------------------------------------------------------------
1 | module Programa10;
2 | var a, b : integer;
3 |
4 | procedure swap();
5 | var x, y : integer;
6 | begin
7 | x := b;
8 | y := a;
9 | a := x;
10 | b := y;
11 | end swap;
12 |
13 | begin
14 | a := 2;
15 | b := 7;
16 | swap();
17 | writeln( a );
18 | writeln( b );
19 | end Programa10.
20 |
--------------------------------------------------------------------------------
/samples/P5.OBE:
--------------------------------------------------------------------------------
1 | module Programa5;
2 | var a, b, c, d, e : integer;
3 |
4 | procedure P1();
5 | begin
6 | a := 2;
7 | b := 4 + 4 + a;
8 | c := a + b;
9 | d := c / 4;
10 | E := c * 4;
11 | end P1;
12 |
13 | begin
14 | P1();
15 | writeln(a);
16 | writeln(b);
17 | writeln(c);
18 | writeln(d);
19 | writeln(E);
20 | end Programa5.
21 |
--------------------------------------------------------------------------------
/samples/P11.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b, c : integer;
3 |
4 | function somar ( x, y : integer ) :integer;
5 | begin
6 | return( x + y );
7 | end somar;
8 |
9 | begin
10 | write("Digite um numero: ");
11 | read( a );
12 | write("Digite um numero: ");
13 | read( b );
14 |
15 | c := somar(a, b);
16 |
17 | write("A soma eh: ");
18 | writeln( c );
19 | end Programa9.
20 |
--------------------------------------------------------------------------------
/samples/p20.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : boolean;
3 |
4 | procedure printBool( bool: boolean );
5 | begin
6 | if bool then
7 | writeln("true");
8 | else
9 | writeln("false");
10 | end;
11 | end printBool;
12 |
13 | begin
14 | a := true;
15 | b := ( a and ( not a ));
16 |
17 | printBool ( a );
18 | printBool ( b );
19 | printBool ( a or b );
20 |
21 | end Programa9.
22 |
--------------------------------------------------------------------------------
/samples/tests/P11.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b, c : integer;
3 |
4 | function somar ( x, y : integer ) :integer;
5 | begin
6 | return( x + y );
7 | end somar;
8 |
9 | begin
10 | write("Digite um numero: ");
11 | read( a );
12 | write("Digite um numero: ");
13 | read( b );
14 |
15 | c := somar(a, b);
16 |
17 | write("A soma eh: ");
18 | writeln( c );
19 | end Programa9.
20 |
--------------------------------------------------------------------------------
/samples/P6.OBE:
--------------------------------------------------------------------------------
1 | module Programa6;
2 | var a, b, c, d, e : integer;
3 |
4 | procedure P1();
5 | begin
6 | a := 2;
7 | b := 4 + 4 + a;
8 | c := a + b;
9 | d := c / 4;
10 | E := c * 4;
11 | end P1;
12 |
13 | procedure P2();
14 | begin
15 | writeln(a);
16 | writeln(b);
17 | writeln(c);
18 | writeln(d);
19 | writeln(E);
20 | end p2;
21 |
22 | begin
23 | P1();
24 | p2();
25 | end Programa6.
--------------------------------------------------------------------------------
/samples/P25.OBE:
--------------------------------------------------------------------------------
1 | module Programa5;
2 | var a, b : integer;
3 |
4 | function factorial( val: integer) : integer;
5 | begin
6 | if( val <= 1 ) then
7 | return 1;
8 | else
9 | return( val * factorial(val-1) );
10 | end;
11 | end factorial;
12 |
13 | begin
14 | write("Digite um numero: ");
15 | read(b);
16 | a := factorial(b);
17 | write("fatorial: ");
18 | writeln(a);
19 | end Programa5.
20 |
--------------------------------------------------------------------------------
/samples/P26.OBE:
--------------------------------------------------------------------------------
1 | module Programa5;
2 | var a, b : integer;
3 |
4 | function somatorio( val: integer) : integer;
5 | begin
6 | if( val >= 0 ) then
7 | return( val + somatorio(val-1) );
8 | else
9 | return 0;
10 | end;
11 | end somatorio;
12 |
13 | begin
14 | write("Digite um numero: ");
15 | read(b);
16 | a := somatorio(b);
17 | write("somatorio: ");
18 | writeln(a);
19 | end Programa5.
20 |
--------------------------------------------------------------------------------
/samples/tests/p20.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : boolean;
3 |
4 | procedure printBool( bool: boolean );
5 | begin
6 | if bool then
7 | writeln("true");
8 | else
9 | writeln("false");
10 | end;
11 | end printBool;
12 |
13 | begin
14 | a := true;
15 | b := ( a and ( not a ));
16 |
17 | printBool ( a );
18 | printBool ( b );
19 | printBool ( a or b );
20 |
21 | end Programa9.
22 |
--------------------------------------------------------------------------------
/samples/tests/P25.OBE:
--------------------------------------------------------------------------------
1 | module Programa5;
2 | var a, b : integer;
3 |
4 | function factorial( val: integer) : integer;
5 | begin
6 | if( val <= 1 ) then
7 | return 1;
8 | else
9 | return( val * factorial(val-1) );
10 | end;
11 | end factorial;
12 |
13 | begin
14 | write("Digite um numero: ");
15 | read(b);
16 | a := factorial(b);
17 | write("fatorial: ");
18 | writeln(a);
19 | end Programa5.
20 |
--------------------------------------------------------------------------------
/samples/tests/P26.OBE:
--------------------------------------------------------------------------------
1 | module Programa5;
2 | var a, b : integer;
3 |
4 | function somatorio( val: integer) : integer;
5 | begin
6 | if( val >= 0 ) then
7 | return( val + somatorio(val-1) );
8 | else
9 | return 0;
10 | end;
11 | end somatorio;
12 |
13 | begin
14 | write("Digite um numero: ");
15 | read(b);
16 | a := somatorio(b);
17 | write("somatorio: ");
18 | writeln(a);
19 | end Programa5.
20 |
--------------------------------------------------------------------------------
/pre_build.cmd:
--------------------------------------------------------------------------------
1 | cls
2 |
3 | del bin\oberonc.exe
4 |
5 | del source\scanner\scanner_lex.cpp
6 |
7 | del source\parser\yy_parser.cpp
8 | del source\parser\yy_parser.h
9 | del source\parser\yy_parser.output
10 |
11 | cd source/parser
12 | bison -t --report=solved --warnings=error yy_parser.y --output=yy_parser.cpp --defines=yy_parser.h
13 |
14 |
15 | cd ../scanner
16 | flex -oscanner_lex.cpp -i scanner_lex.l
17 |
18 | pause
19 |
--------------------------------------------------------------------------------
/bin/run.cmd:
--------------------------------------------------------------------------------
1 | :: ******************************************
2 | :: *
3 | :: * Copyright 2011 ROCHA, Rodrigo C. O.
4 | :: *
5 | :: ******************************************
6 |
7 | @echo off
8 | echo Executable File Name (without the extension file .exe):
9 | set /p Input=
10 |
11 | if not exist "%Input%.exe" (goto EXE_ERROR)
12 |
13 | :RUN
14 | %Input%
15 | goto END
16 |
17 | :EXE_ERROR
18 | ECHO File "%Input%.exe" was not found
19 | goto END
20 |
21 | :END
22 | pause
--------------------------------------------------------------------------------
/samples/p21.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : boolean;
3 |
4 | procedure printBool( bool: boolean );
5 | begin
6 | if bool then
7 | writeln("true");
8 | else
9 | writeln("false");
10 | end;
11 | end printBool;
12 |
13 | function negate( bool: boolean ): boolean;
14 | begin
15 | return not bool;
16 | end negate;
17 |
18 | begin
19 | a := true;
20 | b := negate( a );
21 |
22 | printBool ( a );
23 | printBool ( b );
24 | printBool ( a or b );
25 | printBool ( a and b );
26 | printBool ( not b );
27 |
28 | end Programa9.
29 |
--------------------------------------------------------------------------------
/samples/tests/p21.OBE:
--------------------------------------------------------------------------------
1 | module Programa9;
2 | var a, b : boolean;
3 |
4 | procedure printBool( bool: boolean );
5 | begin
6 | if bool then
7 | writeln("true");
8 | else
9 | writeln("false");
10 | end;
11 | end printBool;
12 |
13 | function negate( bool: boolean ): boolean;
14 | begin
15 | return not bool;
16 | end negate;
17 |
18 | begin
19 | a := true;
20 | b := negate( a );
21 |
22 | printBool ( a );
23 | printBool ( b );
24 | printBool ( a or b );
25 | printBool ( a and b );
26 | printBool ( not b );
27 |
28 | end Programa9.
29 |
--------------------------------------------------------------------------------
/source/ast/node.cpp:
--------------------------------------------------------------------------------
1 | #include "node.h"
2 |
3 | Node::Node(const NodeType nodeType)
4 | {
5 | setNodeType(nodeType);
6 | }
7 |
8 | Node::~Node()
9 | {
10 |
11 | }
12 |
13 | NodeType Node::getNodeType() const
14 | {
15 | return this->nodeType_;
16 | }
17 |
18 | void Node::setNodeType(const NodeType nodeType)
19 | {
20 | this->nodeType_ = nodeType;
21 | }
22 |
23 | int Node::getFirstLine() const
24 | {
25 |
26 | return this->firstLine_;
27 | }
28 |
29 | void Node::setFirstLine(int firstLine)
30 | {
31 |
32 | this->firstLine_ = firstLine;
33 | }
34 |
--------------------------------------------------------------------------------
/samples/p27.OBE:
--------------------------------------------------------------------------------
1 | module Programa11;
2 | var
3 | num, n, r : Integer;
4 |
5 | function fibonacci(num: Integer): Integer;
6 | var
7 | x: Integer;
8 | begin
9 |
10 | if num = 0 then
11 | return 0;
12 | elsif num = 1 then
13 | return 1;
14 | else
15 | x := fibonacci(num - 1);
16 | x := x + fibonacci(num - 2);
17 | return x;
18 | end;
19 |
20 | end fibonacci;
21 |
22 | begin
23 | write("N = ");
24 | read(n);
25 |
26 | r := fibonacci(n);
27 |
28 | write("Fibonacci(");
29 | write(n);
30 | write(") = ");
31 | writeln(r);
32 |
33 | end Programa11.
--------------------------------------------------------------------------------
/samples/tests/p27.OBE:
--------------------------------------------------------------------------------
1 | module Programa11;
2 | var
3 | num, n, r : Integer;
4 |
5 | function fibonacci(num: Integer): Integer;
6 | var
7 | x: Integer;
8 | begin
9 |
10 | if num = 0 then
11 | return 0;
12 | elsif num = 1 then
13 | return 1;
14 | else
15 | x := fibonacci(num - 1);
16 | x := x + fibonacci(num - 2);
17 | return x;
18 | end;
19 |
20 | end fibonacci;
21 |
22 | begin
23 | write("N = ");
24 | read(n);
25 |
26 | r := fibonacci(n);
27 |
28 | write("Fibonacci(");
29 | write(n);
30 | write(") = ");
31 | writeln(r);
32 |
33 | end Programa11.
--------------------------------------------------------------------------------
/samples/p28.OBE:
--------------------------------------------------------------------------------
1 | module Programa11;
2 | var
3 | num, n, r : Integer;
4 |
5 | function fibonacci(num: Integer): Integer;
6 | var
7 | x: Integer;
8 | begin
9 |
10 | if num = 0 then
11 | return 0;
12 | elsif num = 1 then
13 | return 1;
14 | else
15 | x := fibonacci(num - 1);
16 | x := x + fibonacci(num - 2);
17 | return x;
18 | end;
19 |
20 | end fibonacci;
21 |
22 | begin
23 | write("N = ");
24 | read(n);
25 |
26 | while( n >= 0 ) do
27 | r := fibonacci(n);
28 |
29 | write("Fibonacci(");
30 | write(n);
31 | write(") = ");
32 | writeln(r);
33 |
34 | n := n - 1;
35 | end;
36 |
37 | end Programa11.
--------------------------------------------------------------------------------
/samples/tests/p28.OBE:
--------------------------------------------------------------------------------
1 | module Programa11;
2 | var
3 | num, n, r : Integer;
4 |
5 | function fibonacci(num: Integer): Integer;
6 | var
7 | x: Integer;
8 | begin
9 |
10 | if num = 0 then
11 | return 0;
12 | elsif num = 1 then
13 | return 1;
14 | else
15 | x := fibonacci(num - 1);
16 | x := x + fibonacci(num - 2);
17 | return x;
18 | end;
19 |
20 | end fibonacci;
21 |
22 | begin
23 | write("N = ");
24 | read(n);
25 |
26 | while( n >= 0 ) do
27 | r := fibonacci(n);
28 |
29 | write("Fibonacci(");
30 | write(n);
31 | write(") = ");
32 | writeln(r);
33 |
34 | n := n - 1;
35 | end;
36 |
37 | end Programa11.
--------------------------------------------------------------------------------
/samples/p23.OBE:
--------------------------------------------------------------------------------
1 | module Programa23;
2 | var a, b, i : integer;
3 | ignore1, ignore2, ignore3, ignore4: integer;
4 | begin
5 |
6 | write("Inicial: ");
7 | read(a);
8 |
9 | write("Final: ");
10 | read(b);
11 |
12 | write("ignorar: ");
13 | read(ignore1);
14 |
15 | write("ignorar: ");
16 | read(ignore2);
17 |
18 | write("ignorar: ");
19 | read(ignore3);
20 |
21 | write("ignorar: ");
22 | read(ignore4);
23 |
24 | for i := a To b Do
25 |
26 | if i = ignore1 then continue;
27 | elsif i = ignore2 then continue;
28 | elsif i = ignore3 then continue;
29 | elsif i = ignore4 then continue;
30 | end;
31 |
32 | write("i: ");
33 | writeln(i);
34 | end;
35 |
36 | end Programa23.
37 |
--------------------------------------------------------------------------------
/source/debugger/debugger_interfaces.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "debugger_interfaces/code_generator_debugger.h"
9 |
--------------------------------------------------------------------------------
/source/debugger/debugger_utils.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | char * getDebugFileName(const char *baseFileName, const char *extension);
9 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | Copyright 2011 ROCHA, Rodrigo C. O.; FERREIRA, Wallace Dias
2 |
3 | Oberon-0 Compiler: A Compiler for a subset of Oberon version 1.0
4 |
5 | Oberon-0 Compiler is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Oberon-0 Compiler is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Oberon-0 Compiler. If not, see .
17 |
--------------------------------------------------------------------------------
/source/README.txt:
--------------------------------------------------------------------------------
1 | Copyright 2011 ROCHA, Rodrigo C. O.; FERREIRA, Wallace Dias
2 |
3 | Oberon-0 Compiler: A Compiler for a subset of Oberon version 1.0
4 |
5 | Oberon-0 Compiler is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | Oberon-0 Compiler is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Oberon-0 Compiler. If not, see .
17 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/label_argument.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #include "label_argument.h"
10 |
11 | LabelArgument::LabelArgument(const InstructionArgumentType type)
12 | : InstructionArgument(type)
13 | {}
14 |
--------------------------------------------------------------------------------
/source/ast/declaration/declaration_node.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "declaration_node.h"
9 |
10 | DeclarationNode::DeclarationNode(const NodeType nodeType) : Node(nodeType)
11 | {
12 |
13 | }
14 |
15 | DeclarationNode::~DeclarationNode()
16 | {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/bin/assemble.cmd:
--------------------------------------------------------------------------------
1 | :: ******************************************
2 | :: *
3 | :: * Copyright 2011 ROCHA, Rodrigo C. O.
4 | :: *
5 | :: ******************************************
6 |
7 | @echo off
8 | echo Assembly File (without the file extension .s):
9 | set /p Input=
10 |
11 | if not exist "%Input%.s" (goto ASSEMBLY_ERROR)
12 |
13 | :ASSEMBLE
14 | gas\as.exe -o "%Input%.o" "%Input%.s"
15 | if not exist "%Input%.o" (goto ASSEMBLE_ERROR)
16 |
17 | :LINK
18 | gas\ld.exe -o "%Input%.exe" "gas/crt2.o" "gas/crtbegin.o" "gas/crtend.o" "%Input%.o" -L"gas/lib" -lmingw32 -lgcc -lmsvcrt -lkernel32
19 | if not exist "%Input%.exe" (goto LINK_ERROR)
20 |
21 | :DELETE
22 | del /q "%Input%.o"
23 | goto END
24 |
25 | :ASSEMBLY_ERROR
26 | ECHO File "%Input%.s" was not found
27 | goto END
28 |
29 | :ASSEMBLE_ERROR
30 | ECHO It was not possible to create the file "%Input%.o"
31 | goto END
32 |
33 | :LINK_ERROR
34 | ECHO It was not possible to create the file "%Input%.exe"
35 | goto END
36 |
37 | :END
38 | pause
--------------------------------------------------------------------------------
/source/debugger/debugger_interfaces/code_generator_debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef CODE_GENERATOR_DEBUGGER_H
9 | #define CODE_GENERATOR_DEBUGGER_H
10 |
11 | #include "../debugger.h"
12 |
13 | class CodeGeneratorDebugger: public Debugger
14 | {
15 |
16 | public:
17 |
18 | virtual void debugCode(const char *code) = 0;
19 |
20 | };
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/samples/P29.obe:
--------------------------------------------------------------------------------
1 | module Programa29;
2 |
3 | function lerValor(): Integer;
4 |
5 | Var
6 | v: Integer;
7 |
8 | Begin
9 |
10 | read(v);
11 | return v;
12 |
13 | End lerValor;
14 |
15 | procedure gerarValores();
16 | var
17 | numInicial, numFinal: Integer;
18 | numParada, numIgnorado: Integer;
19 | i : Integer;
20 | begin
21 |
22 | repeat
23 |
24 | write("Inicial: ");
25 | read(numInicial);
26 |
27 | write("Final: ");
28 | read(numFinal);
29 |
30 | write("Interromper se encontrar: ");
31 | read(numParada);
32 |
33 | write("Ignorar se encontrar: ");
34 | read(numIgnorado);
35 |
36 | for i := numInicial To numFinal Do
37 |
38 | if i = numParada then
39 | break;
40 | elsif i = numIgnorado then
41 | continue;
42 | else
43 | writeln(i);
44 | end;
45 | end;
46 |
47 | write("Repetir? (0 = Nao) : ");
48 | until lerValor() = 0;
49 |
50 | end gerarValores;
51 |
52 |
53 |
54 | Begin
55 |
56 | gerarValores();
57 |
58 | end Programa29.
59 |
60 |
--------------------------------------------------------------------------------
/source/global/global.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "global.h"
9 |
10 | // Declaração de variáveis compartilhadas.
11 |
12 | // Declara a instância do Oberon-0 Compiler que será compartilhada
13 | // nos arquivos:
14 | //
15 | // main.cpp (entry point do compilador);
16 | // scanner_lex.cpp (analisador léxico gerado pelo Flex) e
17 | // yy_parser.cpp (analisador sintático gerado pelo Bison)
18 |
19 | OberonC oberonc;
20 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/instruction_argument.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "instruction_argument.h"
9 |
10 | InstructionArgument::InstructionArgument(const InstructionArgumentType type)
11 | {
12 | this->type_ = type;
13 | }
14 |
15 | InstructionArgument::~InstructionArgument()
16 | {
17 |
18 | }
19 |
20 |
21 | const InstructionArgumentType InstructionArgument::getType()
22 | {
23 |
24 | return this->type_;
25 | }
26 |
--------------------------------------------------------------------------------
/bin/build.cmd:
--------------------------------------------------------------------------------
1 | :: ******************************************
2 | :: *
3 | :: * Copyright 2011 ROCHA, Rodrigo C. O.
4 | :: *
5 | :: ******************************************
6 | @echo off
7 | echo Enter the name of the oberon file (without the file extension .obe):
8 | set /p Input=
9 |
10 | if not exist "%Input%.obe" (goto COMPILE_ERROR)
11 |
12 | :COMPILE
13 | oberonc "%Input%.obe" -x86
14 | if not exist "%Input%.s" (goto ASSEMBLY_ERROR)
15 |
16 | :ASSEMBLE
17 | gas\as.exe -o "%Input%.o" "%Input%.s"
18 | if not exist "%Input%.o" (goto ASSEMBLE_ERROR)
19 |
20 | :LINK
21 | gas\ld.exe -o "%Input%.exe" "gas/crt2.o" "gas/crtbegin.o" "gas/crtend.o" "%Input%.o" -L"gas/lib" -lmingw32 -lgcc -lmsvcrt -lkernel32
22 | if not exist "%Input%.exe" (goto LINK_ERROR)
23 |
24 | :DELETE
25 | del /q "%Input%.o"
26 | goto END
27 |
28 | :COMPILE_ERROR
29 | ECHO File "%Input%.obe" was not found
30 | goto END
31 |
32 | :ASSEMBLY_ERROR
33 | ECHO It was not possible to create the file "%Input%.s"
34 | goto END
35 |
36 | :ASSEMBLE_ERROR
37 | ECHO It was not possible to create the file "%Input%.o"
38 | goto END
39 |
40 | :LINK_ERROR
41 | ECHO It was not possible to create the file "%Input%.exe"
42 | goto END
43 |
44 | :END
45 | pause
--------------------------------------------------------------------------------
/source/ast/expression/arithmetic_operator.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef ARITHMETIC_OPERATOR_H
9 | #define ARITHMETIC_OPERATOR_H
10 |
11 | enum ArithmeticOperator
12 | {
13 | ARITHMETIC_OPERATOR_UNDEFINED, // Apenas para fins de controle e depuração.
14 | ARITHMETIC_OPERATOR_ADD,
15 | ARITHMETIC_OPERATOR_SUB,
16 | ARITHMETIC_OPERATOR_MULT,
17 | ARITHMETIC_OPERATOR_DIV,
18 | ARITHMETIC_OPERATOR_MOD
19 | };
20 |
21 | const char *getArithmeticOperatorName(ArithmeticOperator op);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/source/debugger/debugger_interfaces/ast_debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef AST_DEBUGGER_H
9 | #define AST_DEBUGGER_H
10 |
11 | #include "../debugger.h"
12 | #include "../../parser/parser_exception.h"
13 |
14 | class ASTDebugger: public Debugger
15 | {
16 |
17 | public:
18 |
19 | virtual void openParentNode(const char *node, int nodeLevel) = 0;
20 | virtual void closeParentNode(const char *node, int nodeLevel) = 0;
21 | virtual void insertLeafNode(const char *node, int nodeLevel) = 0;
22 | };
23 |
24 | #endif
25 |
26 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/module_information.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef MODULE_INFORMATION_H
9 | #define MODULE_INFORMATION_H
10 |
11 | #include "../identifier_information.h"
12 |
13 | #include "variable_information.h"
14 | #include "function_information.h"
15 |
16 | class ModuleInformation: public IdentifierInformation
17 | {
18 |
19 | public:
20 |
21 | ModuleInformation();
22 | ModuleInformation(const char *identifier);
23 |
24 | void debug(SymbolTableDebugger *symbolTableDebugger);
25 |
26 | };
27 | #endif
28 |
--------------------------------------------------------------------------------
/source/ast/declaration/skip_declaration_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef SKIP_DECLARATION_NODE_H
9 | #define SKIP_DECLARATION_NODE_H
10 |
11 | #include "declaration_node.h"
12 |
13 | class SkipDeclarationNode : public DeclarationNode
14 | {
15 |
16 | public:
17 |
18 | SkipDeclarationNode();
19 | ~SkipDeclarationNode();
20 |
21 | void typeCheck(SemanticDebugger *semanticDebugger);
22 | void debug(ASTDebugger *astDebugger, int nodeLevel);
23 |
24 | void generateCCode(ostream &out);
25 |
26 |
27 | };
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/nop_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_NOP_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_NOP_INSTRUCTION_H
11 |
12 | #include "instruction.h"
13 |
14 | class NopInstruction : public Instruction
15 | {
16 |
17 | public:
18 |
19 | NopInstruction();
20 |
21 | vector *getArgumentsInformation();
22 |
23 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
24 | void debug(ostream &out);
25 |
26 |
27 | };
28 |
29 | #endif
30 |
31 |
32 |
--------------------------------------------------------------------------------
/source/debugger/debugger_implementations/simple_code_generator_debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef SIMPLE_CODE_GENERATOR_DEBUGGER_H
9 | #define SIMPLE_CODE_GENERATOR_DEBUGGER_H
10 |
11 | #include "../debugger_interfaces/code_generator_debugger.h"
12 |
13 |
14 | class SimpleCodeGeneratorDebugger: public CodeGeneratorDebugger
15 | {
16 |
17 | public:
18 |
19 | SimpleCodeGeneratorDebugger();
20 |
21 | void debugCode(const char *code);
22 |
23 | protected:
24 |
25 | void createDebugFile(const char *baseFileName);
26 |
27 | };
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/source/debugger/debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef DEBUGGER_H
9 | #define DEBUGGER_H
10 |
11 | #include "debugger_utils.h"
12 | #include
13 | using namespace std;
14 |
15 | class Debugger
16 | {
17 |
18 | public:
19 |
20 | Debugger();
21 | virtual ~Debugger();
22 |
23 | void start(const char *baseFileName);
24 | void stop();
25 |
26 | protected:
27 |
28 | virtual void createDebugFile(const char *baseFileName) = 0;
29 | virtual void preCloseDebugFile();
30 |
31 | bool enabled_;
32 | ofstream debugFile_;
33 |
34 | };
35 |
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/label_argument.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef INTERMEDIATE_CODE_LABEL_ARGUMENT_H
9 | #define INTERMEDIATE_CODE_LABEL_ARGUMENT_H
10 |
11 | #include "instruction_argument.h"
12 |
13 | #define LABEL_NONE 0
14 | #define LABEL_FALL -1
15 |
16 |
17 | class LabelArgument : public InstructionArgument
18 | {
19 | public:
20 |
21 | LabelArgument(const InstructionArgumentType type);
22 | virtual ~LabelArgument(){};
23 |
24 | virtual void debug(CodeGeneratorDebugger * codeGeneratorDebugger) = 0;
25 | virtual void debug(ostream &out) = 0;
26 | };
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/source/debugger/debugger_implementations/simple_ast_debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef SIMPLE_AST_DEBUGGER_H
9 | #define SIMPLE_AST_DEBUGGER_H
10 |
11 | #include "../debugger_interfaces/ast_debugger.h"
12 |
13 | class SimpleASTDebugger: public ASTDebugger
14 | {
15 |
16 | public:
17 |
18 | SimpleASTDebugger();
19 |
20 | void openParentNode(const char *node, int nodeLevel);
21 | void closeParentNode(const char *node, int nodeLevel);
22 | void insertLeafNode(const char *nome, int nodeLevel);
23 |
24 | protected:
25 |
26 | void createDebugFile(const char *baseFileName);
27 |
28 | };
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/temporary_information.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef TEMPORARY_INFORMATION_H
9 | #define TEMPORARY_INFORMATION_H
10 |
11 | #include "../identifier_information.h"
12 | #include "../data_type.h"
13 |
14 | class TemporaryInformation: public IdentifierInformation
15 | {
16 |
17 | public:
18 |
19 | TemporaryInformation();
20 | TemporaryInformation(int number);
21 |
22 |
23 | int getNumber() const;
24 | void setNumber(int number);
25 |
26 | void debug(SymbolTableDebugger *symbolTableDebugger);
27 |
28 | private:
29 |
30 | int number_;
31 | };
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/source/ast/statement/write_line_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef WRITE_LINE_NODE_H
9 | #define WRITE_LINE_NODE_H
10 |
11 | #include "statement_node.h"
12 |
13 | class WriteLineNode : public StatementNode
14 | {
15 |
16 | public:
17 |
18 | WriteLineNode();
19 | ~WriteLineNode();
20 |
21 | void typeCheck(SemanticDebugger *semanticDebugger);
22 |
23 | void debug(ASTDebugger *astDebugger, int nodeLevel);
24 |
25 | void generateCCode(ostream &out);
26 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
27 |
28 | private:
29 |
30 | };
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/source/debugger/debugger_implementations/simple_parser_debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef SIMPLE_PARSER_DEBUGGER_H
9 | #define SIMPLE_PARSER_DEBUGGER_H
10 |
11 | #include "../debugger_interfaces/parser_debugger.h"
12 |
13 |
14 | class SimpleParserDebugger: public ParserDebugger
15 | {
16 |
17 | public:
18 |
19 | SimpleParserDebugger();
20 |
21 | void debugReduction(const char* nonTerminalSymbol, const char *production, int lookaheadLine);
22 | void debugRecoveredError(const char *errorMessage, int lineNumber);
23 |
24 | protected:
25 |
26 | void createDebugFile(const char *baseFileName);
27 |
28 |
29 | };
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/source/ast/statement/skip_statement_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef SKIP_STATEMENT_NODE_H
9 | #define SKIP_STATEMENT_NODE_H
10 |
11 | #include "statement_node.h"
12 |
13 | class SkipStatementNode : public StatementNode
14 | {
15 |
16 | public:
17 |
18 | SkipStatementNode();
19 | ~SkipStatementNode();
20 |
21 | void typeCheck(SemanticDebugger *semanticDebugger);
22 |
23 | void debug(ASTDebugger *astDebugger, int nodeLevel);
24 |
25 | void generateCCode(ostream &out);
26 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
27 | private:
28 |
29 | };
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/source/ast/statement/break_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef BREAK_NODE_H
9 | #define BREAK_NODE_H
10 |
11 | #include "statement_node.h"
12 |
13 | class BreakNode : public StatementNode
14 | {
15 |
16 | public:
17 |
18 | BreakNode();
19 | ~BreakNode();
20 |
21 | void typeCheck(SemanticDebugger *semanticDebugger);
22 | bool checkRepetition(const bool inRepetition, SemanticDebugger * semanticDebugger);
23 |
24 | void debug(ASTDebugger *astDebugger, int nodeLevel);
25 |
26 | void generateCCode(ostream &out);
27 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
28 | };
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/immediate_argument.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef INTERMEDIATE_CODE_IMMEDIATE_ARGUMENT_H
9 | #define INTERMEDIATE_CODE_IMMEDIATE_ARGUMENT_H
10 |
11 | #include "instruction_argument.h"
12 |
13 | class ImmediateArgument : public InstructionArgument
14 | {
15 |
16 | public:
17 |
18 | ImmediateArgument(const long immediateValue);
19 |
20 | void setImmediateValue(const long immediateValue);
21 | long getImmediateValue() const;
22 |
23 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
24 | void debug(ostream &out);
25 | private:
26 |
27 | long immediateValue_;
28 | };
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/string_argument.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef INTERMEDIATE_CODE_STRING_ARGUMENT_H
9 | #define INTERMEDIATE_CODE_STRING_ARGUMENT_H
10 |
11 | #include "instruction_argument.h"
12 |
13 | class StringArgument : public InstructionArgument
14 | {
15 |
16 | public:
17 |
18 | StringArgument(const char *stringValue);
19 | ~StringArgument();
20 |
21 | void setStringValue(const char *stringValue);
22 | char *getStringValue() const;
23 |
24 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
25 | void debug(ostream &out);
26 | private:
27 |
28 | char *stringValue_;
29 | };
30 |
31 | #endif
32 |
33 |
--------------------------------------------------------------------------------
/bin/HowToUse.txt:
--------------------------------------------------------------------------------
1 |
2 | WINDOWS
3 |
4 | oberonc.exe is the compiler executable.
5 | It generates an assembly file compiled from the source code.
6 |
7 | After oberonc has generated the assembly file, you execute
8 | the GNU Assembler (GAS, as) to generate the object file and then
9 | execute the GNU Linker ( ld ) to create the executable file of
10 | your program.
11 |
12 | The batches intend to simplify these steps.
13 |
14 | Once you've created the assembly file, you can
15 | just execute the assemble.cmd and type the
16 | name of the assembly file, without the extension (.s) .
17 |
18 | The build.cmd do all the steps. It means that you
19 | can just execute the build.cmd and type the name
20 | of the source file, without the extension (.obe),
21 | and it will call the compiler, the assembler and
22 | the linker.
23 |
24 |
25 | LINUX
26 |
27 | oberonc is the compiler executable.
28 | It generates an assembly file compiled from the source code.
29 |
30 | After oberonc has generated the assembly file, you can execute the GNU C Compiler (gcc) to generate the executable file of your program.
31 |
32 | The build.sh do all the steps. It means that you can just execute the bash.sh passing the path of your source file as an argument, then it will call the Oberon-0 compiler and the GNU C Compiler (gcc) generating the executable in the same folder of you source file.
33 |
34 |
35 | Copyright 2011 ROCHA, Rodrigo C. O.
36 |
--------------------------------------------------------------------------------
/source/ast/declaration/skip_declaration_node.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "skip_declaration_node.h"
9 |
10 | SkipDeclarationNode::SkipDeclarationNode() : DeclarationNode(NODE_TYPE_SKIP_DECLARATION)
11 | {
12 |
13 | }
14 |
15 | SkipDeclarationNode::~SkipDeclarationNode()
16 | {
17 |
18 | }
19 |
20 | void SkipDeclarationNode::typeCheck(SemanticDebugger *semanticDebugger)
21 | {
22 | // Type Check não aplicável a este nodo.
23 | }
24 |
25 | void SkipDeclarationNode::debug(ASTDebugger *astDebugger, int nodeLevel)
26 | {
27 | astDebugger->insertLeafNode("{Skip Declaration}", nodeLevel);
28 | }
29 |
30 | void SkipDeclarationNode::generateCCode(ostream &out)
31 | {
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/source/debugger/debugger_implementations/formatted_ast_debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef FORMATTED_AST_DEBUGGER_H
9 | #define FORMATTED_AST_DEBUGGER_H
10 |
11 | #include "../debugger_interfaces/ast_debugger.h"
12 |
13 |
14 | class FormattedASTDebugger: public ASTDebugger
15 | {
16 |
17 | public:
18 |
19 | FormattedASTDebugger();
20 |
21 | void openParentNode(const char *node, int nodeLevel);
22 | void closeParentNode(const char *node, int nodeLevel);
23 | void insertLeafNode(const char *nome, int nodeLevel);
24 |
25 | protected:
26 |
27 | void createDebugFile(const char *baseFileName);
28 | void preCloseDebugFile();
29 |
30 |
31 | };
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/source/ast/statement/continue_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef CONTINUE_NODE_H
9 | #define CONTINUE_NODE_H
10 |
11 | #include "statement_node.h"
12 |
13 | class ContinueNode : public StatementNode
14 | {
15 |
16 | public:
17 |
18 | ContinueNode();
19 | ~ContinueNode();
20 |
21 | void typeCheck(SemanticDebugger *semanticDebugger);
22 | bool checkRepetition(const bool inRepetition, SemanticDebugger * semanticDebugger);
23 |
24 | void debug(ASTDebugger *astDebugger, int nodeLevel);
25 |
26 |
27 | void generateCCode(ostream &out);
28 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
29 | };
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/instruction_label.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef INTERMEDIATE_CODE_INSTRUCTION_LABEL_ARGUMENT_H
9 | #define INTERMEDIATE_CODE_INSTRUCTION_LABEL_ARGUMENT_H
10 |
11 |
12 | #include "instruction_argument.h"
13 | #include "label_argument.h"
14 |
15 | class InstructionLabel : public LabelArgument
16 | {
17 |
18 | public:
19 |
20 | InstructionLabel(const int labelNumber);
21 |
22 | void setLabelNumber(const int labelNumber);
23 | int getLabelNumber() const;
24 |
25 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
26 | void debug(ostream &out);
27 | private:
28 |
29 | int labelNumber_;
30 | };
31 |
32 | #endif
33 |
34 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/function_label.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef INTERMEDIATE_CODE_FUNCTION_LABEL_ARGUMENT_H
9 | #define INTERMEDIATE_CODE_FUNCTION_LABEL_ARGUMENT_H
10 |
11 | #include "instruction_argument.h"
12 | #include "label_argument.h"
13 |
14 | class FunctionLabel : public LabelArgument
15 | {
16 | public:
17 |
18 | FunctionLabel(const char *labelString);
19 | ~FunctionLabel();
20 | void setLabelString(const char *labelString);
21 | char *getLabelString() const;
22 |
23 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
24 | void debug(ostream &out);
25 | private:
26 |
27 | char *labelString_;
28 | };
29 |
30 | #endif
31 |
32 |
33 |
--------------------------------------------------------------------------------
/source/ast/expression/relational_operator.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef RELATIONAL_OPERATOR_H
9 | #define RELATIONAL_OPERATOR_H
10 |
11 | enum RelationalOperator
12 | {
13 | RELATIONAL_OPERATOR_UNDEFINED, // Apenas para fins de controle e depuração.
14 | RELATIONAL_OPERATOR_LESS,
15 | RELATIONAL_OPERATOR_GREATER,
16 | RELATIONAL_OPERATOR_LESS_OR_EQUAL,
17 | RELATIONAL_OPERATOR_GREATER_OR_EQUAL,
18 | RELATIONAL_OPERATOR_EQUAL,
19 | RELATIONAL_OPERATOR_DIFFERENT
20 | } ;
21 |
22 | RelationalOperator invertRelationalOperator(RelationalOperator op);
23 | RelationalOperator mirrorRelationalOperator(RelationalOperator op);
24 | const char *getRelationalOperatorName(RelationalOperator op);
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/goto_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_GOTO_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_GOTO_INSTRUCTION_H
11 |
12 | #include "instruction.h"
13 |
14 | class GotoInstruction : public Instruction
15 | {
16 | public:
17 |
18 | GotoInstruction(LabelArgument *label);
19 |
20 | void setLabelArgument(LabelArgument *label);
21 | LabelArgument *getLabelArgument() const ;
22 |
23 | vector *getArgumentsInformation();
24 |
25 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
26 | void debug(ostream &out);
27 | private:
28 |
29 | LabelArgument *label_;
30 | };
31 |
32 | #endif
33 |
34 |
35 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/variable_information.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef VARIABLE_INFORMATION_H
9 | #define VARIABLE_INFORMATION_H
10 |
11 | #include "../identifier_information.h"
12 | #include "../data_type.h"
13 |
14 | class VariableInformation: public IdentifierInformation
15 | {
16 |
17 | public:
18 |
19 | VariableInformation();
20 | VariableInformation(const char *identifier);
21 |
22 | DataType getType() const;
23 | void setType(const DataType type);
24 |
25 | void setOffset(int offset);
26 | int getOffset();
27 |
28 | void debug(SymbolTableDebugger *symbolTableDebugger);
29 |
30 | private:
31 | int offset_;
32 | DataType type_;
33 | };
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/source/ast/statement/write_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef WRITE_NODE_H
9 | #define WRITE_NODE_H
10 |
11 | #include "statement_node.h"
12 | #include "../expression/expression_node.h"
13 |
14 | class WriteNode : public StatementNode
15 | {
16 |
17 | public:
18 |
19 | WriteNode(ExpressionNode *expression);
20 | ~WriteNode();
21 |
22 | void typeCheck(SemanticDebugger *semanticDebugger);
23 |
24 | void debug(ASTDebugger *astDebugger, int nodeLevel);
25 |
26 | void generateCCode(ostream &out);
27 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
28 |
29 | private:
30 |
31 | ExpressionNode *expression_;
32 |
33 | };
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/source/ast/expression/not_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef NOT_NODE_H
9 | #define NOT_NODE_H
10 |
11 | #include "expression_node.h"
12 |
13 | class NotNode : public ExpressionNode
14 | {
15 |
16 | public:
17 |
18 | NotNode(ExpressionNode *operand);
19 | ~NotNode();
20 |
21 | DataType typeCheck(SemanticDebugger *semanticDebugger);
22 | void debug(ASTDebugger *astDebugger, int nodeLevel);
23 |
24 | void generateCCode(ostream &out);
25 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
26 |
27 | protected:
28 |
29 |
30 | void checkConstant();
31 |
32 | private:
33 |
34 | ExpressionNode *operand_;
35 | };
36 |
37 | #endif
38 |
39 |
--------------------------------------------------------------------------------
/source/ast/statement/pre_test_loop_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef PRE_TEST_LOOP_NODE_H
9 | #define PRE_TEST_LOOP_NODE_H
10 |
11 | #include "loop_node.h"
12 | #include "statement_node.h"
13 | #include "statement_sequence_node.h"
14 | #include "../expression/expression_node.h"
15 |
16 | class PreTestLoopNode : public LoopNode
17 | {
18 |
19 | public:
20 |
21 | PreTestLoopNode(ExpressionNode *expression, StatementNode *statement);
22 | ~PreTestLoopNode();
23 |
24 | void debug(ASTDebugger *astDebugger, int nodeLevel);
25 |
26 | void generateCCode(ostream &out);
27 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
28 |
29 | private:
30 |
31 | };
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/resources/mktree.css:
--------------------------------------------------------------------------------
1 | body
2 | {
3 | font-family: Verdana;
4 | font-size: 12px;
5 | }
6 |
7 | ul.mktree
8 | {
9 | color: #555555;
10 | }
11 |
12 | /* Turn off list bullets */
13 | ul.mktree li {
14 | list-style: none;
15 | }
16 |
17 | /* Control how "spaced out" the tree is */
18 | ul.mktree, ul.mktree ul , ul.mktree li {
19 | margin-left:10px;
20 | padding:0px;
21 | }
22 |
23 | /* Provide space for our own "bullet" inside the LI */
24 | ul.mktree li .bullet {
25 | padding-left: 15px;
26 | color: #0099ff;
27 | font-weight:bold;
28 |
29 | }
30 |
31 | /* Show "bullets" in the links, depending on the class of the LI that the link's in */
32 | ul.mktree li.liOpen .bullet {
33 | cursor: pointer;
34 | background-image: url('minus.gif');
35 | background-position: center left;
36 | background-repeat: no-repeat;
37 | }
38 |
39 | ul.mktree li.liClosed .bullet {
40 | cursor: pointer;
41 | background-image: url('plus.gif');
42 | background-position: center left;
43 | background-repeat: no-repeat;
44 | }
45 |
46 | ul.mktree li.liBullet .bullet {
47 | cursor: default;
48 | background-image: url('bullet.gif');
49 | background-position: center left;
50 | background-repeat: no-repeat;
51 | }
52 |
53 | /* Sublists are visible or not based on class of parent LI */
54 | ul.mktree li.liOpen ul {
55 | display: block;
56 | }
57 |
58 | ul.mktree li.liClosed ul {
59 | display: none;
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/source/ast/statement/post_test_loop_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef POST_TEST_LOOP_NODE_H
9 | #define POST_TEST_LOOP_NODE_H
10 |
11 | #include "loop_node.h"
12 | #include "statement_node.h"
13 | #include "statement_sequence_node.h"
14 | #include "../expression/expression_node.h"
15 |
16 | class PostTestLoopNode : public LoopNode
17 | {
18 |
19 | public:
20 |
21 | PostTestLoopNode(StatementNode *statement, ExpressionNode *expression);
22 | ~PostTestLoopNode();
23 |
24 | void debug(ASTDebugger *astDebugger, int nodeLevel);
25 |
26 | void generateCCode(ostream &out);
27 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
28 |
29 | private:
30 |
31 | };
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/return_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_RETURN_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_RETURN_INSTRUCTION_H
11 |
12 | #include "instruction.h"
13 |
14 | class ReturnInstruction : public Instruction
15 | {
16 | public:
17 |
18 | ReturnInstruction(InstructionArgument *src = NULL);
19 |
20 | void setSourceArgument(InstructionArgument *src);
21 | InstructionArgument *getSourceArgument() const ;
22 |
23 | vector *getArgumentsInformation();
24 |
25 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
26 | void debug(ostream &out);
27 | private:
28 |
29 | ArgumentInformation src_;
30 | };
31 |
32 | #endif
33 |
34 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/write_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_WRITE_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_WRITE_INSTRUCTION_H
11 |
12 | #include "instruction.h"
13 |
14 | class WriteInstruction : public Instruction
15 | {
16 |
17 | public:
18 |
19 | WriteInstruction(InstructionArgument *src);
20 |
21 | void setSourceArgument(InstructionArgument *src);
22 | InstructionArgument *getSourceArgument() const ;
23 |
24 | vector *getArgumentsInformation();
25 |
26 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
27 | void debug(ostream &out);
28 | private:
29 |
30 | ArgumentInformation src_;
31 | };
32 |
33 | #endif
34 |
35 |
36 |
--------------------------------------------------------------------------------
/source/scanner/token_type.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef TOKEN_TYPE_H
9 | #define TOKEN_TYPE_H
10 |
11 | /**
12 | Este arquivo abstrai tokens definidos no arquivo "yy_parser.h", gerados pelo Bison,
13 | em uma representação interna de tokens (TokenType) no Scanner.
14 |
15 | Define-se uma função que, dado o tipo do token (TokenType), recupera-se e retorna-se
16 | o respectivo nome associado a este token.
17 | */
18 | #include "../parser/yy_parser.h"
19 |
20 | // Abstrai definição dos tipos de tokens gerados no arquivo
21 | // "yy_parser.h" em uma representação interna ao Scanner.
22 | typedef yytokentype TokenType;
23 |
24 | // Retorna o nome de um token com base em seu tipo.
25 | char *getTokenTypeName(TokenType tokenType);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/source/ast/expression/negation_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef NEGATION_NODE_H
9 | #define NEGATION_NODE_H
10 |
11 | #include "expression_node.h"
12 |
13 | class NegationNode : public ExpressionNode
14 | {
15 |
16 | public:
17 |
18 | NegationNode(ExpressionNode *operand);
19 | ~NegationNode();
20 |
21 | DataType typeCheck(SemanticDebugger *semanticDebugger);
22 | void debug(ASTDebugger *astDebugger, int nodeLevel);
23 |
24 | void generateCCode(ostream &out);
25 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
26 |
27 | protected:
28 |
29 | void checkConstant();
30 |
31 | private:
32 |
33 | ExpressionNode *operand_;
34 | };
35 |
36 | #endif
37 |
38 |
39 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/read_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_READ_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_READ_INSTRUCTION_H
11 |
12 | #include "instruction.h"
13 |
14 | class ReadInstruction : public Instruction
15 | {
16 |
17 | public:
18 |
19 | ReadInstruction(InstructionArgument *dest);
20 |
21 | void setDestinationArgument(InstructionArgument *dest);
22 | InstructionArgument *getDestinationArgument() const ;
23 |
24 | vector *getArgumentsInformation();
25 |
26 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
27 | void debug(ostream &out);
28 | private:
29 |
30 | ArgumentInformation dest_;
31 | };
32 |
33 | #endif
34 |
35 |
36 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/formal_parameter_information.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef FORMAL_PARAMETER_INFORMATION_H
9 | #define FORMAL_PARAMETER_INFORMATION_H
10 |
11 | #include "../identifier_information.h"
12 | #include "../data_type.h"
13 |
14 | class FormalParameterInformation: public IdentifierInformation
15 | {
16 |
17 | public:
18 |
19 | FormalParameterInformation();
20 | FormalParameterInformation(const char *identifier);
21 |
22 | DataType getType() const;
23 | void setType(DataType type);
24 |
25 | void setOffset(int offset);
26 | int getOffset();
27 |
28 | void debug(SymbolTableDebugger *symbolTableDebugger);
29 |
30 | private:
31 | int offset_;
32 | DataType type_;
33 | };
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/parameter_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_PARAMETER_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_PARAMETER_INSTRUCTION_H
11 |
12 | #include "instruction.h"
13 |
14 | class ParameterInstruction : public Instruction
15 | {
16 |
17 | public:
18 |
19 | ParameterInstruction(InstructionArgument *src);
20 |
21 | void setSourceArgument(InstructionArgument *src);
22 | InstructionArgument *getSourceArgument() const ;
23 |
24 | vector *getArgumentsInformation();
25 |
26 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
27 | void debug(ostream &out);
28 | private:
29 | ArgumentInformation src_;
30 | };
31 |
32 | #endif
33 |
34 |
35 |
--------------------------------------------------------------------------------
/source/ast/expression/boolean_literal_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef BOOLEAN_LITERAL_NODE_H
9 | #define BOOLEAN_LITERAL_NODE_H
10 |
11 | #include "expression_node.h"
12 |
13 | class BooleanLiteralNode : public ExpressionNode
14 | {
15 | public:
16 |
17 | BooleanLiteralNode(bool value);
18 | ~BooleanLiteralNode();
19 |
20 | bool getValue() const;
21 |
22 | DataType typeCheck(SemanticDebugger *semanticDebugger);
23 | void debug(ASTDebugger *astDebugger, int nodeLevel);
24 |
25 | void generateCCode(ostream &out);
26 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
27 |
28 | protected:
29 |
30 | void checkConstant();
31 |
32 | private:
33 |
34 | bool value_;
35 | };
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/source/ast/expression/string_literal_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef STRING_LITERAL_NODE_H
9 | #define STRING_LITERAL_NODE_H
10 |
11 | #include "expression_node.h"
12 |
13 | class StringLiteralNode : public ExpressionNode
14 | {
15 |
16 | public:
17 |
18 | StringLiteralNode(const char *value);
19 | ~StringLiteralNode();
20 |
21 | DataType typeCheck(SemanticDebugger *semanticDebugger);
22 | void debug(ASTDebugger *astDebugger, int nodeLevel);
23 |
24 | void generateCCode(ostream &out);
25 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
26 |
27 | protected:
28 |
29 |
30 | void checkConstant();
31 |
32 | private:
33 |
34 | char *value_;
35 | };
36 |
37 | #endif
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/source/ast/expression/and_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef AND_NODE_H
9 | #define AND_NODE_H
10 |
11 | #include "expression_node.h"
12 |
13 | class AndNode : public ExpressionNode
14 | {
15 | public:
16 |
17 | AndNode(ExpressionNode *leftOperand, ExpressionNode *rightOperand);
18 | ~AndNode();
19 |
20 | DataType typeCheck(SemanticDebugger *semanticDebugger);
21 | void debug(ASTDebugger *astDebugger, int nodeLevel);
22 |
23 | void generateCCode(ostream &out);
24 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
25 |
26 |
27 | protected:
28 |
29 | void checkConstant();
30 |
31 | private:
32 |
33 | ExpressionNode *leftOperand_;
34 | ExpressionNode *rightOperand_;
35 | };
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/identifier_argument.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef INTERMEDIATE_CODE_IDENTIFIER_ARGUMENT_H
9 | #define INTERMEDIATE_CODE_IDENTIFIER_ARGUMENT_H
10 |
11 | #include "instruction_argument.h"
12 | #include "../../../symbol_table/identifier_information.h"
13 |
14 | class IdentifierArgument : public InstructionArgument
15 | {
16 |
17 | public:
18 |
19 | IdentifierArgument(IdentifierInformation *information);
20 |
21 | void setIdentifierInformation(IdentifierInformation *information);
22 | IdentifierInformation *getIdentifierInformation();
23 |
24 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
25 | void debug(ostream &out);
26 | private:
27 |
28 | IdentifierInformation *information_;
29 | };
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/source/ast/expression/or_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef OR_NODE_H
9 | #define OR_NODE_H
10 |
11 | #include "expression_node.h"
12 |
13 | class OrNode : public ExpressionNode
14 | {
15 |
16 | public:
17 |
18 | OrNode(ExpressionNode *leftOperand, ExpressionNode *rightOperand);
19 | ~OrNode();
20 |
21 | DataType typeCheck(SemanticDebugger *semanticDebugger);
22 | void debug(ASTDebugger *astDebugger, int nodeLevel);
23 |
24 | void generateCCode(ostream &out);
25 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
26 |
27 | protected:
28 |
29 |
30 | void checkConstant();
31 |
32 | private:
33 |
34 | ExpressionNode *leftOperand_;
35 | ExpressionNode *rightOperand_;
36 | };
37 |
38 | #endif
39 |
40 |
--------------------------------------------------------------------------------
/source/ast/expression/integer_literal_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTEGER_LITERAL_NODE_H
10 | #define INTEGER_LITERAL_NODE_H
11 |
12 | #include "expression_node.h"
13 |
14 | class IntegerLiteralNode : public ExpressionNode
15 | {
16 |
17 | public:
18 |
19 | IntegerLiteralNode(long value);
20 | ~IntegerLiteralNode();
21 |
22 | long getValue() const;
23 |
24 | DataType typeCheck(SemanticDebugger *semanticDebugger);
25 | void debug(ASTDebugger *astDebugger, int nodeLevel);
26 |
27 | void generateCCode(ostream &out);
28 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
29 |
30 | protected:
31 |
32 |
33 | void checkConstant();
34 |
35 | private:
36 |
37 | long value_;
38 | };
39 |
40 | #endif
41 |
42 |
43 |
--------------------------------------------------------------------------------
/source/ast/statement/read_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef READ_NODE_H
9 | #define READ_NODE_H
10 |
11 | #include "statement_node.h"
12 | #include "../expression/identifier_node.h"
13 |
14 | #include "../../symbol_table/data_type.h"
15 |
16 | class ReadNode : public StatementNode
17 | {
18 |
19 | public:
20 |
21 | ReadNode(IdentifierNode *identifierNode);
22 | ~ReadNode();
23 |
24 | IdentifierNode *getIdentifier() const;
25 |
26 | void typeCheck(SemanticDebugger *semanticDebugger);
27 |
28 | void debug(ASTDebugger *astDebugger, int nodeLevel);
29 |
30 | void generateCCode(ostream &out);
31 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
32 |
33 | private:
34 |
35 | IdentifierNode *identifier_;
36 | };
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/source/symbol_table/data_type.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "data_type.h"
9 |
10 | const char *getDataTypeName(DataType DataType)
11 | {
12 | const char * typeName = 0;
13 |
14 | switch(DataType)
15 | {
16 |
17 | case DATA_TYPE_UNDEFINED:
18 | typeName = "Undefined Type";
19 | break;
20 |
21 | case DATA_TYPE_ERROR:
22 | typeName = "Invalid Type";
23 | break;
24 |
25 | case DATA_TYPE_BOOLEAN:
26 | typeName = "Boolean";
27 | break;
28 |
29 | case DATA_TYPE_INTEGER:
30 | typeName = "Integer";
31 | break;
32 |
33 | case DATA_TYPE_VOID:
34 | typeName = "Void";
35 | break;
36 |
37 | case DATA_TYPE_STRING:
38 | typeName = "String";
39 | break;
40 |
41 | }
42 |
43 | return typeName;
44 | }
45 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/temporary_argument.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef INTERMEDIATE_CODE_TEMPORARY_ARGUMENT_H
9 | #define INTERMEDIATE_CODE_TEMPORARY_ARGUMENT_H
10 |
11 | #include "instruction_argument.h"
12 | #include "../../../symbol_table/identifier_category/temporary_information.h"
13 |
14 | class TemporaryArgument : public InstructionArgument
15 | {
16 |
17 | public:
18 |
19 | TemporaryArgument(TemporaryInformation * temporaryInformation);
20 |
21 | void setNumber(const int number);
22 | int getNumber() const;
23 |
24 | TemporaryInformation *getTemporaryInformation() const;
25 |
26 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
27 | void debug(ostream &out);
28 |
29 | private:
30 |
31 | TemporaryInformation * temporaryInformation_;
32 | };
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/source/parser/parser_exception.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "parser_exception.h"
9 |
10 | /**
11 | Implementação da classe ParserException.
12 | */
13 |
14 | /**
15 | Construtor padrão - inicializa atributo relativo à mensagem de erro vinculada à exceção.
16 |
17 | @param
18 | errorMessage - mensagem de erro vinculada à exceção.
19 | */
20 | ParserException::ParserException(string errorMessage) throw()
21 | {
22 | this->errorMessage_ = errorMessage;
23 | }
24 |
25 | /**
26 | Destrutor da classe.
27 | */
28 | ParserException::~ParserException() throw()
29 | {
30 |
31 | }
32 |
33 | /**
34 | Retorna a mensagem de erro vinculada à exceção.
35 |
36 | @return
37 | mensagem de erro vinculada à exceção.
38 | */
39 | const char* ParserException::what() const throw()
40 | {
41 | return this->errorMessage_.c_str();
42 | }
43 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/instruction.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "instruction.h"
9 |
10 | Instruction::Instruction(InstructionType type)
11 | : instructionType_(type), label_(0), isDeadCode_(0)
12 | {
13 | }
14 |
15 | void Instruction::setInstructionType(const InstructionType type)
16 | {
17 | this->instructionType_ = type;
18 | }
19 |
20 | InstructionType Instruction::getInstructionType() const
21 | {
22 | return this->instructionType_;
23 | }
24 |
25 | void Instruction::setLabel(LabelArgument *label)
26 | {
27 | this->label_ = label;
28 | }
29 |
30 | LabelArgument *Instruction::getLabel()
31 | {
32 | return this->label_;
33 | }
34 |
35 | void Instruction::setDeadCode(bool isDead)
36 | {
37 | isDeadCode_ = isDead;
38 | }
39 |
40 | bool Instruction::isDeadCode()
41 | {
42 | return isDeadCode_;
43 | }
44 |
--------------------------------------------------------------------------------
/source/ast/declaration/constant_list_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef CONSTANT_LIST_NODE_H
9 | #define CONSTANT_LIST_NODE_H
10 |
11 | #include "declaration_node.h"
12 | #include "declaration_sequence_node.h"
13 | #include "constant_node.h"
14 |
15 | #include "../../symbol_table/data_type.h"
16 |
17 | #include
18 | using namespace std;
19 |
20 | class ConstantListNode : public DeclarationNode
21 | {
22 |
23 | public:
24 |
25 | ConstantListNode();
26 | ~ConstantListNode();
27 |
28 | void addConstantSequence(DeclarationSequenceNode *constSequence, DataType type);
29 |
30 | void typeCheck(SemanticDebugger *semanticDebugger);
31 | void debug(ASTDebugger *astDebugger, int nodeLevel);
32 |
33 | void generateCCode(ostream &out);
34 |
35 |
36 | private:
37 |
38 | list constantList_;
39 |
40 | };
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/source/debugger/debugger_implementations/simple_scanner_debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef SIMPLE_SCANNER_DEBUGGER_H
9 | #define SIMPLE_SCANNER_DEBUGGER_H
10 |
11 | #include "../debugger_interfaces/scanner_debugger.h"
12 |
13 |
14 | class SimpleScannerDebugger: public ScannerDebugger
15 | {
16 |
17 | public:
18 |
19 | SimpleScannerDebugger();
20 |
21 | void debugToken(TokenType tokenType, const char *lexeme, int line, int start_column);
22 | void debugInvalidSymbolError(const char *lexeme, int line, int start_column);
23 | void debugUnterminatedStringError(const char *lexeme, int line, int start_column);
24 | void debugInvalidStringCharacterError(const char *lexeme, int line, int start_column);
25 | void debugUnexpectedEOF(int line);
26 |
27 | protected:
28 |
29 | void createDebugFile(const char *baseFileName);
30 |
31 | };
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/source/ast/statement/return_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef RETURN_NODE_H
9 | #define RETURN_NODE_H
10 |
11 | #include "statement_node.h"
12 | #include "../expression/expression_node.h"
13 |
14 | class ReturnNode : public StatementNode
15 | {
16 |
17 | public:
18 |
19 | ReturnNode(ExpressionNode *expression);
20 | ~ReturnNode();
21 |
22 | DataType getReturnType();
23 |
24 | void typeCheck(SemanticDebugger *semanticDebugger);
25 | bool checkReturn(DataType returnType, SemanticDebugger *semanticDebugger);
26 |
27 | void debug(ASTDebugger *astDebugger, int nodeLevel);
28 |
29 |
30 | void generateCCode(ostream &out);
31 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
32 |
33 | private:
34 |
35 | ExpressionNode *expression_;
36 | DataType returnType_;
37 | };
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/constant_information.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef CONSTANT_INFORMATION_H
9 | #define CONSTANT_INFORMATION_H
10 |
11 | #include "../identifier_information.h"
12 | #include "../data_type.h"
13 |
14 | typedef union _ConstantValue_
15 | {
16 | long intValue;
17 | bool boolValue;
18 |
19 | } ConstantValue;
20 |
21 | class ConstantInformation: public IdentifierInformation
22 | {
23 |
24 | public:
25 |
26 | ConstantInformation();
27 | ConstantInformation(const char *identifier);
28 |
29 | DataType getType() const;
30 | void setType(const DataType type);
31 |
32 | ConstantValue getValue() const;
33 | void setValue(ConstantValue constantValue);
34 |
35 | void debug(SymbolTableDebugger *symbolTableDebugger);
36 |
37 | private:
38 |
39 | DataType type_;
40 | ConstantValue constantValue_;
41 | };
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/source/ast/declaration/variable_list_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef VARIABLE_LIST_NODE_H
9 | #define VARIABLE_LIST_NODE_H
10 |
11 | #include "declaration_node.h"
12 | #include "declaration_sequence_node.h"
13 | #include "variable_node.h"
14 |
15 | #include "../../symbol_table/data_type.h"
16 |
17 | #include
18 | using namespace std;
19 |
20 | class VariableListNode : public DeclarationNode
21 | {
22 |
23 | public:
24 |
25 | VariableListNode();
26 | ~VariableListNode();
27 |
28 | void addVariableSequence(DeclarationSequenceNode *variableSequence,
29 | DataType type);
30 |
31 | void typeCheck(SemanticDebugger *semanticDebugger);
32 | void debug(ASTDebugger *astDebugger, int nodeLevel);
33 |
34 | void generateCCode(ostream &out);
35 |
36 |
37 |
38 | private:
39 |
40 | list variableList_;
41 |
42 | };
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/source/code_generator/code_generator_exception.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "code_generator_exception.h"
9 |
10 | /**
11 | Implementação da classe CodeGeneratorException.
12 | */
13 |
14 | /**
15 | Construtor padrão - inicializa atributo relativo à mensagem de erro vinculada à exceção.
16 |
17 | @param
18 | errorMessage - mensagem de erro vinculada à exceção.
19 | */
20 | CodeGeneratorException::CodeGeneratorException(string errorMessage) throw()
21 | {
22 | this->errorMessage_ = errorMessage;
23 | }
24 |
25 | /**
26 | Destrutor da classe.
27 | */
28 | CodeGeneratorException::~CodeGeneratorException() throw()
29 | {
30 |
31 | }
32 |
33 | /**
34 | Retorna a mensagem de erro vinculada à exceção.
35 |
36 | @return
37 | mensagem de erro vinculada à exceção.
38 | */
39 | const char* CodeGeneratorException::what() const throw()
40 | {
41 | return this->errorMessage_.c_str();
42 | }
43 |
--------------------------------------------------------------------------------
/source/parser/parser.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef PARSER_H
9 | #define PARSER_H
10 |
11 | #include "yy_parser.h"
12 | #include "parser_exception.h"
13 |
14 |
15 | /**
16 | Definição da classe Parser.
17 |
18 | Esta classe encapsula os métodos e funções necessários para executar a análise sintática
19 | (parsing) em um arquivo de código fonte.
20 | */
21 | class Parser
22 | {
23 |
24 | public:
25 |
26 | // Construtor/destrutor.
27 | Parser();
28 | ~Parser();
29 |
30 | // Executa análise sintática no arquivo de código fonte.
31 | void parseSourceFile();
32 |
33 | // Verifica se houve erros ao realizar a análise sintática no arquivo de código fonte.
34 | bool hasError() const;
35 |
36 | // Retorna o número erros encontrados ao realizar a análise sintática no
37 | // arquivo de código fonte.
38 | unsigned int getErrorsCount() const;
39 |
40 | };
41 |
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/copy_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_COPY_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_COPY_INSTRUCTION_H
11 |
12 | #include "instruction.h"
13 |
14 | class CopyInstruction : public Instruction
15 | {
16 | public:
17 |
18 | CopyInstruction(InstructionArgument *src, InstructionArgument *dest);
19 |
20 | void setSourceArgument(InstructionArgument *src);
21 | InstructionArgument *getSourceArgument() const ;
22 |
23 | void setDestinationArgument(InstructionArgument *dest);
24 | InstructionArgument *getDestinationArgument() const ;
25 |
26 | vector *getArgumentsInformation();
27 |
28 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
29 | void debug(ostream &out);
30 | private:
31 |
32 | ArgumentInformation src_;
33 | ArgumentInformation dest_;
34 | };
35 |
36 | #endif
37 |
38 |
39 |
--------------------------------------------------------------------------------
/source/symbol_table/data_type.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef DATA_TYPE_H
9 | #define DATA_TYPE_H
10 |
11 | /**
12 | Enumerações dos possíveis tipos de dados da linguagem Oberon-0.
13 | */
14 | enum DataType
15 | {
16 |
17 | // Tipo criado para simplificar depuração.
18 | // Não corresponde a um tipo real na definição da linguagem.
19 | DATA_TYPE_UNDEFINED,
20 |
21 | // Tipo criado para simplificar a análise semântica.
22 | // Não corresponde a um tipo real na definição da linguagem.
23 | DATA_TYPE_ERROR,
24 |
25 | DATA_TYPE_BOOLEAN,
26 | DATA_TYPE_INTEGER,
27 | DATA_TYPE_STRING,
28 |
29 | // Tipo criado para simplificar a criação da AST e
30 | // análise semântica. Não corresponde a um tipo real
31 | // na definição da linguagem.
32 | DATA_TYPE_VOID,
33 | };
34 |
35 | // Retorna o nome de um tipo de dado.
36 | const char *getDataTypeName(DataType dataType);
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/source/ast/declaration/declaration_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef DECLARATION_NODE_H
9 | #define DECLARATION_NODE_H
10 |
11 | #include "../node.h"
12 |
13 | #include "../../code_generator/intermediate/intermediate_code.h"
14 |
15 | #include "../../code_generator/intermediate/instruction_argument/instruction_argument.h"
16 | #include "../../code_generator/intermediate/instruction_argument/label_argument.h"
17 | #include "../../code_generator/intermediate/instruction_argument/instruction_label.h"
18 |
19 | class DeclarationNode : public Node
20 | {
21 |
22 | public:
23 |
24 | DeclarationNode(const NodeType nodeType);
25 | virtual ~DeclarationNode();
26 |
27 | virtual void typeCheck(SemanticDebugger *semanticDebugger) = 0;
28 |
29 | virtual void generateCCode(ostream &out) = 0;
30 | virtual void generateIntermediateCode(IntermediateCode *intermediateCode){/*make it pure virtual*/};
31 |
32 | };
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/source/ast/declaration/variable_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef VARIABLE_NODE_H
9 | #define VARIABLE_NODE_H
10 |
11 | #include "declaration_node.h"
12 |
13 | #include "../../symbol_table/data_type.h"
14 | #include "../../symbol_table/identifier_category/variable_information.h"
15 |
16 |
17 | class VariableNode : public DeclarationNode
18 | {
19 |
20 | public:
21 |
22 | VariableNode(VariableInformation *variableInfo);
23 | ~VariableNode();
24 |
25 | DataType getType() const;
26 | void setType(const DataType type);
27 |
28 | VariableInformation *getIdentifierInformation();
29 |
30 | const char *getIdentifier() const;
31 |
32 | void typeCheck(SemanticDebugger *semanticDebugger);
33 | void debug(ASTDebugger *astDebugger, int nodeLevel);
34 |
35 | void generateCCode(ostream &out);
36 |
37 |
38 |
39 | private:
40 |
41 | VariableInformation *variableInfo_;
42 | };
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/argument_information.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef ARGUMENT_INFORMATION_H
9 | #define ARGUMENT_INFORMATION_H
10 |
11 | #include "instruction_argument.h"
12 |
13 | #define ARGUMENT_INFORMATION_STATUS_UNDEFINED -999
14 | #define ARGUMENT_INFORMATION_STATUS_NOT_ALIVE -1
15 | #define ARGUMENT_INFORMATION_STATUS_ALIVE_ON_EXIT -2
16 |
17 | class ArgumentInformation
18 | {
19 | public:
20 | ArgumentInformation();
21 | ~ArgumentInformation();
22 |
23 | InstructionArgument * getInstructionArgument() const;
24 | void setInstructionArgument(InstructionArgument * instructionArgument);
25 |
26 | int getStatus() const;
27 | void setStatus(int status);
28 |
29 | const char * getStatusPrefix() const;
30 |
31 | private:
32 |
33 | InstructionArgument * instructionArgument_;
34 | int status_;
35 | char statusPrefix_[32];
36 | };
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/temporary_information.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "temporary_information.h"
9 | #include
10 |
11 | TemporaryInformation::TemporaryInformation()
12 | {
13 | this->setCategoryType(IDENTIFIER_CATEGORY_TYPE_TEMPORARY);
14 | this->number_ = -1;
15 | }
16 |
17 | TemporaryInformation::TemporaryInformation(int number)
18 | {
19 | this->setCategoryType(IDENTIFIER_CATEGORY_TYPE_TEMPORARY);
20 | this->number_ = number;
21 |
22 | }
23 |
24 | int TemporaryInformation::getNumber() const
25 | {
26 | return this->number_;
27 | }
28 |
29 |
30 | void TemporaryInformation::setNumber(int number)
31 | {
32 | this->number_ = number;
33 | }
34 |
35 | void TemporaryInformation::debug(SymbolTableDebugger *symbolTableDebugger)
36 | {
37 | // Debug não aplicável a esta classe uma vez em que objetos da mesma são
38 | // instanciados após a análise de escopos do programa.
39 | }
40 |
--------------------------------------------------------------------------------
/source/ast/expression/arithmetic_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef ARITHMETIC_NODE_H
9 | #define ARITHMETIC_NODE_H
10 |
11 | #include "expression_node.h"
12 |
13 | #include "arithmetic_operator.h"
14 |
15 | class ArithmeticNode : public ExpressionNode
16 | {
17 |
18 | public:
19 |
20 | ArithmeticNode(ExpressionNode *leftOperand, ArithmeticOperator operation, ExpressionNode *rightOperand);
21 | ~ArithmeticNode();
22 |
23 | DataType typeCheck(SemanticDebugger *semanticDebugger);
24 | void debug(ASTDebugger *astDebugger, int nodeLevel);
25 |
26 | void generateCCode(ostream &out);
27 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
28 |
29 | protected:
30 |
31 | void checkConstant();
32 |
33 | private:
34 |
35 | ExpressionNode *leftOperand_;
36 | ArithmeticOperator operation_;
37 | ExpressionNode *rightOperand_;
38 | };
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/source/ast/declaration/module_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef MODULE_NODE_H
9 | #define MODULE_NODE_H
10 |
11 | #include "declaration_node.h"
12 | #include "../statement/statement_node.h"
13 |
14 | #include "../../symbol_table/identifier_category/module_information.h"
15 |
16 | class ModuleNode : public DeclarationNode
17 | {
18 |
19 | public:
20 |
21 | ModuleNode(ModuleInformation *moduleInfo,
22 | DeclarationNode *declarations,
23 | StatementNode *statements);
24 |
25 | ~ModuleNode();
26 |
27 | void typeCheck(SemanticDebugger *semanticDebugger);
28 | void debug(ASTDebugger * astDebugger, int nodeLevel);
29 | void generateCCode(ostream &out);
30 | void generateIntermediateCode(IntermediateCode *intermediateCode);
31 |
32 | private:
33 |
34 | ModuleInformation *moduleInfo_;
35 | DeclarationNode *declarations_;
36 | StatementNode *statements_;
37 |
38 | };
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/source/ast/expression/relational_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef RELATIONAL_NODE_H
9 | #define RELATIONAL_NODE_H
10 |
11 | #include "expression_node.h"
12 | #include "relational_operator.h"
13 |
14 | class RelationalNode : public ExpressionNode
15 | {
16 |
17 | public:
18 |
19 | RelationalNode(ExpressionNode *leftOperand, RelationalOperator operation, ExpressionNode *rightOperand);
20 | ~RelationalNode();
21 |
22 | DataType typeCheck(SemanticDebugger *semanticDebugger);
23 | void debug(ASTDebugger *astDebugger, int nodeLevel);
24 |
25 | void generateCCode(ostream &out);
26 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
27 |
28 | protected:
29 |
30 |
31 | void checkConstant();
32 |
33 | private:
34 |
35 | ExpressionNode *leftOperand_;
36 | RelationalOperator operation_;
37 | ExpressionNode *rightOperand_;
38 | };
39 |
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/negation_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_NEGATION_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_NEGATION_INSTRUCTION_H
11 |
12 | #include "instruction.h"
13 |
14 | class NegationInstruction : public Instruction
15 | {
16 | public:
17 |
18 | NegationInstruction(InstructionArgument *src, InstructionArgument *dest);
19 |
20 | void setSourceArgument(InstructionArgument *src);
21 | InstructionArgument *getSourceArgument() const ;
22 |
23 | void setDestinationArgument(InstructionArgument *dest);
24 | InstructionArgument *getDestinationArgument() const ;
25 |
26 | vector *getArgumentsInformation();
27 |
28 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
29 | void debug(ostream &out);
30 | private:
31 |
32 | ArgumentInformation src_;
33 | ArgumentInformation dest_;
34 | };
35 |
36 | #endif
37 |
38 |
39 |
--------------------------------------------------------------------------------
/source/ast/expression/arithmetic_operator.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "arithmetic_operator.h"
9 |
10 | const char *getArithmeticOperatorName(ArithmeticOperator op)
11 | {
12 | const char * arithmeticOperatorName = "Undefined Arithmetic Operator";
13 |
14 | switch(op)
15 | {
16 |
17 | case ARITHMETIC_OPERATOR_ADD:
18 | arithmeticOperatorName = "Add";
19 | break;
20 |
21 | case ARITHMETIC_OPERATOR_SUB:
22 | arithmeticOperatorName = "Sub";
23 | break;
24 |
25 | case ARITHMETIC_OPERATOR_MULT:
26 | arithmeticOperatorName = "Mult";
27 | break;
28 |
29 | case ARITHMETIC_OPERATOR_DIV:
30 | arithmeticOperatorName = "Div";
31 | break;
32 |
33 | case ARITHMETIC_OPERATOR_MOD:
34 | arithmeticOperatorName = "Mod";
35 | break;
36 |
37 |
38 | default:
39 | break;
40 |
41 | }
42 |
43 | return arithmeticOperatorName;
44 | }
45 |
--------------------------------------------------------------------------------
/source/code_generator/machine/register_descriptor.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef REGISTER_DESCRIPTOR_H
9 | #define REGISTER_DESCRIPTOR_H
10 |
11 | #include "../intermediate/instruction_argument/temporary_argument.h"
12 | #include "../intermediate/instruction_argument/identifier_argument.h"
13 | #include "../../util/integer_hash_table.h"
14 |
15 | #include
16 | #include
17 | using std::list;
18 |
19 | class RegisterDescriptor
20 | {
21 | public:
22 |
23 | RegisterDescriptor();
24 | ~RegisterDescriptor();
25 |
26 | void addVariable(IdentifierInformation *variableInfo);
27 | void addVariables(list *variableInfoList);
28 |
29 | void removeVariable(IdentifierInformation *variableInfo);
30 | void removeAllVariables();
31 |
32 | list *getVariablesList();
33 |
34 | private:
35 |
36 | list identifierInfoList_;
37 |
38 | };
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/source/ast/statement/skip_statement_node.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "skip_statement_node.h"
9 |
10 | #include "../../code_generator/intermediate/instruction/nop_instruction.h"
11 |
12 | SkipStatementNode::SkipStatementNode() : StatementNode(NODE_TYPE_SKIP_STATEMENT)
13 | {
14 |
15 | }
16 |
17 | SkipStatementNode::~SkipStatementNode()
18 | {
19 |
20 | }
21 |
22 | void SkipStatementNode::typeCheck(SemanticDebugger *semanticDebugger)
23 | {
24 | // Type checking não aplicável a este nó.
25 | }
26 |
27 | void SkipStatementNode::debug(ASTDebugger *astDebugger, int nodeLevel)
28 | {
29 | astDebugger->insertLeafNode("{Skip Statement}", nodeLevel);
30 | }
31 |
32 | void SkipStatementNode::generateCCode(ostream &out)
33 | {
34 | }
35 |
36 | void SkipStatementNode::generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector)
37 | {
38 | intermediateCode->addInstruction(instructionVector, new NopInstruction());
39 | }
40 |
--------------------------------------------------------------------------------
/source/ast/declaration/declaration_sequence_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef DECLARATION_SEQUENCE_NODE_H
9 | #define DECLARATION_SEQUENCE_NODE_H
10 |
11 | #include "declaration_node.h"
12 |
13 | class DeclarationSequenceNode : public DeclarationNode
14 | {
15 |
16 | public:
17 |
18 | DeclarationSequenceNode(DeclarationNode *firstDeclaration,
19 | DeclarationNode *nextDeclaration);
20 |
21 | ~DeclarationSequenceNode();
22 |
23 | DeclarationNode * getFirstDeclaration() const;
24 | DeclarationNode * getNextDeclaration() const;
25 |
26 | void typeCheck(SemanticDebugger *semanticDebugger);
27 | void debug(ASTDebugger * astDebugger, int nodeLevel);
28 | void generateCCode(ostream &out);
29 | void generateIntermediateCode(IntermediateCode *intermediateCode);
30 |
31 |
32 |
33 | private:
34 |
35 | DeclarationNode *firstDeclaration_;
36 | DeclarationNode *nextDeclaration_;
37 |
38 | };
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/source/ast/statement/assignment_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef ASSIGNMENT_NODE_H
9 | #define ASSIGNMENT_NODE_H
10 |
11 | #include "statement_node.h"
12 | #include "../expression/expression_node.h"
13 | #include "../expression/identifier_node.h"
14 |
15 | #include "../../symbol_table/data_type.h"
16 |
17 | class AssignmentNode : public StatementNode
18 | {
19 |
20 | public:
21 |
22 | AssignmentNode(IdentifierNode *identifierNode, ExpressionNode *rightExpression);
23 | ~AssignmentNode();
24 |
25 | IdentifierNode *getIdentifier() const;
26 |
27 | void typeCheck(SemanticDebugger *semanticDebugger);
28 |
29 | void debug(ASTDebugger *astDebugger, int nodeLevel);
30 |
31 | void generateCCode(ostream &out);
32 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
33 | private:
34 |
35 | IdentifierNode *identifier_;
36 | ExpressionNode *rightExpression_;
37 |
38 | };
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/source/ast/declaration/formal_parameter_list_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef FORMAL_PARAMETER_LIST_NODE_H
9 | #define FORMAL_PARAMETER_LIST_NODE_H
10 |
11 | #include "declaration_node.h"
12 | #include "declaration_sequence_node.h"
13 | #include "formal_parameter_node.h"
14 |
15 | #include "../../symbol_table/data_type.h"
16 |
17 | #include
18 | using namespace std;
19 |
20 | class FormalParameterListNode : public DeclarationNode
21 | {
22 |
23 | public:
24 |
25 | FormalParameterListNode();
26 | ~FormalParameterListNode();
27 |
28 | void addFormalParameterSequence(DeclarationSequenceNode *formalParameterSequence,
29 | DataType type);
30 |
31 | void typeCheck(SemanticDebugger *semanticDebugger);
32 | void debug(ASTDebugger *astDebugger, int nodeLevel);
33 | void generateCCode(ostream &out);
34 |
35 |
36 | private:
37 |
38 | list formalParameterList_;
39 |
40 | };
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/source/debugger/debugger.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "debugger.h"
9 |
10 | Debugger::Debugger()
11 | {
12 | this->enabled_ = false;
13 | }
14 |
15 | Debugger::~Debugger()
16 | {
17 | if(this->debugFile_.is_open())
18 | {
19 | // Fecha arquivo de debug, caso necessário.
20 | this->debugFile_.close();
21 | }
22 | }
23 |
24 | void Debugger::start(const char *baseFileName)
25 | {
26 | this->stop();
27 |
28 | this->createDebugFile(baseFileName);
29 | this->enabled_ = true;
30 | }
31 |
32 | void Debugger::stop()
33 | {
34 | if(this->debugFile_.is_open())
35 | {
36 | this->preCloseDebugFile();
37 |
38 | // Fecha arquivo de debug, caso necessário.
39 | this->debugFile_.close();
40 |
41 | }
42 |
43 | // Reseta flags de controle I/O.
44 | this->debugFile_.clear();
45 | this->enabled_ = false;
46 | }
47 |
48 | void Debugger::preCloseDebugFile()
49 | {
50 | // Do nothing.
51 | }
52 |
--------------------------------------------------------------------------------
/source/ast/declaration/formal_parameter_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef FORMAL_PARAMETER_NODE_H
9 | #define FORMAL_PARAMETER_NODE_H
10 |
11 | #include "declaration_node.h"
12 |
13 | #include "../../symbol_table/data_type.h"
14 | #include "../../symbol_table/identifier_category/formal_parameter_information.h"
15 |
16 |
17 | class FormalParameterNode : public DeclarationNode
18 | {
19 |
20 | public:
21 |
22 | FormalParameterNode(FormalParameterInformation *formalParameterInfo);
23 | ~FormalParameterNode();
24 |
25 | const char *getIdentifier() const;
26 | FormalParameterInformation *getIdentifierInformation();
27 |
28 | DataType getType() const;
29 | void setType(const DataType type);
30 |
31 | void typeCheck(SemanticDebugger *semanticDebugger);
32 | void debug(ASTDebugger *astDebugger, int nodeLevel);
33 | void generateCCode(ostream &out);
34 |
35 |
36 | private:
37 |
38 | FormalParameterInformation * formalParameterInfo_;
39 |
40 | };
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/identifier_argument.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #include "identifier_argument.h"
10 |
11 | #include
12 |
13 | IdentifierArgument::IdentifierArgument(IdentifierInformation *information)
14 | : InstructionArgument(INSTRUCTION_ARGUMENT_TYPE_IDENTIFIER)
15 | {
16 | setIdentifierInformation(information);
17 | }
18 |
19 | void IdentifierArgument::setIdentifierInformation(IdentifierInformation *information)
20 | {
21 | this->information_ = information;
22 | }
23 |
24 | IdentifierInformation *IdentifierArgument::getIdentifierInformation()
25 | {
26 | return this->information_;
27 | }
28 |
29 | void IdentifierArgument::debug(CodeGeneratorDebugger * codeGeneratorDebugger)
30 | {
31 | const char *str = information_->getIdentifier();
32 |
33 | codeGeneratorDebugger->debugCode(str);
34 |
35 | }
36 |
37 | void IdentifierArgument::debug(ostream &out)
38 | {
39 | const char *str = information_->getIdentifier();
40 |
41 | out << str;
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/instruction_label.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "instruction_label.h"
9 |
10 | #include
11 | using namespace std;
12 |
13 | InstructionLabel::InstructionLabel(const int labelNumber)
14 | : LabelArgument(INSTRUCTION_ARGUMENT_TYPE_INSTUCTION_LABEL)
15 | {
16 | setLabelNumber(labelNumber);
17 | }
18 |
19 | void InstructionLabel::setLabelNumber(const int labelNumber)
20 | {
21 | this->labelNumber_ = labelNumber;
22 | }
23 |
24 | int InstructionLabel::getLabelNumber() const
25 | {
26 | return this->labelNumber_;
27 | }
28 |
29 | void InstructionLabel::debug(CodeGeneratorDebugger * codeGeneratorDebugger)
30 | {
31 | stringstream strValue;
32 |
33 | strValue << "L" << labelNumber_;
34 | codeGeneratorDebugger->debugCode(strValue.str().c_str());
35 |
36 | }
37 |
38 | void InstructionLabel::debug(ostream &out)
39 | {
40 | stringstream strValue;
41 |
42 | strValue << "L" << labelNumber_;
43 | out << strValue.str().c_str();
44 | }
45 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/module_information.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "module_information.h"
9 | #include
10 |
11 | ModuleInformation::ModuleInformation()
12 | {
13 |
14 | this->setCategoryType(IDENTIFIER_CATEGORY_TYPE_MODULE);
15 | }
16 |
17 | ModuleInformation::ModuleInformation(const char *identifier)
18 | : IdentifierInformation(IDENTIFIER_CATEGORY_TYPE_MODULE, identifier)
19 | {
20 |
21 | }
22 |
23 | void ModuleInformation::debug(SymbolTableDebugger *symbolTableDebugger)
24 | {
25 | const char *categoryTypeName = getIdentifierCategoryTypeName( this->getCategoryType() );
26 |
27 | stringstream scopeLevelStr;
28 | scopeLevelStr << this->getScopeLevel();
29 |
30 | symbolTableDebugger->debugIdentifierInfo(categoryTypeName);
31 | symbolTableDebugger->debugIdentifierInfoAttribute("Identifier", this->getIdentifier());
32 | symbolTableDebugger->debugIdentifierInfoAttribute("Scope Level", scopeLevelStr.str().c_str());
33 |
34 | symbolTableDebugger->newLine();
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/source/ast/expression/actual_parameter_list_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef ACTUAL_PARAMETER_LIST_NODE_H
9 | #define ACTUAL_PARAMETER_LIST_NODE_H
10 |
11 | #include "expression_node.h"
12 | #include "../../symbol_table/data_type.h"
13 |
14 | #include
15 | using namespace std;
16 |
17 | class ActualParameterListNode : public ExpressionNode
18 | {
19 |
20 | public:
21 |
22 | ActualParameterListNode();
23 | ~ActualParameterListNode();
24 |
25 | list & getActualParameterList();
26 | void addActualParameter(ExpressionNode *expression);
27 |
28 | DataType typeCheck(SemanticDebugger *semanticDebugger);
29 | void debug(ASTDebugger *astDebugger, int nodeLevel);
30 |
31 | void generateCCode(ostream &out);
32 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
33 |
34 | protected:
35 |
36 | void checkConstant();
37 |
38 | private:
39 |
40 | list actualParameterList_;
41 |
42 | };
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/source/code_generator/machine/variable_descriptor.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef VARIABLE_DESCRIPTOR_H
9 | #define VARIABLE_DESCRIPTOR_H
10 |
11 | #include "../intermediate/instruction_argument/identifier_argument.h"
12 | #include "../intermediate/instruction_argument/temporary_argument.h"
13 | #include "../../util/integer_hash_table.h"
14 |
15 | #include
16 | #include
17 | using std::list;
18 |
19 | class VariableDescriptor
20 | {
21 | public:
22 |
23 | VariableDescriptor();
24 | ~VariableDescriptor();
25 |
26 | void addRegister(int reg);
27 | void addRegisters(list * registers);
28 |
29 | void removeRegister(int reg);
30 | void removeAllRegisters();
31 |
32 | list *getRegistersList();
33 |
34 | void setInMemory(bool inMemory);
35 | bool isInMemory() const;
36 |
37 | void setAlive(bool alive);
38 | bool isAlive() const;
39 |
40 | private:
41 |
42 | list registersList_;
43 | bool inMemory_;
44 | bool alive_;
45 |
46 | };
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/function_information.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef FUNCTION_INFORMATION_H
9 | #define FUNCTION_INFORMATION_H
10 |
11 | #include "../identifier_information.h"
12 | #include "../data_type.h"
13 | #include "formal_parameter_information.h"
14 | #include "variable_information.h"
15 |
16 | #include
17 | using namespace std;
18 |
19 | class FunctionInformation: public IdentifierInformation
20 | {
21 |
22 | public:
23 |
24 | FunctionInformation();
25 | FunctionInformation(const char *identifier);
26 |
27 | DataType getReturnType() const;
28 | void setReturnType(DataType returnType);
29 |
30 | list & getFormalParameterList();
31 | list & getVariableList();
32 |
33 | void debug(SymbolTableDebugger *symbolTableDebugger);
34 |
35 | private:
36 |
37 | list formalParameterList_;
38 | list variableList_;
39 |
40 | DataType returnType_;
41 | };
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/source/symbol_table/scope.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef SCOPE_H
9 | #define SCOPE_H
10 |
11 | #include "identifier_information.h"
12 | #include "../debugger/debugger_interfaces/symbol_table_debugger.h"
13 | #include "../util/hash_table.h"
14 |
15 | #include
16 | using namespace std;
17 |
18 | #define SCOPE_HASH_TABLE_SIZE 127
19 |
20 | /**
21 | Definição da classe utilizada para representar um escopo de um programa.
22 | */
23 | class Scope
24 | {
25 |
26 | public:
27 |
28 | Scope(const char *name);
29 | ~Scope();
30 |
31 | const char *getName() const;
32 | void setName(const char *name);
33 |
34 | void insertIdentifierInfo(IdentifierInformation *identifierInfo);
35 | IdentifierInformation *findInfoByIdentifier(const char *identifier);
36 |
37 |
38 | void debug(SymbolTableDebugger *symbolTableDebugger);
39 |
40 | private:
41 | char *name_;
42 |
43 | HashTable *identifierInfoMap_;
44 | list orderedInsertedInfo_;
45 | };
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/immediate_argument.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "immediate_argument.h"
9 |
10 | #include
11 | using namespace std;
12 |
13 | ImmediateArgument::ImmediateArgument(const long immediateValue)
14 | : InstructionArgument(INSTRUCTION_ARGUMENT_TYPE_IMMEDIATE)
15 | {
16 | setImmediateValue(immediateValue);
17 | }
18 |
19 | void ImmediateArgument::setImmediateValue(const long immediateValue)
20 | {
21 | this->immediateValue_ = immediateValue;
22 | }
23 |
24 | long ImmediateArgument::getImmediateValue() const
25 | {
26 | return this->immediateValue_;
27 | }
28 |
29 | void ImmediateArgument::debug(CodeGeneratorDebugger * codeGeneratorDebugger)
30 | {
31 | stringstream strValue;
32 |
33 | strValue << immediateValue_;
34 | codeGeneratorDebugger->debugCode(strValue.str().c_str());
35 | }
36 |
37 | void ImmediateArgument::debug(ostream &out)
38 | {
39 | stringstream strValue;
40 |
41 | strValue << immediateValue_;
42 | out << strValue.str().c_str();
43 | }
44 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/nop_instruction.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #include "nop_instruction.h"
10 |
11 | NopInstruction::NopInstruction()
12 | : Instruction(INSTRUCTION_TYPE_NOP)
13 | {}
14 |
15 | vector *NopInstruction::getArgumentsInformation()
16 | {
17 | vector *args = new vector();
18 | args->push_back(NULL);
19 | return args;
20 | }
21 |
22 | void NopInstruction::debug(CodeGeneratorDebugger * codeGeneratorDebugger)
23 | {
24 |
25 | if(getLabel())
26 | {
27 | getLabel()->debug(codeGeneratorDebugger);
28 |
29 |
30 | codeGeneratorDebugger->debugCode(":");
31 | }
32 |
33 |
34 | codeGeneratorDebugger->debugCode("\tNop ( )\n");
35 | }
36 |
37 | void NopInstruction::debug(ostream &out)
38 | {
39 |
40 | if(getLabel())
41 | {
42 | getLabel()->debug(out);
43 | out << ": ";
44 | }
45 |
46 | out << "Nop ( )";
47 | out << "\t\t\t ---";
48 | out << "\t ---";
49 | out << "\t ---";
50 |
51 | out << endl;
52 | }
53 |
--------------------------------------------------------------------------------
/source/ast/statement/procedure_call_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef PROCEDURE_CALL_NODE_H
9 | #define PROCEDURE_CALL_NODE_H
10 |
11 | #include "statement_node.h"
12 | #include "../expression/expression_node.h"
13 | #include "../expression/actual_parameter_list_node.h"
14 |
15 | #include "../../symbol_table/data_type.h"
16 | #include "../../symbol_table/identifier_category/function_information.h"
17 |
18 |
19 | class ProcedureCallNode : public StatementNode
20 | {
21 |
22 | public:
23 |
24 | ProcedureCallNode(FunctionInformation *functionInfo, ActualParameterListNode* actualParameterList);
25 | ~ProcedureCallNode();
26 |
27 | const char *getIdentifier();
28 |
29 | void typeCheck(SemanticDebugger *semanticDebugger);
30 |
31 | void debug(ASTDebugger *astDebugger, int nodeLevel);
32 |
33 | void generateCCode(ostream &out);
34 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
35 | private:
36 |
37 | FunctionInformation * functionInfo_;
38 | ActualParameterListNode * actualParameterList_;
39 |
40 | };
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/instruction_argument.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef INTERMEDIATE_CODE_INSTRUCTION_ARGUMENT_H
9 | #define INTERMEDIATE_CODE_INSTRUCTION_ARGUMENT_H
10 |
11 | #include "../../../debugger/debugger_interfaces/code_generator_debugger.h"
12 |
13 | enum InstructionArgumentType
14 | {
15 | INSTRUCTION_ARGUMENT_TYPE_IDENTIFIER,
16 | INSTRUCTION_ARGUMENT_TYPE_IMMEDIATE,
17 | INSTRUCTION_ARGUMENT_TYPE_LABEL,
18 | INSTRUCTION_ARGUMENT_TYPE_INSTUCTION_LABEL,
19 | INSTRUCTION_ARGUMENT_TYPE_FUNCTION_LABEL,
20 | INSTRUCTION_ARGUMENT_TYPE_TEMPORARY,
21 | INSTRUCTION_ARGUMENT_TYPE_STRING
22 | };
23 |
24 | class InstructionArgument
25 | {
26 |
27 | public:
28 |
29 | InstructionArgument(const InstructionArgumentType type);
30 | virtual ~InstructionArgument();
31 |
32 | virtual void debug(CodeGeneratorDebugger * codeGeneratorDebugger) = 0;
33 | virtual void debug(ostream &out) = 0;
34 |
35 | const InstructionArgumentType getType();
36 |
37 | private:
38 | InstructionArgumentType type_;
39 |
40 |
41 | };
42 |
43 | #endif
44 |
45 |
46 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/call_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_CALL_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_CALL_INSTRUCTION_H
11 |
12 | #include "instruction.h"
13 |
14 | class CallInstruction: public Instruction
15 | {
16 | public:
17 | CallInstruction(InstructionArgument *firstArg, InstructionArgument *secondArg, InstructionArgument *dest=NULL);
18 |
19 | void setFirstArgument(InstructionArgument *firstArg);
20 | InstructionArgument *getFirstArgument() const ;
21 |
22 | void setSecondArgument(InstructionArgument *secondArg);
23 | InstructionArgument *getSecondArgument() const ;
24 |
25 | void setDestinationArgument(InstructionArgument *dest);
26 | InstructionArgument *getDestinationArgument() const ;
27 |
28 | vector *getArgumentsInformation();
29 |
30 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
31 | void debug(ostream &out);
32 | private:
33 | ArgumentInformation firstArg_;
34 | ArgumentInformation secondArg_;
35 | ArgumentInformation dest_;
36 | };
37 |
38 | #endif
39 |
40 |
41 |
--------------------------------------------------------------------------------
/source/debugger/debugger_implementations/simple_symbol_table_debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef SIMPLE_SYMBOL_TABLE_DEBUGGER_H
9 | #define SIMPLE_SYMBOL_TABLE_DEBUGGER_H
10 |
11 | #include "../debugger_interfaces/symbol_table_debugger.h"
12 |
13 | class SimpleSymbolTableDebugger: public SymbolTableDebugger
14 | {
15 |
16 | public:
17 |
18 | SimpleSymbolTableDebugger();
19 |
20 | void debugScopeStart(const char *scopeName);
21 | void debugScopeEnd();
22 | void debugIdentifierInfo(const char *name);
23 | void debugIdentifierInfoAttribute(const char *name, const char *value);
24 | void debugIdentifierInfoAttribute(const char *name, int value);
25 | void debugIdentifierInfoAttribute(const char *name, bool value);
26 |
27 | void newLine();
28 |
29 | void debugIdentifierNotDeclared(const char *identifier, int lineNumber);
30 | void debugIdentifierAlreadyDeclared(const char *identifier, int lineNumber);
31 | void debugUnexpectedUseOfIdentifier(const char *identifier, int lineNumber);
32 |
33 | protected:
34 |
35 | void createDebugFile(const char *baseFileName);
36 |
37 | };
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/source/ast/declaration/constant_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef CONSTANT_NODE_H
9 | #define CONSTANT_NODE_H
10 |
11 | #include "declaration_node.h"
12 | #include "../expression/expression_node.h"
13 |
14 | #include "../../symbol_table/data_type.h"
15 | #include "../../symbol_table/identifier_category/constant_information.h"
16 |
17 |
18 | class ConstantNode : public DeclarationNode
19 | {
20 |
21 | public:
22 |
23 | ConstantNode(ConstantInformation *constantInformation,
24 | ExpressionNode *expressionValue);
25 | ~ConstantNode();
26 |
27 | DataType getType() const;
28 | void setType(const DataType DataType);
29 |
30 | ExpressionNode *getExpressionValue() const;
31 | void setExpressionValue(ExpressionNode *expressionValue);
32 |
33 | const char *getIdentifier() const;
34 |
35 | void typeCheck(SemanticDebugger *semanticDebugger);
36 | void debug(ASTDebugger * astDebugger, int nodeLevel);
37 | void generateCCode(ostream &out);
38 |
39 |
40 | private:
41 |
42 | ConstantInformation *constantInformation_;
43 | ExpressionNode *expressionValue_;
44 |
45 | };
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/source/ast/statement/statement_sequence_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef STATEMENT_SEQUENCE_NODE_H
9 | #define STATEMENT_SEQUENCE_NODE_H
10 |
11 | #include "statement_node.h"
12 | #include "conditional_node.h"
13 | #include "loop_node.h"
14 | #include "break_node.h"
15 | #include "continue_node.h"
16 |
17 | class StatementSequenceNode : public StatementNode
18 | {
19 |
20 | public:
21 |
22 | StatementSequenceNode(StatementNode *firstStatement, StatementNode *nextStatement);
23 | ~StatementSequenceNode();
24 | int getFirstLine() const;
25 |
26 | void typeCheck(SemanticDebugger *semanticDebugger);
27 | bool checkRepetition(const bool inRepetition, SemanticDebugger * semanticDebugger);
28 | bool checkReturn(DataType returnType, SemanticDebugger *semanticDebugger);
29 |
30 | void debug(ASTDebugger *astDebugger, int nodeLevel);
31 |
32 |
33 | void generateCCode(ostream &out);
34 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
35 | private:
36 |
37 | StatementNode *firstStatement_;
38 | StatementNode *nextStatement_;
39 |
40 | };
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/source/debugger/debugger_interfaces/symbol_table_debugger.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef SYMBOL_TABLE_DEBUGGER_H
9 | #define SYMBOL_TABLE_DEBUGGER_H
10 |
11 | #include "../debugger.h"
12 | #include "../../parser/parser_exception.h"
13 |
14 | // Função para exibição de erros sintáticos, definida externamente (yy_parser.cpp),
15 | // que será utilizada por implementações de debuggers para a Tabela de Símbolos.
16 | extern void yyerror(const char* errmsg);
17 |
18 | class SymbolTableDebugger: public Debugger
19 | {
20 |
21 | public:
22 |
23 | virtual void debugScopeStart(const char *scopeName) = 0;
24 | virtual void debugScopeEnd() = 0;
25 |
26 | virtual void debugIdentifierInfo(const char *name) = 0;
27 | virtual void debugIdentifierInfoAttribute(const char *name, const char *value) = 0;
28 |
29 | virtual void newLine() = 0;
30 |
31 | virtual void debugIdentifierNotDeclared(const char *identifier, int lineNumber) = 0;
32 | virtual void debugIdentifierAlreadyDeclared(const char *identifier, int lineNumber) = 0;
33 | virtual void debugUnexpectedUseOfIdentifier(const char *identifier, int lineNumber) = 0;
34 |
35 | };
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/source/ast/expression/function_call_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef FUNCTION_CALL_NODE_H
9 | #define FUNCTION_CALL_NODE_H
10 |
11 | #include "expression_node.h"
12 | #include "actual_parameter_list_node.h"
13 |
14 | #include "../../symbol_table/data_type.h"
15 | #include "../../symbol_table/identifier_category/function_information.h"
16 |
17 |
18 | class FunctionCallNode : public ExpressionNode
19 | {
20 |
21 | public:
22 |
23 | FunctionCallNode(FunctionInformation *functionInfo, ActualParameterListNode *actualParameterList);
24 | ~FunctionCallNode();
25 |
26 |
27 | const char *getIdentifier();
28 |
29 | void setReturnType(const DataType type);
30 | DataType getReturnType() const;
31 |
32 | DataType typeCheck(SemanticDebugger *semanticDebugger);
33 | void debug(ASTDebugger *astDebugger, int nodeLevel);
34 |
35 | void generateCCode(ostream &out);
36 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
37 |
38 | protected:
39 |
40 |
41 | void checkConstant();
42 |
43 | private:
44 |
45 | FunctionInformation * functionInfo_;
46 | ActualParameterListNode * actualParameterList_;
47 |
48 | };
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/source/ast/statement/conditional_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef CONDITIONAL_NODE_H
9 | #define CONDITIONAL_NODE_H
10 |
11 | #include "statement_node.h"
12 | #include "../expression/expression_node.h"
13 | #include "statement_sequence_node.h"
14 |
15 | #include "../../symbol_table/data_type.h"
16 |
17 |
18 | class ConditionalNode : public StatementNode
19 | {
20 |
21 | public:
22 |
23 | ConditionalNode(ExpressionNode *expression,
24 | StatementNode *firstStatement,
25 | StatementNode *nextStatement);
26 |
27 | ~ConditionalNode();
28 |
29 |
30 | void typeCheck(SemanticDebugger *semanticDebugger);
31 | bool checkRepetition(const bool inRepetition, SemanticDebugger *semanticDebugger);
32 | bool checkReturn(DataType returnType, SemanticDebugger *semanticDebugger);
33 |
34 | void debug(ASTDebugger *astDebugger, int nodeLevel);
35 |
36 | void generateCCode(ostream &out);
37 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
38 |
39 | private:
40 |
41 | ExpressionNode *expression_;
42 | StatementNode *firstStatement_;
43 | StatementNode *nextStatement_;
44 |
45 | };
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/source/ast/statement/write_line_node.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "write_line_node.h"
9 |
10 | #include "../../code_generator/intermediate/instruction/write_instruction.h"
11 |
12 | #include "../../code_generator/intermediate/instruction_argument/string_argument.h"
13 |
14 | WriteLineNode::WriteLineNode() : StatementNode(NODE_TYPE_WRITE_LINE)
15 | {
16 |
17 | }
18 |
19 | WriteLineNode::~WriteLineNode()
20 | {
21 |
22 | }
23 |
24 | void WriteLineNode::typeCheck(SemanticDebugger *semanticDebugger)
25 | {
26 | // Type Check não aplicável a este nodo.
27 | }
28 |
29 | void WriteLineNode::debug(ASTDebugger *astDebugger, int nodeLevel)
30 | {
31 | astDebugger->insertLeafNode("{Write New Line}", nodeLevel);
32 | }
33 |
34 |
35 | void WriteLineNode::generateCCode(ostream &out)
36 | {
37 | out << "printf(\"\\n\");" << endl;
38 | }
39 |
40 | void WriteLineNode::generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector)
41 | {
42 | StringArgument *stringArgument = new StringArgument("\"\\n\"");
43 | intermediateCode->addInstruction(instructionVector, new WriteInstruction( stringArgument ) );
44 | intermediateCode->addInstructionArgumentToCleanUpList( stringArgument );
45 | }
46 |
--------------------------------------------------------------------------------
/source/ast/statement/loop_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef LOOP_NODE_H
9 | #define LOOP_NODE_H
10 |
11 | #include "statement_node.h"
12 | #include "statement_sequence_node.h"
13 | #include "../expression/expression_node.h"
14 |
15 | class LoopNode : public StatementNode
16 | {
17 |
18 | public:
19 |
20 | LoopNode(const NodeType nodeType, StatementNode *statement, ExpressionNode *expression);
21 | ~LoopNode();
22 |
23 | void typeCheck(SemanticDebugger *semanticDebugger);
24 | bool checkRepetition(const bool inRepetition, SemanticDebugger * semanticDebugger);
25 | bool checkReturn(DataType returnType, SemanticDebugger *semanticDebugger);
26 |
27 | StatementNode *getStatement();
28 | void setStatement(StatementNode *statement);
29 |
30 | ExpressionNode *getExpression();
31 | void setExpression(ExpressionNode *expression);
32 |
33 | virtual void debug(ASTDebugger *astDebugger, int nodeLevel) = 0;
34 |
35 | virtual void generateCCode(ostream &out) = 0;
36 | virtual void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector) = 0;
37 |
38 | private:
39 |
40 | StatementNode *statement_;
41 | ExpressionNode *expression_;
42 |
43 | };
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/temporary_argument.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "temporary_argument.h"
9 | #include
10 | using namespace std;
11 |
12 | TemporaryArgument::TemporaryArgument(TemporaryInformation * temporaryInformation)
13 | : InstructionArgument(INSTRUCTION_ARGUMENT_TYPE_TEMPORARY)
14 | {
15 | this->temporaryInformation_ = temporaryInformation;
16 | }
17 |
18 | void TemporaryArgument::setNumber(const int number)
19 | {
20 | this->temporaryInformation_->setNumber(number);
21 | }
22 |
23 | int TemporaryArgument::getNumber() const
24 | {
25 | return this->temporaryInformation_->getNumber();
26 | }
27 |
28 | TemporaryInformation *TemporaryArgument::getTemporaryInformation() const
29 | {
30 |
31 | return this->temporaryInformation_;
32 | }
33 |
34 | void TemporaryArgument::debug(CodeGeneratorDebugger * codeGeneratorDebugger)
35 | {
36 | stringstream strValue;
37 |
38 | strValue << "%reg" << this->getNumber();
39 | codeGeneratorDebugger->debugCode(strValue.str().c_str());
40 | }
41 |
42 | void TemporaryArgument::debug(ostream &out)
43 | {
44 | stringstream strValue;
45 |
46 | strValue << "%reg" << this->getNumber();
47 | out << strValue.str().c_str();
48 | }
49 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/string_argument.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "string_argument.h"
9 |
10 | #include
11 | #include
12 | using namespace std;
13 |
14 | StringArgument::StringArgument(const char *stringValue)
15 | : InstructionArgument(INSTRUCTION_ARGUMENT_TYPE_STRING), stringValue_(0)
16 | {
17 | setStringValue(stringValue);
18 | }
19 |
20 | StringArgument::~StringArgument()
21 | {
22 | delete []stringValue_;
23 | }
24 |
25 | void StringArgument::setStringValue(const char *stringValue)
26 | {
27 | delete []stringValue_;
28 |
29 | this->stringValue_ = new char[strlen(stringValue)+1];
30 | strcpy(this->stringValue_, stringValue);
31 | }
32 |
33 | char *StringArgument::getStringValue() const
34 | {
35 | return this->stringValue_;
36 | }
37 |
38 | void StringArgument::debug(CodeGeneratorDebugger * codeGeneratorDebugger)
39 | {
40 | stringstream strValue;
41 | strValue << this->stringValue_;
42 |
43 | codeGeneratorDebugger->debugCode(strValue.str().c_str());
44 | }
45 |
46 | void StringArgument::debug(ostream &out)
47 | {
48 | stringstream strValue;
49 | strValue << this->stringValue_;
50 |
51 | out << strValue.str().c_str();
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/identifier_category_type.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef IDENTIFIER_CATEGORY_TYPE_H
9 | #define IDENTIFIER_CATEGORY_TYPE_H
10 |
11 | /**
12 | Enumeração dos possíveis tipos de categorias vinculadas a identificadores.
13 | Esses tipos são especificados em subclasses da classe Information, sendo objetos
14 | destas subclasses inseridas na tabela de símbolos durante a fase de parsing.
15 |
16 | @see Parser
17 |
18 | @see Information
19 |
20 | @see ModuleInfo
21 | @see ProcedureInfo
22 | @see FunctionInfo
23 | @see ConstantInformation
24 | @see VariableInformation
25 | @see FormalParameterInformation
26 |
27 | @see SymbolTable
28 |
29 | */
30 | enum IdentifierCategoryType
31 | {
32 | IDENTIFIER_CATEGORY_TYPE_UNDEFINED,
33 | IDENTIFIER_CATEGORY_TYPE_MODULE,
34 | IDENTIFIER_CATEGORY_TYPE_PROCEDURE,
35 | IDENTIFIER_CATEGORY_TYPE_FUNCTION,
36 | IDENTIFIER_CATEGORY_TYPE_CONSTANT,
37 | IDENTIFIER_CATEGORY_TYPE_VARIABLE,
38 | IDENTIFIER_CATEGORY_TYPE_FORMAL_PARAMETER,
39 | IDENTIFIER_CATEGORY_TYPE_TEMPORARY
40 | };
41 |
42 | // Retorna o nome associado a uma categoria de identificador.
43 | const char *getIdentifierCategoryTypeName(IdentifierCategoryType categoryType);
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/source/debugger/debugger_utils.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "debugger_utils.h"
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | char * getDebugFileName(const char *baseFileName, const char *extension)
15 | {
16 | const char *baseFileExtension = strrchr(baseFileName, '.');
17 | size_t debugFileExtensionLen = strlen(extension) + 1 ; // '.' + extension
18 |
19 | char *debugFileName;
20 |
21 | if(baseFileExtension != NULL)
22 | {
23 | // [baseFileName]'.'
24 | size_t baseFileNameLen = (size_t)baseFileExtension - (size_t)baseFileName;
25 |
26 | debugFileName = new char[baseFileNameLen + debugFileExtensionLen + 1];
27 |
28 | // baseFileName + '.'
29 | strncpy(debugFileName, baseFileName, baseFileNameLen+1);
30 | debugFileName[baseFileNameLen+1] = '\0';
31 |
32 | // extension + '\0'
33 | strcat(debugFileName, extension);
34 | }
35 | else
36 | {
37 | size_t baseFileNameLen = strlen(baseFileName);
38 |
39 | // baseFileName + '.' + extension + '\0'
40 | debugFileName = new char[baseFileNameLen + debugFileExtensionLen + 1];
41 | sprintf(debugFileName, "%s.%s", baseFileName, extension);
42 | }
43 |
44 | return debugFileName;
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/source/symbol_table/identifier_category/identifier_category_type.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #include "identifier_category_type.h"
9 |
10 | const char *getIdentifierCategoryTypeName(IdentifierCategoryType categoryType)
11 | {
12 | const char * categoryTypeName = 0;
13 |
14 | switch(categoryType)
15 | {
16 |
17 | case IDENTIFIER_CATEGORY_TYPE_FORMAL_PARAMETER:
18 | categoryTypeName = "Formal Parameter";
19 | break;
20 |
21 | case IDENTIFIER_CATEGORY_TYPE_FUNCTION:
22 | categoryTypeName = "Function";
23 | break;
24 |
25 | case IDENTIFIER_CATEGORY_TYPE_MODULE:
26 | categoryTypeName = "Module";
27 | break;
28 |
29 | case IDENTIFIER_CATEGORY_TYPE_PROCEDURE:
30 | categoryTypeName = "Procedure";
31 | break;
32 |
33 | case IDENTIFIER_CATEGORY_TYPE_UNDEFINED:
34 | categoryTypeName = "Undefined";
35 | break;
36 |
37 | case IDENTIFIER_CATEGORY_TYPE_CONSTANT:
38 | categoryTypeName = "Constant";
39 | break;
40 |
41 | case IDENTIFIER_CATEGORY_TYPE_VARIABLE:
42 | categoryTypeName = "Variable";
43 | break;
44 |
45 |
46 | case IDENTIFIER_CATEGORY_TYPE_TEMPORARY:
47 | categoryTypeName = "Temporary";
48 | break;
49 | }
50 |
51 | return categoryTypeName;
52 | }
53 |
--------------------------------------------------------------------------------
/source/ast/expression/identifier_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef IDENTIFIER_NODE_H
9 | #define IDENTIFIER_NODE_H
10 |
11 | #include "expression_node.h"
12 |
13 | #include "../../symbol_table/data_type.h"
14 | #include "../../symbol_table/identifier_information.h"
15 | #include "../../symbol_table/identifier_category/constant_information.h"
16 | #include "../../symbol_table/identifier_category/variable_information.h"
17 | #include "../../symbol_table/identifier_category/formal_parameter_information.h"
18 |
19 |
20 | class IdentifierNode : public ExpressionNode
21 | {
22 | public:
23 |
24 | IdentifierNode(IdentifierInformation *identifierInfo);
25 | ~IdentifierNode();
26 |
27 | IdentifierInformation *getIdentifierInformation();
28 | const char *getIdentifier() const;
29 | IdentifierCategoryType getCategoryType() const;
30 | DataType getType() const;
31 |
32 | DataType typeCheck(SemanticDebugger *semanticDebugger);
33 | void debug(ASTDebugger *astDebugger, int nodeLevel);
34 |
35 | void generateCCode(ostream &out);
36 | void generateIntermediateCode(IntermediateCode *intermediateCode, vector*instructionVector);
37 |
38 | protected:
39 |
40 | void checkConstant();
41 |
42 | private:
43 |
44 | IdentifierInformation *identifierInfo_;
45 | };
46 |
47 | #endif
48 |
49 |
--------------------------------------------------------------------------------
/source/ast/declaration/function_node.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef FUNCTION_NODE_H
9 | #define FUNCTION_NODE_H
10 |
11 | #include "declaration_node.h"
12 | #include "../statement/statement_node.h"
13 |
14 | #include "../../symbol_table/data_type.h"
15 | #include "../../symbol_table/identifier_category/function_information.h"
16 |
17 |
18 | class FunctionNode : public DeclarationNode
19 | {
20 | public:
21 |
22 | FunctionNode(FunctionInformation *functionInfo,
23 | DeclarationNode *declarations,
24 | StatementNode *statements);
25 |
26 | ~FunctionNode();
27 |
28 | const char *getIdentifier();
29 |
30 | DataType getReturnType() const;
31 | void setReturnType(const DataType returnType);
32 |
33 | void setDeclarations(DeclarationNode *declarations);
34 | DeclarationNode * getDeclarations() const;
35 |
36 | void setStatements(StatementNode *statements);
37 | StatementNode * getStatements() const;
38 |
39 | void typeCheck(SemanticDebugger *semanticDebugger);
40 | void debug(ASTDebugger * astDebugger, int nodeLevel);
41 | void generateCCode(ostream &out);
42 | void generateIntermediateCode(IntermediateCode *intermediateCode);
43 |
44 | private:
45 |
46 | FunctionInformation *functionInfo_;
47 | DeclarationNode *declarations_;
48 | StatementNode *statements_;
49 |
50 | };
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction/conditional_goto_instruction.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #ifndef INTERMEDIATE_CODE_CONDITIONAL_GOTO_INSTRUCTION_H
10 | #define INTERMEDIATE_CODE_CONDITIONAL_GOTO_INSTRUCTION_H
11 |
12 | #include "../../../ast/expression/relational_operator.h"
13 | #include "instruction.h"
14 |
15 | class ConditionalGotoInstruction : public Instruction
16 | {
17 | public:
18 |
19 | ConditionalGotoInstruction(RelationalOperator op, InstructionArgument *firstArg, InstructionArgument *secondArg, LabelArgument *label);
20 |
21 | void setRelationalOperator(RelationalOperator op);
22 | RelationalOperator getRelationalOperator();
23 |
24 | void setFirstArgument(InstructionArgument *firstArg);
25 | InstructionArgument *getFirstArgument() const ;
26 |
27 | void setSecondArgument(InstructionArgument *secondArg);
28 | InstructionArgument *getSecondArgument() const ;
29 |
30 | void setLabelArgument(LabelArgument *label);
31 | LabelArgument *getLabelArgument() const ;
32 |
33 | vector *getArgumentsInformation();
34 |
35 | void debug(CodeGeneratorDebugger * codeGeneratorDebugger);
36 | void debug(ostream &out);
37 |
38 | private:
39 |
40 | RelationalOperator relationalOperator_;
41 | ArgumentInformation firstArg_;
42 | ArgumentInformation secondArg_;
43 | LabelArgument *label_;
44 | };
45 |
46 | #endif
47 |
48 |
49 |
--------------------------------------------------------------------------------
/source/code_generator/intermediate/instruction_argument/function_label.cpp:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 |
9 | #include "function_label.h"
10 |
11 | #include
12 | #include
13 | using namespace std;
14 |
15 | FunctionLabel::FunctionLabel(const char *labelString)
16 | : LabelArgument(INSTRUCTION_ARGUMENT_TYPE_INSTUCTION_LABEL), labelString_(0)
17 | {
18 | setLabelString(labelString);
19 | }
20 |
21 | FunctionLabel::~FunctionLabel()
22 | {
23 | delete [] labelString_;
24 | }
25 |
26 | void FunctionLabel::setLabelString(const char *labelString)
27 | {
28 | if(this->labelString_)
29 | {
30 | delete [] this->labelString_;
31 | this->labelString_ = 0;
32 | }
33 |
34 | if(labelString)
35 | {
36 | this->labelString_ = new char[strlen(labelString)+1];
37 | strcpy(labelString_, labelString);
38 | }
39 | }
40 |
41 | char *FunctionLabel::getLabelString() const
42 | {
43 | return this->labelString_;
44 | }
45 |
46 | void FunctionLabel::debug(CodeGeneratorDebugger * codeGeneratorDebugger)
47 | {
48 | stringstream strValue;
49 |
50 | strValue << endl << labelString_ << ':' << endl << endl;
51 | codeGeneratorDebugger->debugCode(strValue.str().c_str());
52 | }
53 |
54 | void FunctionLabel::debug(ostream &out)
55 | {
56 | stringstream strValue;
57 |
58 | strValue << endl << labelString_ << ':' << endl << endl;
59 | out << strValue.str().c_str();
60 | }
61 |
--------------------------------------------------------------------------------
/source/code_generator/machine/basic_block.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************/
2 | /** A Compiler for a subset of Oberon **/
3 | /** authors: **/
4 | /** ROCHA, Rodrigo Caetano de Oliveira (rcor) **/
5 | /** FERREIRA, Wallace Dias **/
6 | /************************************************************************************************************************/
7 |
8 | #ifndef MACHINE_CODE_BASIC_BLOCK_H
9 | #define MACHINE_CODE_BASIC_BLOCK_H
10 |
11 | #include
12 | #include
13 | using std::vector;
14 |
15 | #include "../intermediate/instruction/instruction.h"
16 | #include "../intermediate/instruction_argument/argument_information.h"
17 |
18 | class BasicBlock
19 | {
20 | public:
21 | BasicBlock(vector::iterator begin, vector::iterator end);
22 | BasicBlock();
23 | void setBeginIterator(vector::iterator begin);
24 | void setEndIterator(vector::iterator end);
25 |
26 | vector::iterator getBeginIterator();
27 | vector::iterator getEndIterator();
28 |
29 | vector * getInstructionVector();
30 |
31 | void setFunctionName(const char *functionName);
32 | const char *getFunctionName();
33 |
34 | void setStartingFunction(bool isStarting);
35 | bool isStartingFunction();
36 |
37 | void setLastFunctionBlock(bool isLast);
38 | bool isLastFunctionBlock();
39 |
40 | void optimise();
41 |
42 | void debug(ostream &out);
43 |
44 |
45 |
46 | private:
47 | const char *functionName_;
48 | bool isStartingFunction_;
49 | bool isLastFunctionBlock_;
50 | vector::iterator begin_;
51 | vector::iterator end_;
52 | };
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------