-
Notifications
You must be signed in to change notification settings - Fork 0
/
OberonParser.cpp
69 lines (53 loc) · 1.67 KB
/
OberonParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Created by vedam on 7/10/23.
//
#include "OberonParser.hpp"
#include "ErrorReporter.hpp"
#include "Tokenizer.hpp"
void OberonParser::parseConsts()
{
}
void OberonParser::parseTypes()
{
}
void OberonParser::parseProcedures()
{
}
OberonParser::OberonParser(ErrorReporter *reporter) : reporter(reporter)
{
}
void OberonParser::parseModule(Tokenizer *tokenizer)
{
auto token = tokenizer->getNextToken();
if(token.getTokenType() != TokenType::MODULE) {
reporter->report(token.getFilename(), token.getLine(), token.getColumn(), "missing MODULE at location");
return;
}
// check to see if the next parameter is IDENTIFIER otherwise report error and return.
if(tokenizer->peek().getTokenType() != TokenType::IDENTIFIER) {
token = tokenizer->peek();
reporter->report(token.getFilename(), token.getLine(), token.getColumn(), "missing IDENTIFIER at location");
return;
}
// eat the identifier so that we can create the ModuleExpr
token = tokenizer->getNextToken();
// check to see if the next token is a semi-colon. if so, we have the beginnings of a valid module.
// Otherwise, report that we are missing a semi-colon and return
if(tokenizer->peek().getTokenType() != TokenType::SEMICOLON) {
token = tokenizer->peek();
reporter->report(token.getFilename(), token.getLine(),
token.getColumn(), "missing ';' at location");
return;
}
// eat the semicolon since it indicates the end of the module declaration.
tokenizer->getNextToken();
m_ast.reset(new ModuleExpr(token.getParsedString()));
}
Expr *OberonParser::ast() const
{
return m_ast.get();
}
SymbolTable OberonParser::symbolTable() const
{
return symbols;
}