Skip to content

Commit 9567a88

Browse files
Added template frontend (lexer and parser)
1 parent 30809c7 commit 9567a88

File tree

300 files changed

+87839
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+87839
-6
lines changed

.vscode/settings.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"files.associations": {
3+
"xstring": "cpp",
4+
"iostream": "cpp",
5+
"algorithm": "cpp",
6+
"cmath": "cpp",
7+
"cstddef": "cpp",
8+
"cstdint": "cpp",
9+
"cstdio": "cpp",
10+
"cstdlib": "cpp",
11+
"cstring": "cpp",
12+
"cwchar": "cpp",
13+
"deque": "cpp",
14+
"exception": "cpp",
15+
"initializer_list": "cpp",
16+
"ios": "cpp",
17+
"iosfwd": "cpp",
18+
"istream": "cpp",
19+
"limits": "cpp",
20+
"new": "cpp",
21+
"ostream": "cpp",
22+
"stdexcept": "cpp",
23+
"streambuf": "cpp",
24+
"string": "cpp",
25+
"system_error": "cpp",
26+
"type_traits": "cpp",
27+
"typeinfo": "cpp",
28+
"utility": "cpp",
29+
"xfacet": "cpp",
30+
"xiosbase": "cpp",
31+
"xlocale": "cpp",
32+
"xlocinfo": "cpp",
33+
"xlocnum": "cpp",
34+
"xmemory": "cpp",
35+
"xmemory0": "cpp",
36+
"xstddef": "cpp",
37+
"xtr1common": "cpp",
38+
"xutility": "cpp",
39+
"vector": "cpp"
40+
}
41+
}

implementation/bin/graph.gv

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Gerado por GNU Bison 3.0.2.
2+
// Reportar erros para <bug-bison@gnu.org>.
3+
// Página inicial: <http://www.gnu.org/software/bison/>.
4+
5+
digraph "src/frontend/parser.y"
6+
{
7+
node [fontname = courier, shape = box, colorscheme = paired6]
8+
edge [fontname = courier]
9+
10+
0 [label="Estado0\n\l 0 $accept: . source $end\l"]
11+
0 -> 1 [style=dashed label="source"]
12+
0 -> "0R1" [style=solid]
13+
"0R1" [label="R1", fillcolor=3, shape=diamond, style=filled]
14+
1 [label="Estado1\n\l 0 $accept: source . $end\l"]
15+
1 -> 2 [style=solid label="$end"]
16+
2 [label="Estado2\n\l 0 $accept: source $end .\l"]
17+
2 -> "2R0" [style=solid]
18+
"2R0" [label="Acc", fillcolor=1, shape=diamond, style=filled]
19+
}

implementation/bin/ulang

72.7 KB
Binary file not shown.

implementation/obj/cmdline.o

89.2 KB
Binary file not shown.

implementation/obj/config.o

940 Bytes
Binary file not shown.
7.23 KB
Binary file not shown.

implementation/obj/main.o

6.17 KB
Binary file not shown.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* cmdline.cpp
3+
*
4+
* Created on: 09/06/2016
5+
* Author: Miguel
6+
*/
7+
8+
#include <utility>
9+
#include <vector>
10+
#include <util.h>
11+
#include "cmdline.h"
12+
13+
std::vector<std::pair<char, std::string>> opts_single_list;
14+
std::vector<std::pair<std::string, std::string>> opts_list;
15+
16+
char is_opt(std::string opt) {
17+
return !opt.find("--") ? 2 : !opt.find("-") ? 1 : 0;
18+
}
19+
20+
char get_single_opt(std::string opt) {
21+
for(int i = 0; i < opt.size(); i++)
22+
if(opt[i] != '-')
23+
return opt[i];
24+
return -1;
25+
}
26+
27+
std::string get_string_opt(std::string opt) {
28+
for(int i = 0; i < opt.size(); i++)
29+
if(opt[i] != '-')
30+
return opt.substr(i, opt.size());
31+
return NULLSTR;
32+
}
33+
34+
/* Pushes options such as -o, -c, -e, etc */
35+
void cmd_push_single(std::string opt, std::string arg) {
36+
opts_single_list.push_back(std::make_pair(get_single_opt(opt), arg));
37+
}
38+
39+
/* Pushes options such as --opt=, --compile, --enable="feature", etc */
40+
void cmd_push(std::string opt, std::string arg) {
41+
opts_list.push_back(make_pair(get_string_opt(opt), arg));
42+
}
43+
44+
std::pair<char,std::string> cmd_query(char opt_query) {
45+
for(auto pair : opts_single_list)
46+
if(pair.first == opt_query) return pair;
47+
return std::make_pair(0, NULLSTR);
48+
}
49+
50+
std::pair<std::string,std::string> cmd_query(std::string opt_query) {
51+
for(auto pair : opts_list)
52+
if(pair.first == opt_query) return pair;
53+
return std::make_pair(NULLSTR, NULLSTR);
54+
}
55+
56+
char cmd_has_opt(char opt) {
57+
for(auto pair : opts_single_list)
58+
if(pair.first == opt) return 1;
59+
return 0;
60+
}
61+
62+
char cmd_has_opt(std::string opt) {
63+
for(auto pair : opts_list)
64+
if(pair.first == opt) return 1;
65+
return 0;
66+
}
67+
68+
void cmdline_parse(int argc, char ** argv) {
69+
/* Iterate through the cmdline: */
70+
int ctr = 2;
71+
while(ctr < argc) {
72+
std::string opt = std::string(argv[ctr++]);
73+
char opt_type;
74+
if((opt_type = is_opt(opt)))
75+
if(opt_type == 1)
76+
cmd_push_single(opt, ctr < argc ? std::string(argv[ctr]) : NULLSTR);
77+
else if(opt_type == 2)
78+
cmd_push(opt, ctr < argc ? std::string(argv[ctr]) : NULLSTR);
79+
}
80+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef _CMDLINE_H_
2+
#define _CMDLINE_H_
3+
4+
#include <string>
5+
6+
char get_single_opt(std::string opt);
7+
std::string get_string_opt(std::string opt);
8+
std::pair<char,std::string> cmd_query(char opt_query);
9+
std::pair<std::string,std::string> cmd_query(std::string opt_query);
10+
char cmd_has_opt(char opt);
11+
char cmd_has_opt(std::string opt);
12+
void cmdline_parse(int argc, char ** argv);
13+
14+
#endif

implementation/src/config.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "config.h"
2+

0 commit comments

Comments
 (0)